Download:
child 35:1963573a943e
parent 33:654a2f3e9ccf
34:19dac34d9a51
Anton Shestakov <engored@ya.ru>, Mon, 03 Mar 2014 15:42:17 +0900
Rename rpsN:get_rules/0 to get_hands/0.

5 файлов изменено, 17 вставок(+), 17 удалений(-) [+]
src/rps3.erl file | annotate | diff | comparison | revisions
src/rps5.erl file | annotate | diff | comparison | revisions
src/rps_bots.erl file | annotate | diff | comparison | revisions
src/rps_room.erl file | annotate | diff | comparison | revisions
test/rps3_tests.erl file | annotate | diff | comparison | revisions
--- a/src/rps3.erl Mon Mar 03 15:37:24 2014 +0900
+++ b/src/rps3.erl Mon Mar 03 15:42:17 2014 +0900
@@ -1,7 +1,7 @@
-module(rps3).
--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, [H|Tail]) ->
lists:last(Tail);
@@ -13,7 +13,7 @@
beats(H, T).
loses(H) ->
- beats(H, lists:reverse(get_rules())).
+ beats(H, lists:reverse(get_hands())).
% winner for 3 hands is:
% 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
@@ -1,11 +1,11 @@
-module(rps5).
-export([
- get_rules/0,
+ get_hands/0,
beats/1, test_beats/0,
loses/1, test_loses/0,
winning_hand/1, test_winning_hand/0]).
-get_rules() -> [rock, paper, scissors, spock, lizard].
+get_hands() -> [rock, paper, scissors, spock, lizard].
beats(rock) ->
[scissors, lizard];
@@ -42,14 +42,14 @@
fun(H) ->
io:format("~w beats ~w.~n", [H, beats(H)])
end,
- get_rules()).
+ get_hands()).
test_loses() ->
lists:foreach(
fun(H) ->
io:format("~w loses to ~w.~n", [H, loses(H)])
end,
- get_rules()).
+ get_hands()).
% winner for 3 hands is:
% rock, rock, rock -> rock
@@ -69,13 +69,13 @@
end, undefined, HSet).
test_winning_hand() ->
- Exclude = fun(Hand) -> lists:delete(Hand, get_rules()) end,
+ Exclude = fun(Hand) -> lists:delete(Hand, get_hands()) end,
Cases = [
[rock, rock, rock],
[rock, paper, scissors],
[rock, paper, paper],
[rock, rock, paper]
- |lists:map(Exclude, get_rules())
+ |lists:map(Exclude, get_hands())
],
lists:foreach(
fun(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
@@ -10,7 +10,7 @@
receive
{room, Room, Rules} ->
random:seed(now()),
- Hands = apply(Rules, get_rules, []),
+ Hands = apply(Rules, get_hands, []),
fool(Room, Hands)
end.
@@ -32,7 +32,7 @@
copycat(joined) ->
receive
{room, Room, Rules} ->
- copycat(Room, hd(apply(Rules, get_rules, [])))
+ copycat(Room, hd(apply(Rules, get_hands, [])))
end.
copycat(Room, Hand) ->
@@ -52,8 +52,8 @@
gambler(joined) ->
receive
{room, Room, Rules} ->
- 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]),
gambler(Room, Wins)
end.
--- 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
@@ -43,8 +43,8 @@
room(State=#state{rules=Rules, choices=Choices}) ->
receive
{Hand, Who} ->
- 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
true ->
--- 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
@@ -1,8 +1,8 @@
-module(rps3_tests).
-include_lib("eunit/include/eunit.hrl").
-get_rules_test() ->
- ?assertEqual(length(rps3:get_rules()), 3).
+get_hands_test() ->
+ ?assertEqual(length(rps3:get_hands()), 3).
winning_hand_test() ->
?assertEqual(rps3:winning_hand([rock, paper]), paper),