From 624cf525cebb16b04a77ec18be4ac5454870596d Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Mon, 5 Nov 2012 14:57:47 +0100 Subject: tit4tat.pl: Count total paymenet --- tit4tat.pl | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tit4tat.pl b/tit4tat.pl index 85df991..82d4f61 100644 --- a/tit4tat.pl +++ b/tit4tat.pl @@ -33,15 +33,21 @@ tit4tat(A, Hist, PayA, PayB) :- tit4tat_select(Old, Hist), step(A, Old, PayA, PayB). +sum([], 0). +sum([H|T], S):-sum(T, TMP), S is TMP + H. + loop(end, _). -loop(End, Hist):- End\=end, - write('Type c,d or end to end: '), read(Choice), +loop(End, Hist, PayedA, PayedB):- End\=end, + write('Type c,d or e to end: '), read(Choice), tit4tat(Choice, Hist, PAY_A, PAY_B), - write('A Pay: '),write(PAY_A),nl, - write('B Pay: '),write(PAY_B),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, [Choice|Hist]). + loop(Choice, [Choice|Hist], [PAY_A|PayedA], [PAY_B|PayedB]). -start:-loop(noend, []). +start:-loop(noend, [], [], []). -- cgit