--- a/rps.erl Tue Feb 25 23:55:18 2014 +0900
+++ b/rps.erl Wed Feb 26 01:38:26 2014 +0900
+-import(rps3, [get_rules/0, beats/1]).
lobby/0, counter/0, printer/0, room/1,
fool/0, copycat/0, gambler/0]).
--define(RULES, [rock, paper, scissors]).
-define(BOTS, [fool, copycat, gambler]).
% winner for 3 players is:
% rock, rock, rock -> undefined
% rock, paper, scissors -> undefined
winner(Choices) when length(Choices) > 1 ->
CSet = sets:from_list([C || {C, _} <- Choices]),
- RSet = sets:from_list(?RULES),
+ RSet = sets:from_list(get_rules()),
Absents = sets:subtract(RSet, CSet),
case sets:size(Absents) of
room(Players, Choices) ->
- ObjectIsOk = lists:any(fun(X) -> X =:= Object end, ?RULES),
+ ObjectIsOk = lists:any(fun(X) -> X =:= Object end, get_rules()),
ChoiceMade = lists:any(fun({_, Player}) -> Player =:= Who end, Choices),
case ObjectIsOk andalso not ChoiceMade of
- Choice = lists:nth(random:uniform(length(?RULES)), ?RULES),
+ Choice = lists:nth(random:uniform(length(get_rules())), get_rules()),
- copycat(Room, hd(?RULES))
+ copycat(Room, hd(get_rules()))
- Wins = dict:from_list([{C, 0} || C <- ?RULES]),
+ Wins = dict:from_list([{C, 0} || C <- get_rules()]),
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rps3.erl Wed Feb 26 01:38:26 2014 +0900
+-export([get_rules/0, beats/1, test_beats/0]).
+get_rules() -> [rock, paper, scissors].
+ io:format("~w beats ~w.~n", [C, beats(C)])