From 2e3c0c10659a3d76532e9b85bf479f210f92a4b8 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Tue, 6 Nov 2012 11:31:26 +0100 Subject: tit4tat.pl: Fix going through work-loop when we get end-signal --- tit4tat.pl | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tit4tat.pl b/tit4tat.pl index ec0eccb..4614314 100644 --- a/tit4tat.pl +++ b/tit4tat.pl @@ -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([], [], []). -- cgit