Download:
child 39:1cda561a868f
parent 37:674e9537b6ab
38:ec8d1ad0da1d
Anton Shestakov <engored@ya.ru>, Mon, 03 Mar 2014 20:08:31 +0900
Rename #state from rps_rules.hrl to #ruleinfo.

3 файлов изменено, 8 вставок(+), 8 удалений(-) [+]
src/rps3.erl file | annotate | diff | comparison | revisions
src/rps_rules.erl file | annotate | diff | comparison | revisions
src/rps_rules.hrl file | annotate | diff | comparison | revisions
--- a/src/rps3.erl Mon Mar 03 20:06:02 2014 +0900
+++ b/src/rps3.erl Mon Mar 03 20:08:31 2014 +0900
@@ -11,7 +11,7 @@
Text = "scissors cut paper covers rock crushes scissors",
{ok, rps_rules:parse(Text)}.
-handle_call(get_hands, _From, State=#state{hands=Hands}) ->
+handle_call(get_hands, _From, State=#ruleinfo{hands=Hands}) ->
{reply, Hands, State};
% winner for 3 hands is:
@@ -23,7 +23,7 @@
handle_call({winning_hand, Hands}, _From, State) ->
{reply, rps_rules:winning_hand(Hands, State), State};
-handle_call({why, H1, H2}, _From, State=#state{why=Why}) ->
+handle_call({why, H1, H2}, _From, State=#ruleinfo{why=Why}) ->
{reply, dict:fetch({H1, H2}, Why), State}.
handle_cast(_Msg, State) -> {noreply, State}.
--- a/src/rps_rules.erl Mon Mar 03 20:06:02 2014 +0900
+++ b/src/rps_rules.erl Mon Mar 03 20:08:31 2014 +0900
@@ -4,10 +4,10 @@
parse(Text) ->
Tokens = lists:map(fun list_to_atom/1, string:tokens(Text, " ")),
- parse(Tokens, #state{}).
+ parse(Tokens, #ruleinfo{}).
-parse([V1,Label,V2|T], #state{hands=Hands, beats=Beats, loses=Loses, why=Why}) ->
- Acc = #state{
+parse([V1,Label,V2|T], #ruleinfo{hands=Hands, beats=Beats, loses=Loses, why=Why}) ->
+ Acc = #ruleinfo{
hands=[V1|Hands],
beats=dict:append(V1, V2, Beats),
loses=dict:append(V2, V1, Loses),
@@ -23,11 +23,11 @@
% rock, paper, paper -> paper
% rock, rock, paper -> paper
-winning_hand(Hands, State=#state{}) ->
+winning_hand(Hands, State=#ruleinfo{}) ->
HSet = sets:from_list(Hands),
sets:fold(
fun(Hand, Acc) ->
- Loses = dict:fetch(Hand, State#state.loses),
+ Loses = dict:fetch(Hand, State#ruleinfo.loses),
case sets:is_disjoint(sets:from_list(Loses), HSet) of
false -> Acc;
true -> Hand
--- a/src/rps_rules.hrl Mon Mar 03 20:06:02 2014 +0900
+++ b/src/rps_rules.hrl Mon Mar 03 20:08:31 2014 +0900
@@ -1,1 +1,1 @@
--record(state, {hands=[], beats=dict:new(), loses=dict:new(), why=dict:new()}).
+-record(ruleinfo, {hands=[], beats=dict:new(), loses=dict:new(), why=dict:new()}).