diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-11-06 11:31:26 +0100 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-11-06 11:31:26 +0100 |
commit | 2e3c0c10659a3d76532e9b85bf479f210f92a4b8 (patch) | |
tree | eb28d5887e28f8bddbf413c4080d1661e8ecc52f | |
parent | 99a16b0ac78c3e33ec3f1c31e1fe1f5a6d38b5f0 (diff) | |
download | wbs-2e3c0c10659a3d76532e9b85bf479f210f92a4b8.tar.gz wbs-2e3c0c10659a3d76532e9b85bf479f210f92a4b8.tar.bz2 wbs-2e3c0c10659a3d76532e9b85bf479f210f92a4b8.zip |
tit4tat.pl: Fix going through work-loop when we get end-signal
-rw-r--r-- | tit4tat.pl | 24 |
1 files changed, 13 insertions, 11 deletions
@@ -38,18 +38,20 @@ tit4tat(A, Hist, PayA, PayB) :- sum([], 0). sum([H|T], S) :- sum(T, TMP), S is TMP + H. -loop(end, _). -loop(End, Hist, PayedA, PayedB):- End\=end, - write('Type c,d or e to end: '), read(Choice), +do(e, _, _, _):-!. +do(Choice, Hist, PayedA, PayedB) :- + tit4tat(Choice, Hist, PayA, PayB), - tit4tat(Choice, Hist, PAY_A, PAY_B), + write('A Pay: '), write(PayA), write('\t'), + write('B Pay: '), write(PayB), write('\t'), + write('A: '), sum([PayA|PayedA], SumA), write(SumA), write('\t'), + write('B: '), sum([PayB|PayedB], SumB), write(SumB), nl, + write(Choice),nl, - write('A Pay: '),write(PAY_A),write('\t'), - write('B Pay: '),write(PAY_B),write('\t'), - write('A: '), sum([PAY_A|PayedA], SumA), write(SumA), write('\t'), - write('B: '), sum([PAY_B|PayedB], SumB), write(SumB), nl, + loop([Choice|Hist], [PayA|PayedA], [PayB|PayedB]). +loop(Hist, PayedA, PayedB) :- + write('Type c,d or e to end: '), read(Choice), + do(Choice, Hist, PayedA, PayedB). - loop(Choice, [Choice|Hist], [PAY_A|PayedA], [PAY_B|PayedB]). - -start:-loop(noend, [], [], []). +start :- loop([], [], []). |