Anton Shestakov <engored@ya.ru>, Mon, 03 Mar 2014 20:08:31 +0900
Rename #state from rps_rules.hrl to #ruleinfo.
src/rps.erl
Permissions: -rw-r--r--
lobby/0, counter/0, printer/0]). -define(BOTS, [fool, copycat, gambler]). rps_nickserv:start_link(), register(lobby, spawn_link(?MODULE, lobby, [])), register(counter, spawn_link(?MODULE, counter, [])), register(printer, spawn_link(?MODULE, printer, [])), [spawn_link(rps_bots, Bot, []) || Bot <- ?BOTS]. lobby(Players) when length(Players) =:= length(?BOTS) -> Room = spawn_link(rps_room, room, [?RULES, Players]), lists:foreach(fun(Player) -> Player ! {room, Room, ?RULES} end, Players), counter(0, 0, dict:new(), dict:new()). counter(Plays, Draws, Wins, Hands) -> 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)); wins, dict:to_list(Wins), hands, dict:to_list(Hands)}}, counter(Plays, Draws, Wins, Hands) io:format("Stats: ~w.~n", [Stats]) counter ! {sendstats, self()}