--- a/src/rps3.erl Mon Mar 03 15:37:24 2014 +0900
+++ b/src/rps3.erl Mon Mar 03 15:42:17 2014 +0900
--export([get_rules/0, winning_hand/1]).
+-export([get_hands/0, winning_hand/1]).
-get_rules() -> [rock, paper, scissors].
+get_hands() -> [rock, paper, scissors].
- beats(H, lists:reverse(get_rules())).
+ beats(H, lists:reverse(get_hands())).
% rock, rock, rock -> rock
--- a/src/rps5.erl Mon Mar 03 15:37:24 2014 +0900
+++ b/src/rps5.erl Mon Mar 03 15:42:17 2014 +0900
winning_hand/1, test_winning_hand/0]).
-get_rules() -> [rock, paper, scissors, spock, lizard].
+get_hands() -> [rock, paper, scissors, spock, lizard].
io:format("~w beats ~w.~n", [H, beats(H)])
io:format("~w loses to ~w.~n", [H, loses(H)])
% rock, rock, rock -> rock
- Exclude = fun(Hand) -> lists:delete(Hand, get_rules()) end,
+ Exclude = fun(Hand) -> lists:delete(Hand, get_hands()) end,
- |lists:map(Exclude, get_rules())
+ |lists:map(Exclude, get_hands())
--- a/src/rps_bots.erl Mon Mar 03 15:37:24 2014 +0900
+++ b/src/rps_bots.erl Mon Mar 03 15:42:17 2014 +0900
- Hands = apply(Rules, get_rules, []),
+ Hands = apply(Rules, get_hands, []),
- copycat(Room, hd(apply(Rules, get_rules, [])))
+ copycat(Room, hd(apply(Rules, get_hands, [])))
- R = apply(Rules, get_rules, []),
- Wins = dict:from_list([{C, 0} || C <- R]),
+ Hands = apply(Rules, get_hands, []),
+ Wins = dict:from_list([{Hand, 0} || Hand <- Hands]),
--- a/src/rps_room.erl Mon Mar 03 15:37:24 2014 +0900
+++ b/src/rps_room.erl Mon Mar 03 15:42:17 2014 +0900
room(State=#state{rules=Rules, choices=Choices}) ->
- R = apply(Rules, get_rules, []),
- ObjectIsOk = lists:any(fun(X) -> X =:= Hand end, R),
+ Hands = apply(Rules, get_hands, []),
+ ObjectIsOk = lists:any(fun(X) -> X =:= Hand end, Hands),
ChoiceMade = lists:keymember(Who, 2, Choices),
case ObjectIsOk andalso not ChoiceMade of
--- a/test/rps3_tests.erl Mon Mar 03 15:37:24 2014 +0900
+++ b/test/rps3_tests.erl Mon Mar 03 15:42:17 2014 +0900
-include_lib("eunit/include/eunit.hrl").
- ?assertEqual(length(rps3:get_rules()), 3).
+ ?assertEqual(length(rps3:get_hands()), 3).
?assertEqual(rps3:winning_hand([rock, paper]), paper),