From 1c86bdd6b2f717bb722983377d144a9b2863fc68 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 7 Nov 2012 10:42:03 +0100 Subject: prisoners_dilemma: Track module state Will be needed for peridical algorithms. --- always_coorporate.pl | 2 +- always_defect.pl | 2 +- grudger.pl | 2 +- mistrust_tit4tat.pl | 2 +- prisoners_dilemma.pl | 14 +++++++------- random_choice.pl | 2 +- tit42tat.pl | 4 ++-- tit4tat.pl | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/always_coorporate.pl b/always_coorporate.pl index 4f11264..e6094df 100644 --- a/always_coorporate.pl +++ b/always_coorporate.pl @@ -1 +1 @@ -always_coorporate(_, c). +always_coorporate(_, c, _, _). diff --git a/always_defect.pl b/always_defect.pl index 3857d5f..f9fd91d 100644 --- a/always_defect.pl +++ b/always_defect.pl @@ -1 +1 @@ -always_defect(_, d). +always_defect(_, d, _, _). diff --git a/grudger.pl b/grudger.pl index 5337e49..3a78513 100644 --- a/grudger.pl +++ b/grudger.pl @@ -4,4 +4,4 @@ grudger([], c). grudger([d|_], d). -grudger([c|Tail], Decision) :- grudger(Tail, Decision). +grudger([c|Tail], Decision, _, _) :- grudger(Tail, Decision). diff --git a/mistrust_tit4tat.pl b/mistrust_tit4tat.pl index ebea1cb..5b95b9e 100644 --- a/mistrust_tit4tat.pl +++ b/mistrust_tit4tat.pl @@ -3,4 +3,4 @@ % Use opponents last decision mistrust_tit4tat([Last|_],Last). % Fallback to defect if history is empty. -mistrust_tit4tat([],d). +mistrust_tit4tat([],d,_,_). diff --git a/prisoners_dilemma.pl b/prisoners_dilemma.pl index ffcbfad..b690fbe 100644 --- a/prisoners_dilemma.pl +++ b/prisoners_dilemma.pl @@ -24,14 +24,14 @@ pay(d,c,4). pay2(A, B, PayA, PayB) :- pay(A, B, PayA), pay(B, A, PayB). -decide(Module, Hist, Decision) :- call(Module, Hist, Decision). +decide(Module, Hist, Decision, State, NewState) :- call(Module, Hist, Decision, State, NewState). sum([], 0). sum([H|T], S) :- sum(T, TMP), S is TMP + H. do(e, _, _, _, _) :- !. -do(Choice, Module, Hist, PayedA, PayedB) :- - decide(Module, Hist, ModuleDecision), +do(Choice, Module, ModuleState, Hist, PayedA, PayedB) :- + decide(Module, Hist, ModuleDecision, ModuleState, NewModuleState), pay2(Choice, ModuleDecision, PayA, PayB), write('A Pay: '), write(Choice), write(': '), write(PayA), write('\t'), @@ -39,12 +39,12 @@ do(Choice, Module, Hist, PayedA, PayedB) :- write('A: '), sum([PayA|PayedA], SumA), write(SumA), write('\t'), write('B: '), sum([PayB|PayedB], SumB), write(SumB), nl, - loop(Module, [Choice|Hist], [PayA|PayedA], [PayB|PayedB]). + loop(Module, NewModuleState, [Choice|Hist], [PayA|PayedA], [PayB|PayedB]). -loop(Module, Hist, PayedA, PayedB) :- +loop(Module, ModuleState, Hist, PayedA, PayedB) :- write('Type c,d or e to end: '), read(Choice), - do(Choice, Module, Hist, PayedA, PayedB). + do(Choice, Module, ModuleState, Hist, PayedA, PayedB). -start(Module) :- consult(Module), loop(Module, [], [], []). +start(Module) :- consult(Module), loop(Module, [], [], [], []). start :- start(tit4tat),halt. diff --git a/random_choice.pl b/random_choice.pl index 3a2dfe3..43e4735 100644 --- a/random_choice.pl +++ b/random_choice.pl @@ -1,4 +1,4 @@ random_choice_do(c,Number):-Number < 0.5,!. random_choice_do(d,_). -random_choice(_, Choice) :- random(Number), random_choice_do(Choice, Number). +random_choice(_, Choice, _, _) :- random(Number), random_choice_do(Choice, Number). diff --git a/tit42tat.pl b/tit42tat.pl index 4ec519d..72a6e6a 100644 --- a/tit42tat.pl +++ b/tit42tat.pl @@ -1,5 +1,5 @@ % Select distraction only if opponents both last decision were to distract. % See: http://en.wikipedia.org/wiki/Tit_for_tat#Tit_for_two_tats -tit42tat([d,d|_],d). -tit42tat(_,c). +tit42tat([d,d|_],d,_,_). +tit42tat(_,c,_,_). diff --git a/tit4tat.pl b/tit4tat.pl index c94c13e..47d8535 100644 --- a/tit4tat.pl +++ b/tit4tat.pl @@ -1,6 +1,6 @@ % Syntax: MODULE(UserDecisionHistry [in], ModuleDecision [out]) % Use opponents last decision -tit4tat([Last|_],Last). +tit4tat([Last|_],Last,_,_). % Fallback to coorporate if history is empty. -tit4tat([],c). +tit4tat([],c,_,_). -- cgit