--- a/src/rps3.erl Mon Mar 03 20:06:02 2014 +0900
+++ b/src/rps3.erl Mon Mar 03 20:08:31 2014 +0900
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}) ->
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
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}) ->
+parse([V1,Label,V2|T], #ruleinfo{hands=Hands, beats=Beats, loses=Loses, why=Why}) ->
beats=dict:append(V1, V2, Beats),
loses=dict:append(V2, V1, Loses),
% rock, paper, paper -> paper
% rock, rock, paper -> paper
-winning_hand(Hands, State=#state{}) ->
+winning_hand(Hands, State=#ruleinfo{}) ->
HSet = sets:from_list(Hands),
- Loses = dict:fetch(Hand, State#state.loses),
+ Loses = dict:fetch(Hand, State#ruleinfo.loses),
case sets:is_disjoint(sets:from_list(Loses), HSet) of
--- 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
--record(state, {hands=[], beats=dict:new(), loses=dict:new(), why=dict:new()}).
+-record(ruleinfo, {hands=[], beats=dict:new(), loses=dict:new(), why=dict:new()}).