--- a/rps.erl Sun Feb 23 15:02:21 2014 +0900
+++ b/rps.erl Sun Feb 23 16:38:28 2014 +0900
--export([lobby/0, counter/2, printer/0, room/1, beats/1, winner/1, go/0, fool/0]).
+ lobby/0, counter/0, printer/0, room/1,
-define(RULES, [rock, paper, scissors]).
-define(BOTS, [fool, fool, fool]).
register(lobby, spawn(rps, lobby, [])),
- register(counter, spawn(rps, counter, [[], []])),
+ register(counter, spawn(rps, counter, [])),
register(printer, spawn(rps, printer, [])),
[spawn(rps, Bot, []) || Bot <- ?BOTS].
+ counter(0, 0, dict:new()).
+counter(Plays, Draws, Wins) ->
- %io:format("draw: ~w.~n", [Choices]),
- counter([Choices|Draws], Wins);
- %io:format("the winner is ~w.~n", [Winner]),
- counter(Draws, [Winner|Wins]);
+ counter(Plays + 1, Draws + 1, Wins);
+ {winner, {_, Winner}} ->
+ counter(Plays + 1, Draws, dict:update_counter(Winner, 1, Wins));
- Pid ! {stats, {draws, length(Draws), wins, length(Wins)}},
+ Pid ! {stats, {plays, Plays, draws, Draws, wins, dict:to_list(Wins)}},
+ counter(Plays, Draws, Wins)