Download:
child 8:94027114ff65
parent 6:bb8fdb49d6ba
7:14b33824d432
Anton Shestakov <engored@ya.ru>, Tue, 25 Feb 2014 23:16:04 +0900
Add copycat bot. It copies the winning hand all the time.

1 файлов изменено, 21 вставок(+), 2 удалений(-) [+]
rps.erl file | annotate | diff | comparison | revisions
--- a/rps.erl Sun Feb 23 16:38:28 2014 +0900
+++ b/rps.erl Tue Feb 25 23:16:04 2014 +0900
@@ -3,10 +3,10 @@
go/0,
beats/1, winner/1,
lobby/0, counter/0, printer/0, room/1,
- fool/0]).
+ fool/0, copycat/0]).
-define(RULES, [rock, paper, scissors]).
--define(BOTS, [fool, fool, fool]).
+-define(BOTS, [fool, copycat, fool]).
beats(C) ->
beats(C, ?RULES).
@@ -135,3 +135,22 @@
{winner, _} ->
fool(Room)
end.
+
+copycat() ->
+ lobby ! {join, self()},
+ copycat(joined).
+
+copycat(joined) ->
+ receive
+ {room, Room} ->
+ copycat(Room, hd(?RULES))
+ end.
+
+copycat(Room, Choice) ->
+ receive
+ start ->
+ Room ! {Choice, self()},
+ copycat(Room, Choice);
+ {winner, {NewChoice, _}} ->
+ copycat(Room, NewChoice)
+ end.