--- a/src/rps3.erl Sat Mar 08 23:36:15 2014 +0900
+++ b/src/rps3.erl Sat Mar 08 23:37:19 2014 +0900
handle_call({winning_hand, Hands}, _From, State) ->
{reply, rps_rules:winning_hand(Hands, State), State};
-handle_call({why, H1, H2}, _From, State=#ruleinfo{why=Why}) ->
- {reply, dict:fetch({H1, H2}, Why), State}.
+handle_call({why, H1, H2}, _From, State=#ruleinfo{}) ->
+ {reply, rps_rules:why(H1, H2, State), State}.
handle_cast(_Msg, State) -> {noreply, State}.
--- a/src/rps5.erl Sat Mar 08 23:36:15 2014 +0900
+++ b/src/rps5.erl Sat Mar 08 23:37:19 2014 +0900
handle_call({winning_hand, Hands}, _From, State) ->
{reply, rps_rules:winning_hand(Hands, State), State};
-handle_call({why, H1, H2}, _From, State=#ruleinfo{why=Why}) ->
- {reply, dict:fetch({H1, H2}, Why), State}.
+handle_call({why, H1, H2}, _From, State=#ruleinfo{}) ->
+ {reply, rps_rules:why(H1, H2, State), State}.
handle_cast(_Msg, State) -> {noreply, State}.
--- a/src/rps_rules.erl Sat Mar 08 23:36:15 2014 +0900
+++ b/src/rps_rules.erl Sat Mar 08 23:37:19 2014 +0900
--export([parse/1, winning_hand/2]).
+-export([parse/1, winning_hand/2, why/3]).
-include("rps_rules.hrl").
add_unique(Elem, List) ->
+why(H1, H2, State=#ruleinfo{}) when is_atom(H2) ->
+ atom_to_list(dict:fetch({H1, H2}, State#ruleinfo.why));
+why(H1, Hands, State=#ruleinfo{}) when is_list(Hands) ->
+ F = fun(H2) -> why(H1, H2, State) ++ " " ++ atom_to_list(H2) end,
+ atom_to_list(H1) ++ " " ++ string:join(lists:map(F, Hands), ", ").