Permalink
Browse files

Merge pull request #1 from ojrac/master

A quick tit-for-tat bot
  • Loading branch information...
2 parents 172196f + 4fe8233 commit 54d341b6173ece80c99ba552f33f6c6843ae754d @dmilstein committed Jul 15, 2011
Showing with 22 additions and 0 deletions.
  1. +22 −0 titfortat.erl
View
@@ -0,0 +1,22 @@
+%%% The rumored-to-be-optimal-ish strategy for prisoners' dilemma
+
+-module(titfortat).
+-export([init/0, play/2, result/2, stop/1]).
+
+init() ->
+ dict:new().
+
+play(Opponent, State) ->
+ case dict:find(Opponent, State) of
+ {ok, OpponentLastMove} ->
+ {OpponentLastMove, State};
+ error ->
+ {cooperate, State}
+ end.
+
+result({Opponent, _OwnChoice, OpponentChoice}, State) ->
+ dict:store(Opponent, OpponentChoice, State).
+
+stop(_State) ->
+ ok.
+

0 comments on commit 54d341b

Please sign in to comment.