summaryrefslogtreecommitdiff
path: root/rules
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2012-11-08 13:17:20 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2012-11-08 13:17:20 +0100
commit553e4655f2227783051d5ea7fba65d9135310ad4 (patch)
treedf7ddbc67de4cef8c0eda917c76233ddc63d3feb /rules
parentf22d7a9894d530fa2f8ceaeff3a8a52746ad7a1c (diff)
downloadwbs-553e4655f2227783051d5ea7fba65d9135310ad4.tar.gz
wbs-553e4655f2227783051d5ea7fba65d9135310ad4.tar.bz2
wbs-553e4655f2227783051d5ea7fba65d9135310ad4.zip
Prisoners Dilemma: Move rules to subdirectory
Diffstat (limited to 'rules')
-rw-r--r--rules/always_coorporate.pl1
-rw-r--r--rules/always_defect.pl1
-rw-r--r--rules/grudger.pl8
-rw-r--r--rules/hard_tit4tat.pl6
-rw-r--r--rules/mistrust_tit4tat.pl7
-rw-r--r--rules/naive_prober.pl9
-rw-r--r--rules/pavlov.pl6
-rw-r--r--rules/periodically_ddc.pl4
-rw-r--r--rules/periodically_ssz.pl4
-rw-r--r--rules/random_choice.pl2
-rw-r--r--rules/tit42tat.pl5
-rw-r--r--rules/tit4tat.pl11
12 files changed, 64 insertions, 0 deletions
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,_,_).