summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2012-11-07 10:42:03 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2012-11-07 10:42:03 +0100
commit1c86bdd6b2f717bb722983377d144a9b2863fc68 (patch)
treef003aa6ea51edeb0147ba0f2aa97df67f210148f
parent087a091275763a651613e9f168ff8bc19c31f6cb (diff)
downloadwbs-1c86bdd6b2f717bb722983377d144a9b2863fc68.tar.gz
wbs-1c86bdd6b2f717bb722983377d144a9b2863fc68.tar.bz2
wbs-1c86bdd6b2f717bb722983377d144a9b2863fc68.zip
prisoners_dilemma: Track module state
Will be needed for peridical algorithms.
-rw-r--r--always_coorporate.pl2
-rw-r--r--always_defect.pl2
-rw-r--r--grudger.pl2
-rw-r--r--mistrust_tit4tat.pl2
-rw-r--r--prisoners_dilemma.pl14
-rw-r--r--random_choice.pl2
-rw-r--r--tit42tat.pl4
-rw-r--r--tit4tat.pl4
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,_,_).