diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-11-05 14:57:47 +0100 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2012-11-05 14:57:47 +0100 |
commit | 624cf525cebb16b04a77ec18be4ac5454870596d (patch) | |
tree | a9bc6d59fc6f27ba11b47d73dd0e9307bcc4c9f0 | |
parent | a40ea9b1904e872ca35daa168c4f7ec995895be2 (diff) | |
download | wbs-624cf525cebb16b04a77ec18be4ac5454870596d.tar.gz wbs-624cf525cebb16b04a77ec18be4ac5454870596d.tar.bz2 wbs-624cf525cebb16b04a77ec18be4ac5454870596d.zip |
tit4tat.pl: Count total paymenet
-rw-r--r-- | tit4tat.pl | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -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, [], [], []). |