Permalink
Browse files

Player randy

  • Loading branch information...
Matthew Tovbin
Matthew Tovbin committed Mar 25, 2012
1 parent 446518a commit 4c35605a5d61d3bfc5a53938f7f7126aa1c9eaf2
Showing with 36 additions and 0 deletions.
  1. +36 −0 src/players/rpsls_randy_player.erl
@@ -0,0 +1,36 @@
%% @author Matthew Tovbin <tovbinm@gmail.com>
%% @doc Randy is another random player.
%%
%% Explanation:
%% Similar to RPS game, RPSLS is a balanced game, i.e. win chances distribute uniformely over all the choices.
%% So it is impossible to gain an advantage over a truly random opponent.
%% This can be easily seen by looking into the RPSLS normal form matrix (http://goo.gl/UTzgE), which is one of magic square
%% matrices that sums to 0 in any column/row.
%% Additionally one can easily be verify the chances of winning in each round by solving the following linear program:
%% (build from the normal form matrix)
%%
%% maximize x0 subject to:
%% -x2 + x3 + x4 - x5 - x0 >= 0
%% x1 - x3 - x4 + x5 - x0 >= 0
%% -x1 + x2 + x4 - x5 - x0 >= 0
%% -x1 + x2 - x3 + x5 - x0 >= 0
%% x1 - x2 + x3 - x4 - x0 >= 0
%% x1 + x2 + x3 + x4 + x5 == 1
%% where: x0,x1,x2,x3,x4,x5 >= 0
%%
%% Which gives us an optimal solution of: (0.2, 0.2, 0.2, 0.2, 0.2), i.e. uniform distribution.
%%
-module(rpsls_randy_player).
-author('Matthew Tovbin <tovbinm@gmail.com>').
-behaviour(rpsls_player).
-export([init/0, play/2]).
%% @private
-spec init() -> State::term().
init() -> _ = random:seed(erlang:now()), {}. %% God, bless my seed ;))
-spec play(History::[{You::rpsls_player:choice(), Rival::rpsls_player:choice()}], State::term()) -> {rpsls_player:choice(), NewState::term()}.
play(_History, {}) -> {lists:nth(random:uniform(5), [rock, paper, scissors, lizard, spock]), {}}.

0 comments on commit 4c35605

Please sign in to comment.