summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tit4tat.pl24
1 files 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([], [], []).