summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tit4tat.pl22
1 files changed, 16 insertions, 6 deletions
diff --git a/tit4tat.pl b/tit4tat.pl
index 33abcb9..5eb54f4 100644
--- a/tit4tat.pl
+++ b/tit4tat.pl
@@ -24,11 +24,21 @@ step(A, B, PAY_A, PAY_B) :-
pay(A, B, PAY_A),
pay(B, A, PAY_B).
-loop(end).
-loop(OLD):- OLD\=end,
+% Use opponents last decision
+tit4tat_select(H,[H|_]).
+% Fallback to coorporate at beginning
+tit4tat_select(c,[]).
+
+tit4tat(A, Hist, PayA, PayB) :-
+ tit4tat_select(Old, Hist),
+ step(A, Old, PayA, PayB).
+
+loop(end, [_]).
+loop(End, Hist):- End\=end,
write('Type c,d or end to end: '), read(Word),
- step(Word, OLD, PAY_A, PAY_B),
- write('A Pay: '),write(PAY_A),nl, write('B Pay: '),write(PAY_B),nl,
- loop(Word).
+ tit4tat(Word, Hist, PAY_A, PAY_B),
+ write('A Pay: '),write(PAY_A),nl,
+ write('B Pay: '),write(PAY_B),nl,
+ loop(Word, [Word|Hist]).
-start:-loop(c).
+start:-loop(noend, []).