Anton Shestakov <engored@ya.ru>, Sat, 08 Mar 2014 23:46:38 +0900
Strictly speaking, rps_rules has no state.
src/rps_bots.erl
Permissions: -rw-r--r--
-export([fool/0, copycat/0, gambler/0]). rps_nickserv:nick(self(), "fool"), Hands = apply(Rules, get_hands, []), Hand = lists:nth(random:uniform(length(Hands)), Hands), rps_nickserv:nick(self(), "copycat"), copycat(Room, hd(apply(Rules, get_hands, []))) {winner, {NewHand, _}} -> rps_nickserv:nick(self(), "gambler"), Hands = apply(Rules, get_hands, []), Wins = dict:from_list([{Hand, 0} || Hand <- Hands]), F = fun({_, A}, {_, B}) -> A =< B end, {Hand, _} = hd(lists:sort(F, dict:to_list(Wins))), gambler(Room, dict:update_counter(Hand, 1, Wins))