summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2012-11-05 14:57:47 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2012-11-05 14:57:47 +0100
commit624cf525cebb16b04a77ec18be4ac5454870596d (patch)
treea9bc6d59fc6f27ba11b47d73dd0e9307bcc4c9f0
parenta40ea9b1904e872ca35daa168c4f7ec995895be2 (diff)
downloadwbs-624cf525cebb16b04a77ec18be4ac5454870596d.tar.gz
wbs-624cf525cebb16b04a77ec18be4ac5454870596d.tar.bz2
wbs-624cf525cebb16b04a77ec18be4ac5454870596d.zip
tit4tat.pl: Count total paymenet
-rw-r--r--tit4tat.pl18
1 files 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, [], [], []).