summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2012-11-05 14:37:07 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2012-11-05 14:38:04 +0100
commit7c65af4393f262a21d86a8594b8ffdbd1b23d1aa (patch)
treed3b7b59a25ae3092286e45b4f56fd6b643626fad
parent09759eb88c5e8da40777b2caa3e803dd7b03fdb1 (diff)
downloadwbs-7c65af4393f262a21d86a8594b8ffdbd1b23d1aa.tar.gz
wbs-7c65af4393f262a21d86a8594b8ffdbd1b23d1aa.tar.bz2
wbs-7c65af4393f262a21d86a8594b8ffdbd1b23d1aa.zip
tit4tat.pl: Try to split ruleset and input/output operation
-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, []).