--- a/rps.erl Tue Feb 25 23:16:04 2014 +0900
+++ b/rps.erl Tue Feb 25 23:55:18 2014 +0900
lobby/0, counter/0, printer/0, room/1,
+ fool/0, copycat/0, gambler/0]).
-define(RULES, [rock, paper, scissors]).
--define(BOTS, [fool, copycat, fool]).
+-define(BOTS, [fool, copycat, gambler]).
{winner, {NewChoice, _}} ->
+ lobby ! {join, self()},
+ Wins = dict:from_list([{C, 0} || C <- ?RULES]),
+ F = fun({_, A}, {_, B}) -> A =< B end,
+ {Choice, _} = hd(lists:sort(F, dict:to_list(Wins))),
+ Room ! {Choice, self()},
+ {winner, {Choice, _}} ->
+ gambler(Room, dict:update_counter(Choice, 1, Wins))