rockemsockemrationalagents

find nash equilibrium with fictitious play
git clone https://wehaveforgeathome.hates.computer/rockemsockemrationalagents.git
Log | Files | Refs | LICENSE

commit 0d4605487ae6cdcbe41b0a9fcd6b9b9f2b7476eb
parent 420418b1e49b96c106393180fb1b23622ec01e91
Author: Ryan Wolf <rwolf@borderstylo.com>
Date:   Mon,  1 Mar 2010 14:25:24 -0800

take payoff matrix as command line arguments

Diffstat:
MREADME.md | 22+++++++++++++++++-----
Mresera.pl | 17++++++++++++-----
2 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/README.md b/README.md @@ -8,17 +8,29 @@ See [prisoner's dilemma](http://en.wikipedia.org/wiki/Prisoner%27s_dilemma), [st Usage ----- -The board is hard-coded into resara.pl, so edit and run it: +To test payoff matrix: - $ perl resera.pl - Player Column: (100.000000%, 0.000000%) - Player Row: (100.000000%, 0.000000%) + Choice 1 | Choice 2 + ------------------- + Choice 1 | a, b | c, d + Choice 2 | e, f | g, h + +Run resera.pl with the arguments + + $ perl resera.pl a b c d e f g h + +For example, using the Example PD payoff matrix for the wiki page [prisoner's dilemma](http://en.wikipedia.org/wiki/Prisoner%27s_dilemma): + + $ perl resera.pl 3 3 0 5 5 0 1 1 + Player Column: (0.000000%, 100.000000%) + Player Row: (0.000000%, 100.000000%) + +The output describes the strategy our players mimicked (both players always chose the second option, e.g. "always defect"). TODO ----- * expand summary -* take the board as command line arguments * ouput the board * there's a lot of room to optimise (precomputing $a-$b-$c+$d instead of finding it n times comes immediately to mind)--faster means more iterations * add a fun license diff --git a/resera.pl b/resera.pl @@ -3,12 +3,19 @@ use strict; use warnings; -my $choices = [[0,0], [0,0]]; +# default taken from http://en.wikipedia.org/wiki/Prisoner%27s_dilemma +my $grid = [ + [[3, 3], [0, 5]], + [[5, 0], [1, 1]] +]; +if (scalar @ARGV == 8) { + $grid = [ + [[$ARGV[0], $ARGV[1]], [$ARGV[2], $ARGV[3]]], + [[$ARGV[4], $ARGV[5]], [$ARGV[6], $ARGV[7]]] + ]; +} -my $grid = -# col 0 col 1 -[[[1,1], [0,0]], # row 0 - [[0,0], [0,0]]]; # row 1 +my $choices = [[0,0], [0,0]]; my $iterations = 10000;