Download:
child 17:f187ebbdcfb3
parent 15:36f639142522
16:68f812e39f5a
Anton Shestakov <engored@ya.ru>, Wed, 26 Feb 2014 19:36:35 +0900
Count winning hands too.

1 файлов изменено, 13 вставок(+), 7 удалений(-) [+]
rps.erl file | annotate | diff | comparison | revisions
--- a/rps.erl Wed Feb 26 19:05:49 2014 +0900
+++ b/rps.erl Wed Feb 26 19:36:35 2014 +0900
@@ -50,17 +50,23 @@
end.
counter() ->
- counter(0, 0, dict:new()).
+ counter(0, 0, dict:new(), dict:new()).
-counter(Plays, Draws, Wins) ->
+counter(Plays, Draws, Wins, Hands) ->
receive
{draw, _} ->
- counter(Plays + 1, Draws + 1, Wins);
- {winner, {_, Winner}} ->
- counter(Plays + 1, Draws, dict:update_counter(Winner, 1, Wins));
+ counter(Plays + 1, Draws + 1, Wins, Hands);
+ {winner, {Hand, Winner}} ->
+ counter(Plays + 1, Draws,
+ dict:update_counter(Winner, 1, Wins),
+ dict:update_counter(Hand, 1, Hands));
{sendstats, Pid} ->
- Pid ! {stats, {plays, Plays, draws, Draws, wins, dict:to_list(Wins)}},
- counter(Plays, Draws, Wins)
+ Pid ! {stats, {
+ plays, Plays,
+ draws, Draws,
+ wins, dict:to_list(Wins),
+ hands, dict:to_list(Hands)}},
+ counter(Plays, Draws, Wins, Hands)
end.
printer() ->