Download:
child 9:4b4d65b99174
parent 7:14b33824d432
8:94027114ff65
Anton Shestakov <engored@ya.ru>, Tue, 25 Feb 2014 23:55:18 +0900
Add gambler bot (see gambler's fallacy). Completely broke the other bots.

1 файлов изменено, 24 вставок(+), 2 удалений(-) [+]
rps.erl file | annotate | diff | comparison | revisions
--- a/rps.erl Tue Feb 25 23:16:04 2014 +0900
+++ b/rps.erl Tue Feb 25 23:55:18 2014 +0900
@@ -3,10 +3,10 @@
go/0,
beats/1, winner/1,
lobby/0, counter/0, printer/0, room/1,
- fool/0, copycat/0]).
+ fool/0, copycat/0, gambler/0]).
-define(RULES, [rock, paper, scissors]).
--define(BOTS, [fool, copycat, fool]).
+-define(BOTS, [fool, copycat, gambler]).
beats(C) ->
beats(C, ?RULES).
@@ -154,3 +154,25 @@
{winner, {NewChoice, _}} ->
copycat(Room, NewChoice)
end.
+
+gambler() ->
+ lobby ! {join, self()},
+ gambler(joined).
+
+gambler(joined) ->
+ receive
+ {room, Room} ->
+ Wins = dict:from_list([{C, 0} || C <- ?RULES]),
+ gambler(Room, Wins)
+ end.
+
+gambler(Room, Wins) ->
+ receive
+ start ->
+ F = fun({_, A}, {_, B}) -> A =< B end,
+ {Choice, _} = hd(lists:sort(F, dict:to_list(Wins))),
+ Room ! {Choice, self()},
+ gambler(Room, Wins);
+ {winner, {Choice, _}} ->
+ gambler(Room, dict:update_counter(Choice, 1, Wins))
+ end.