44:8d400faca258
Anton Shestakov <engored@ya.ru>, Thu, 06 Mar 2014 19:39:46 +0900
Use ~p instead of ~w for win stats, overall more human-friendly format in printer.

next change 51:24ba56a575b1
previous change 42:82a465d8a5c1

src/rps5.erl

Permissions: -rw-r--r--

Other formats: Feeds:
-module(rps5).
-behaviour(gen_server).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
-export([start_link/0, get_hands/0, winning_hand/1, why/2]).
-include("rps_rules.hrl").
start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
init([]) ->
Text = "scissors cut paper covers rock crushes lizard poisons spock smashes scissors decapitate lizard eats paper disproves spock vaporizes rock crushes scissors",
{ok, rps_rules:parse(Text)}.
handle_call(get_hands, _From, State=#ruleinfo{hands=Hands}) ->
{reply, Hands, State};
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_cast(_Msg, State) -> {noreply, State}.
handle_info(_Msg, State) -> {noreply, State}.
terminate(_Reason, _State) -> ok.
code_change(_OldVersion, State, _Extra) -> {ok, State}.
get_hands() ->
gen_server:call(?MODULE, get_hands).
winning_hand(Hands) ->
gen_server:call(?MODULE, {winning_hand, Hands}).
why(H1, H2) ->
gen_server:call(?MODULE, {why, H1, H2}).