Anton Shestakov <engored@ya.ru>, Sat, 01 Mar 2014 23:02:31 +0900
Unused export.
src/rps.erl
Permissions: -rw-r--r--
-import(rps3, [get_rules/0]). lobby/0, counter/0, printer/0, fool/0, copycat/0, gambler/0]). -define(BOTS, [fool, copycat, gambler]). register(lobby, spawn_link(?MODULE, lobby, [])), register(counter, spawn_link(?MODULE, counter, [])), register(printer, spawn_link(?MODULE, printer, [])), [spawn_link(?MODULE, Bot, []) || Bot <- ?BOTS]. lobby(Players) when length(Players) =:= length(?BOTS) -> Room = spawn_link(rps_room, room, [Players]), lists:foreach(fun(Player) -> Player ! {room, Room} 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()} Hand = lists:nth(random:uniform(length(get_rules())), get_rules()), copycat(Room, hd(get_rules())) {winner, {NewHand, _}} -> Wins = dict:from_list([{C, 0} || C <- get_rules()]), F = fun({_, A}, {_, B}) -> A =< B end, {Hand, _} = hd(lists:sort(F, dict:to_list(Wins))), gambler(Room, dict:update_counter(Hand, 1, Wins))