summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--prisoners_dilemma.pl5
-rw-r--r--tit4tat.pl11
2 files changed, 6 insertions, 10 deletions
diff --git a/prisoners_dilemma.pl b/prisoners_dilemma.pl
index 66578e8..a8e3a33 100644
--- a/prisoners_dilemma.pl
+++ b/prisoners_dilemma.pl
@@ -24,14 +24,15 @@ pay(d,c,4).
pay2(A, B, PayA, PayB) :- pay(A, B, PayA), pay(B, A, PayB).
-decide(Module, A, Hist, PayA, PayB) :- call(Module, A, Hist, PayA, PayB).
+decide(Module, Hist, Decision) :- call(Module, Hist, Decision).
sum([], 0).
sum([H|T], S) :- sum(T, TMP), S is TMP + H.
do(e, _, _, _, _) :- !.
do(Choice, Module, Hist, PayedA, PayedB) :-
- decide(Module, Choice, Hist, PayA, PayB),
+ decide(Module, Hist, ModuleDecision),
+ pay2(Choice, ModuleDecision, PayA, PayB),
write('A Pay: '), write(PayA), write('\t'),
write('B Pay: '), write(PayB), write('\t'),
diff --git a/tit4tat.pl b/tit4tat.pl
index e03fd5d..6362ecc 100644
--- a/tit4tat.pl
+++ b/tit4tat.pl
@@ -1,9 +1,4 @@
-%
% 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),
- pay2(A, Old, PayA, PayB).
+tit4tat([Last|_],Last).
+% Fallback to coorporate if history is empty.
+tit4tat([],c).