Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Two new players

  • Loading branch information...
commit a08f2f6794d70240f099bfef1128179eddf9bd7e 1 parent 2a60397
authored May 04, 2012
16  src/players/rpsls_leor_player.erl
... ...
@@ -0,0 +1,16 @@
  1
+%% @author Leor Leor <leorleor@gmail.com>
  2
+%% @copyright 2012
  3
+%% @doc Rockem Spockem bot by Leor
  4
+-module(rpsls_leor_player).
  5
+-author(' Leor Leor <leorleor@gmail.com>').
  6
+
  7
+-behaviour(rpsls_player).
  8
+
  9
+-export([init/0, play/2]).
  10
+
  11
+%% @private
  12
+-spec init() -> State::term().
  13
+init() -> _ = random:seed(erlang:now()), {}.
  14
+
  15
+-spec play(History::[{You::rpsls_player:choice(), Rival::rpsls_player:choice()}], State::term()) -> {rpsls_player:choice(), NewState::term()}.
  16
+play(_History, {}) -> {lists:nth(random:uniform(5), [paper, scissors, spock, rock, lizard]), {}}.
43  src/players/rpsls_marcelo_player.erl
... ...
@@ -0,0 +1,43 @@
  1
+%% @author Fernando Benavides <fernando.benavides@inakanetworks.com>
  2
+%% @copyright 2012 Inaka Networks
  3
+%% @doc Player that always choose spock
  4
+-module(rpsls_marcelo_player).
  5
+-author('Fernando Benavides <fernando.benavides@inakanetworks.com>').
  6
+
  7
+-behaviour(rpsls_player).
  8
+
  9
+-export([init/0, play/2]).
  10
+
  11
+%% @private
  12
+-spec init() -> State::term().
  13
+init() -> spock.
  14
+
  15
+-spec play(History::[{You::rpsls_player:choice(), Rival::rpsls_player:choice()}], State::term()) -> {rpsls_player:choice(), NewState::term()}.
  16
+
  17
+choose_winner(spock) ->
  18
+	lizard;
  19
+
  20
+choose_winner(lizard) ->
  21
+	rock;
  22
+
  23
+choose_winner(rock) ->
  24
+	paper;
  25
+
  26
+choose_winner(paper) ->
  27
+	scissors;
  28
+
  29
+choose_winner(scissors) ->
  30
+	spock.
  31
+
  32
+play(History, _State) ->
  33
+	MoveCount = lists:foldl(
  34
+		fun(Round, Acc) ->
  35
+			{_Mine, Opponent} = Round,
  36
+			{Opponent,Times} = lists:keyfind(Opponent, 1, Acc),
  37
+			lists:keystore(Opponent, 1, Acc, {Opponent, Times + 1})
  38
+		end,
  39
+		[{spock, 0}, {scissors, 0}, {paper, 0}, {rock, 0}, {lizard, 0}],
  40
+		History
  41
+	),
  42
+	{Move, _Times} = lists:last(lists:keysort(2, MoveCount)),
  43
+	{choose_winner(Move), _State}.

0 notes on commit a08f2f6

Please sign in to comment.
Something went wrong with that request. Please try again.