--- a/src/rps.erl Sat Mar 01 23:02:31 2014 +0900
+++ b/src/rps.erl Sat Mar 01 23:07:50 2014 +0900
--import(rps3, [get_rules/0]).
- lobby/0, counter/0, printer/0,
- fool/0, copycat/0, gambler/0]).
+ lobby/0, counter/0, printer/0]).
-define(BOTS, [fool, copycat, gambler]).
register(lobby, spawn_link(?MODULE, lobby, [])),
register(counter, spawn_link(?MODULE, counter, [])),
register(printer, spawn_link(?MODULE, printer, [])),
- [spawn_link(?MODULE, Bot, []) || Bot <- ?BOTS].
+ [spawn_link(rps_bots, Bot, []) || Bot <- ?BOTS].
counter ! {sendstats, self()}
- lobby ! {join, self()},
- Hand = lists:nth(random:uniform(length(get_rules())), get_rules()),
- lobby ! {join, self()},
- copycat(Room, hd(get_rules()))
- {winner, {NewHand, _}} ->
- lobby ! {join, self()},
- Wins = dict:from_list([{C, 0} || C <- get_rules()]),
- F = fun({_, A}, {_, B}) -> A =< B end,
- {Hand, _} = hd(lists:sort(F, dict:to_list(Wins))),
- gambler(Room, dict:update_counter(Hand, 1, Wins))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/rps_bots.erl Sat Mar 01 23:07:50 2014 +0900
+-import(rps3, [get_rules/0]).
+-export([fool/0, copycat/0, gambler/0]).
+ lobby ! {join, self()},
+ Hand = lists:nth(random:uniform(length(get_rules())), get_rules()),
+ lobby ! {join, self()},
+ copycat(Room, hd(get_rules()))
+ {winner, {NewHand, _}} ->
+ lobby ! {join, self()},
+ Wins = dict:from_list([{C, 0} || C <- get_rules()]),
+ F = fun({_, A}, {_, B}) -> A =< B end,
+ {Hand, _} = hd(lists:sort(F, dict:to_list(Wins))),
+ gambler(Room, dict:update_counter(Hand, 1, Wins))