From 7c65af4393f262a21d86a8594b8ffdbd1b23d1aa Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Mon, 5 Nov 2012 14:37:07 +0100 Subject: tit4tat.pl: Try to split ruleset and input/output operation --- tit4tat.pl | 22 ++++++++++++++++------ 1 file 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, []). -- cgit