From 553e4655f2227783051d5ea7fba65d9135310ad4 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Thu, 8 Nov 2012 13:17:20 +0100 Subject: Prisoners Dilemma: Move rules to subdirectory --- always_coorporate.pl | 1 - always_defect.pl | 1 - grudger.pl | 8 -------- hard_tit4tat.pl | 6 ------ mistrust_tit4tat.pl | 7 ------- naive_prober.pl | 9 --------- pavlov.pl | 6 ------ periodically_ddc.pl | 4 ---- periodically_ssz.pl | 4 ---- prisoners_dilemma.pl | 2 +- random_choice.pl | 2 -- rules/always_coorporate.pl | 1 + rules/always_defect.pl | 1 + rules/grudger.pl | 8 ++++++++ rules/hard_tit4tat.pl | 6 ++++++ rules/mistrust_tit4tat.pl | 7 +++++++ rules/naive_prober.pl | 9 +++++++++ rules/pavlov.pl | 6 ++++++ rules/periodically_ddc.pl | 4 ++++ rules/periodically_ssz.pl | 4 ++++ rules/random_choice.pl | 2 ++ rules/tit42tat.pl | 5 +++++ rules/tit4tat.pl | 11 +++++++++++ tit42tat.pl | 5 ----- tit4tat.pl | 11 ----------- 25 files changed, 65 insertions(+), 65 deletions(-) delete mode 100644 always_coorporate.pl delete mode 100644 always_defect.pl delete mode 100644 grudger.pl delete mode 100644 hard_tit4tat.pl delete mode 100644 mistrust_tit4tat.pl delete mode 100644 naive_prober.pl delete mode 100644 pavlov.pl delete mode 100644 periodically_ddc.pl delete mode 100644 periodically_ssz.pl delete mode 100644 random_choice.pl create mode 100644 rules/always_coorporate.pl create mode 100644 rules/always_defect.pl create mode 100644 rules/grudger.pl create mode 100644 rules/hard_tit4tat.pl create mode 100644 rules/mistrust_tit4tat.pl create mode 100644 rules/naive_prober.pl create mode 100644 rules/pavlov.pl create mode 100644 rules/periodically_ddc.pl create mode 100644 rules/periodically_ssz.pl create mode 100644 rules/random_choice.pl create mode 100644 rules/tit42tat.pl create mode 100644 rules/tit4tat.pl delete mode 100644 tit42tat.pl delete mode 100644 tit4tat.pl diff --git a/always_coorporate.pl b/always_coorporate.pl deleted file mode 100644 index e6094df..0000000 --- a/always_coorporate.pl +++ /dev/null @@ -1 +0,0 @@ -always_coorporate(_, c, _, _). diff --git a/always_defect.pl b/always_defect.pl deleted file mode 100644 index f9fd91d..0000000 --- a/always_defect.pl +++ /dev/null @@ -1 +0,0 @@ -always_defect(_, d, _, _). diff --git a/grudger.pl b/grudger.pl deleted file mode 100644 index 76f9629..0000000 --- a/grudger.pl +++ /dev/null @@ -1,8 +0,0 @@ -% Grudger, Spiteful: -% Cooperates until the second has defected, after -% that move defects forever (he does not forgive). -% http://euler.fd.cvut.cz/predmety/game_theory/lecture_repeat.pdf - -grudger([], c, _, _). -grudger([d|_], d, _, _). -grudger([c|Tail], Decision, _, _) :- grudger(Tail, Decision, _, _). diff --git a/hard_tit4tat.pl b/hard_tit4tat.pl deleted file mode 100644 index 8efc124..0000000 --- a/hard_tit4tat.pl +++ /dev/null @@ -1,6 +0,0 @@ -% Hard Tit for Tat: -% Cooperates unless the opponent has defected -% at least once in the last two rounds. - -hard_tit4tat([A,B|_],d,_,_):-(A=d;B=d),!. -hard_tit4tat(_,c,_,_). diff --git a/mistrust_tit4tat.pl b/mistrust_tit4tat.pl deleted file mode 100644 index 5e80c02..0000000 --- a/mistrust_tit4tat.pl +++ /dev/null @@ -1,7 +0,0 @@ -% Mistrust Tit for Tat: -% In the first round it defects, than it plays opponent’s move. - -% Use opponents last decision -mistrust_tit4tat([Last|_],Last,_,_). -% Fallback to defect if history is empty. -mistrust_tit4tat([],d,_,_). diff --git a/naive_prober.pl b/naive_prober.pl deleted file mode 100644 index df2bcf5..0000000 --- a/naive_prober.pl +++ /dev/null @@ -1,9 +0,0 @@ -% Naive Prober: -% Like Tit for Tat, but sometimes, after the opponent has cooperated, it -% defects (e.g. at random, in one of ten rounds in average). - -naive_prober([d|_],d,_,_). -% but only for for 90% if coorporated -naive_prober([c|_],Choice,_,_):-random(Number), (Number < 0.1 -> Choice=d; Choice=c). -% Fallback to coorporate if history is empty. -naive_prober([],c,_,_). diff --git a/pavlov.pl b/pavlov.pl deleted file mode 100644 index 0da8011..0000000 --- a/pavlov.pl +++ /dev/null @@ -1,6 +0,0 @@ -% Pavlov: -% Cooperates if and only if both players opted for the -% same choice in the previous move, otherwise it defects. -pavlov([], c, _, c):-!. -pavlov([Choice|_], c, Choice, c):-!. -pavlov(_, d, _, d). diff --git a/periodically_ddc.pl b/periodically_ddc.pl deleted file mode 100644 index 897986d..0000000 --- a/periodically_ddc.pl +++ /dev/null @@ -1,4 +0,0 @@ -% Plays periodically: Defect–Defect–Coop. -periodically_ddc(_, d, [], [1]). -periodically_ddc(_, d, [1], [2]). -periodically_ddc(_, c, [2], []). diff --git a/periodically_ssz.pl b/periodically_ssz.pl deleted file mode 100644 index 21cb017..0000000 --- a/periodically_ssz.pl +++ /dev/null @@ -1,4 +0,0 @@ -% Plays periodically: Coop-Coop-Defect -periodically_ssz(_, c, [], [1]). -periodically_ssz(_, c, [1], [2]). -periodically_ssz(_, d, [2], []). diff --git a/prisoners_dilemma.pl b/prisoners_dilemma.pl index b690fbe..16d0388 100644 --- a/prisoners_dilemma.pl +++ b/prisoners_dilemma.pl @@ -46,5 +46,5 @@ loop(Module, ModuleState, Hist, PayedA, PayedB) :- do(Choice, Module, ModuleState, Hist, PayedA, PayedB). -start(Module) :- consult(Module), loop(Module, [], [], [], []). +start(Module) :- atom_concat('rules/', Module, Path), write(Path), consult(Path), loop(Module, [], [], [], []). start :- start(tit4tat),halt. diff --git a/random_choice.pl b/random_choice.pl deleted file mode 100644 index 3bd4a91..0000000 --- a/random_choice.pl +++ /dev/null @@ -1,2 +0,0 @@ -random_choice(_, Choice, _, _) :- - random(Number), (Number < 0.5 -> Choice=c ; Choice=d). diff --git a/rules/always_coorporate.pl b/rules/always_coorporate.pl new file mode 100644 index 0000000..e6094df --- /dev/null +++ b/rules/always_coorporate.pl @@ -0,0 +1 @@ +always_coorporate(_, c, _, _). diff --git a/rules/always_defect.pl b/rules/always_defect.pl new file mode 100644 index 0000000..f9fd91d --- /dev/null +++ b/rules/always_defect.pl @@ -0,0 +1 @@ +always_defect(_, d, _, _). diff --git a/rules/grudger.pl b/rules/grudger.pl new file mode 100644 index 0000000..76f9629 --- /dev/null +++ b/rules/grudger.pl @@ -0,0 +1,8 @@ +% Grudger, Spiteful: +% Cooperates until the second has defected, after +% that move defects forever (he does not forgive). +% http://euler.fd.cvut.cz/predmety/game_theory/lecture_repeat.pdf + +grudger([], c, _, _). +grudger([d|_], d, _, _). +grudger([c|Tail], Decision, _, _) :- grudger(Tail, Decision, _, _). diff --git a/rules/hard_tit4tat.pl b/rules/hard_tit4tat.pl new file mode 100644 index 0000000..8efc124 --- /dev/null +++ b/rules/hard_tit4tat.pl @@ -0,0 +1,6 @@ +% Hard Tit for Tat: +% Cooperates unless the opponent has defected +% at least once in the last two rounds. + +hard_tit4tat([A,B|_],d,_,_):-(A=d;B=d),!. +hard_tit4tat(_,c,_,_). diff --git a/rules/mistrust_tit4tat.pl b/rules/mistrust_tit4tat.pl new file mode 100644 index 0000000..5e80c02 --- /dev/null +++ b/rules/mistrust_tit4tat.pl @@ -0,0 +1,7 @@ +% Mistrust Tit for Tat: +% In the first round it defects, than it plays opponent’s move. + +% Use opponents last decision +mistrust_tit4tat([Last|_],Last,_,_). +% Fallback to defect if history is empty. +mistrust_tit4tat([],d,_,_). diff --git a/rules/naive_prober.pl b/rules/naive_prober.pl new file mode 100644 index 0000000..df2bcf5 --- /dev/null +++ b/rules/naive_prober.pl @@ -0,0 +1,9 @@ +% Naive Prober: +% Like Tit for Tat, but sometimes, after the opponent has cooperated, it +% defects (e.g. at random, in one of ten rounds in average). + +naive_prober([d|_],d,_,_). +% but only for for 90% if coorporated +naive_prober([c|_],Choice,_,_):-random(Number), (Number < 0.1 -> Choice=d; Choice=c). +% Fallback to coorporate if history is empty. +naive_prober([],c,_,_). diff --git a/rules/pavlov.pl b/rules/pavlov.pl new file mode 100644 index 0000000..0da8011 --- /dev/null +++ b/rules/pavlov.pl @@ -0,0 +1,6 @@ +% Pavlov: +% Cooperates if and only if both players opted for the +% same choice in the previous move, otherwise it defects. +pavlov([], c, _, c):-!. +pavlov([Choice|_], c, Choice, c):-!. +pavlov(_, d, _, d). diff --git a/rules/periodically_ddc.pl b/rules/periodically_ddc.pl new file mode 100644 index 0000000..897986d --- /dev/null +++ b/rules/periodically_ddc.pl @@ -0,0 +1,4 @@ +% Plays periodically: Defect–Defect–Coop. +periodically_ddc(_, d, [], [1]). +periodically_ddc(_, d, [1], [2]). +periodically_ddc(_, c, [2], []). diff --git a/rules/periodically_ssz.pl b/rules/periodically_ssz.pl new file mode 100644 index 0000000..21cb017 --- /dev/null +++ b/rules/periodically_ssz.pl @@ -0,0 +1,4 @@ +% Plays periodically: Coop-Coop-Defect +periodically_ssz(_, c, [], [1]). +periodically_ssz(_, c, [1], [2]). +periodically_ssz(_, d, [2], []). diff --git a/rules/random_choice.pl b/rules/random_choice.pl new file mode 100644 index 0000000..3bd4a91 --- /dev/null +++ b/rules/random_choice.pl @@ -0,0 +1,2 @@ +random_choice(_, Choice, _, _) :- + random(Number), (Number < 0.5 -> Choice=c ; Choice=d). diff --git a/rules/tit42tat.pl b/rules/tit42tat.pl new file mode 100644 index 0000000..281bc4d --- /dev/null +++ b/rules/tit42tat.pl @@ -0,0 +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,_,_). diff --git a/rules/tit4tat.pl b/rules/tit4tat.pl new file mode 100644 index 0000000..2cf520c --- /dev/null +++ b/rules/tit4tat.pl @@ -0,0 +1,11 @@ +% Tit for Tat: +% Begins with cooperation and then plays what its opponent played in the last +% move (if the opponent defects in some round, Tit for Tat will defect in the +% following one; to cooperation it responds with cooperation). + +% Syntax: MODULE(UserDecisionHistry [in], ModuleDecision [out]) + +% Use opponents last decision +tit4tat([Last|_],Last,_,_). +% Fallback to coorporate if history is empty. +tit4tat([],c,_,_). diff --git a/tit42tat.pl b/tit42tat.pl deleted file mode 100644 index 281bc4d..0000000 --- a/tit42tat.pl +++ /dev/null @@ -1,5 +0,0 @@ -% 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,_,_). diff --git a/tit4tat.pl b/tit4tat.pl deleted file mode 100644 index 2cf520c..0000000 --- a/tit4tat.pl +++ /dev/null @@ -1,11 +0,0 @@ -% Tit for Tat: -% Begins with cooperation and then plays what its opponent played in the last -% move (if the opponent defects in some round, Tit for Tat will defect in the -% following one; to cooperation it responds with cooperation). - -% Syntax: MODULE(UserDecisionHistry [in], ModuleDecision [out]) - -% Use opponents last decision -tit4tat([Last|_],Last,_,_). -% Fallback to coorporate if history is empty. -tit4tat([],c,_,_). -- cgit