Download:
child 42:82a465d8a5c1
parent 40:7d4b76367349
41:f32e096c5433
Anton Shestakov <engored@ya.ru>, Mon, 03 Mar 2014 22:17:50 +0900
Add only unique hands to #ruleinfo.hands.

1 файлов изменено, 7 вставок(+), 1 удалений(-) [+]
src/rps_rules.erl file | annotate | diff | comparison | revisions
--- a/src/rps_rules.erl Mon Mar 03 22:17:13 2014 +0900
+++ b/src/rps_rules.erl Mon Mar 03 22:17:50 2014 +0900
@@ -2,13 +2,19 @@
-export([parse/1, winning_hand/2]).
-include("rps_rules.hrl").
+add_unique(Elem, List) ->
+ case lists:member(Elem, List) of
+ true -> List;
+ false -> [Elem|List]
+ end.
+
parse(Text) ->
Tokens = lists:map(fun list_to_atom/1, string:tokens(Text, " ")),
parse(Tokens, #ruleinfo{}).
parse([V1,Label,V2|T], #ruleinfo{hands=Hands, beats=Beats, loses=Loses, why=Why}) ->
Acc = #ruleinfo{
- hands=[V1|Hands],
+ hands=add_unique(V1, Hands),
beats=dict:append(V1, V2, Beats),
loses=dict:append(V2, V1, Loses),
why=dict:store({V1, V2}, Label, Why)},