Commits

Anton Shestakov committed 2e633dc

Strictly speaking, rps_rules has no state.

  • Participants
  • Parent commits eab83ba

Comments (0)

Files changed (1)

src/rps_rules.erl

 % rock, paper, paper    -> paper
 % rock, rock, paper     -> paper
 
-winning_hand(Hands, State=#ruleinfo{}) ->
+winning_hand(Hands, Ruleinfo=#ruleinfo{}) ->
     HSet = sets:from_list(Hands),
     sets:fold(
         fun(Hand, Acc) ->
-            Loses = dict:fetch(Hand, State#ruleinfo.loses),
+            Loses = dict:fetch(Hand, Ruleinfo#ruleinfo.loses),
             case sets:is_disjoint(sets:from_list(Loses), HSet) of
                 false -> Acc;
                 true -> Hand
             end
         end, undefined, HSet).
 
-why(H1, H2, State=#ruleinfo{}) when is_atom(H2) ->
-    atom_to_list(dict:fetch({H1, H2}, State#ruleinfo.why));
+why(H1, H2, Ruleinfo=#ruleinfo{}) when is_atom(H2) ->
+    atom_to_list(dict:fetch({H1, H2}, Ruleinfo#ruleinfo.why));
 
-why(H1, Hands, State=#ruleinfo{}) when is_list(Hands) ->
-    F = fun(H2) -> why(H1, H2, State) ++ " " ++ atom_to_list(H2) end,
+why(H1, Hands, Ruleinfo=#ruleinfo{}) when is_list(Hands) ->
+    F = fun(H2) -> why(H1, H2, Ruleinfo) ++ " " ++ atom_to_list(H2) end,
     atom_to_list(H1) ++ " " ++ string:join(lists:map(F, Hands), ", ").