Anton Shestakov <engored@ya.ru>, Sat, 01 Mar 2014 23:02:31 +0900
Unused export.
src/rps_room.erl
Permissions: -rw-r--r--
-import(rps3, [get_rules/0, winning_hand/1]). % winner for 3 players is: % rock, rock, rock -> undefined % rock, paper, scissors -> undefined % rock, paper, paper -> undefined % rock, rock, paper -> {paper, Who} winner(Choices) when length(Choices) > 1 -> PlayersByHand = lists:foldl( dict:append(Hand, Who, Acc) end, dict:new(), Choices), WHand = winning_hand([Hand || {Hand, _} <- Choices]), WHand =:= undefined -> []; WHand =/= undefined -> dict:fetch(WHand, PlayersByHand) 1 -> {WHand, hd(Players)}; lists:foreach(fun(Player) -> Player ! start end, Players), room(Players, Choices) when length(Players) =:= length(Choices) -> Winner = winner(Choices), lists:foreach(fun(Player) -> Player ! Msg end, Players), room(Players, Choices) -> ObjectIsOk = lists:any(fun(X) -> X =:= Hand end, get_rules()), ChoiceMade = lists:keymember(Who, 2, Choices), case ObjectIsOk andalso not ChoiceMade of room(Players, [{Hand, Who}|Choices]); io:format("~w picks ~w, not allowed.~n", [Who, Hand]),