The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Game::Theory::TwoPersonMatrix - Analyze a 2 person matrix game

VERSION

version 0.2007

SYNOPSIS

 use Game::Theory::TwoPersonMatrix;

 my $g = Game::Theory::TwoPersonMatrix->new(
    1 => { 1 => 0.2, 2 => 0.3, 3 => 0.5 },
    2 => { 1 => 0.1, 2 => 0.7, 3 => 0.2 },
    payoff => [ [-5, 4, 6],
                [ 3,-2, 2],
                [ 2,-3, 1] ]
 );
 $g->row_reduce();
 $g->col_reduce();
 my $player = 1;
 my $p = $g->saddlepoint();
 my $o = $g->oddments();
 my $e = $g->expected_payoff();
 my $c = $g->counter_strategy($player);
 my $u = $g->play();

 $g = Game::Theory::TwoPersonMatrix->new(
    1 => { 1 => 0.1, 2 => 0.2, 3 => 0.7 },
    2 => { 1 => 0.1, 2 => 0.2, 3 => 0.3, 4 => 0.4 },
    # Payoff table for the row player
    payoff1 => [ [5,3,8,2],   # 1
                 [6,5,7,1],   # 2
                 [7,4,6,0] ], # 3
    # Payoff table for the column player (opponent)
    #             1 2 3 4
    payoff2 => [ [2,0,1,3],
                 [3,4,4,1],
                 [5,6,8,2] ],
 );
 my $t = $g->mm_tally();
 my $m = $g->pareto_optimal();
 my $n = $g->nash();
 $e = $g->expected_payoff();
 $c = $g->counter_strategy($player);
 $u = $g->play();

DESCRIPTION

A Game::Theory::TwoPersonMatrix analyzes a two person matrix game of player names, strategies and utilities ("payoffs").

Players 1 and 2 are the "row" and "column" players, respectively. This is due to the tabular format of a matrix game:

                  Player 2
                  --------
         Strategy 0.5  0.5
 Player |   0.5    1   -1  < Payoff
    1   |   0.5   -1    1  <

A non-zero sum game is represented by two payoff profiles, as above in the SYNOPSIS.

METHODS

new()

 $g = Game::Theory::TwoPersonMatrix->new(
    1 => { 1 => 0.5, 2 => 0.5 },
    2 => { 1 => 0.5, 2 => 0.5 },
    payoff => [ [1,0],
                [0,1] ]
 );
 $g = Game::Theory::TwoPersonMatrix->new(
    payoff1 => [ [2,3],
                 [2,1] ],
    payoff2 => [ [3,5],
                 [2,3] ],
 );

Create a new Game::Theory::TwoPersonMatrix object.

Player strategies are given by a hash reference of numbered keys - one for each strategy. Payoffs are given by array references of lists of outcomes. For zero-sum games this is a single payoff list. For non-zero-sum games this is given as two lists - one for each player.

expected_payoff()

 $e = $g->expected_payoff();

Return the expected payoff value of a game.

s_expected_payoff()

 $g = Game::Theory::TwoPersonMatrix->new(
    1 => { 1 => '(1 - p)', 2 => 'p' },
    2 => { 1 => 1, 2 => 0 },
    payoff => [ ['a','b'], ['c','d'] ]
 );
 $s = $g->s_expected_payoff();

Return the symbolic expected payoff expression for a non-numeric game.

Using real payoff values, we solve the resulting expression for p in the eg/ examples.

counter_strategy()

 $c = $g->counter_strategy($player);

Return the expected payoff, for a given player, of either a zero-sum or non-zero-sum game, given pure opponent strategies.

saddlepoint()

 $p = $g->saddlepoint;

Return the saddlepoint of a zero-sum game, or undef if there is none.

A saddlepoint is simultaneously minimum for its row and maximum for its column.

oddments()

 $o = $g->oddments();

Return each player's "oddments" for a 2x2 zero-sum game with no saddlepoint.

row_reduce()

 $g->row_reduce();

Reduce a zero-sum game by identifying and eliminating strictly dominated rows and their associated player strategies.

col_reduce()

 $g->col_reduce();

Reduce a zero-sum game by identifying and eliminating strictly dominated columns and their associated opponent strategies.

mm_tally()

 $t = $g->mm_tally();

For zero-sum games, return the maximum of row minimums and the minimum of column maximums. For non-zero-sum games, return the maximum of row and column minimums.

pareto_optimal()

 $m = $g->pareto_optimal();

Return the Pareto optimal outcomes for a non-zero-sum game.

nash()

 $n = $g->nash();

Identify the Nash equilibria in a non-zero-sum game.

Given payoff pair (a,b), a is maximum for its column and b is maximum for its row.

play()

 $u = $g->play();
 $u = $g->play(%strategies);

Return a single outcome for a zero-sum game or a pair for a non-zero-sum game.

An optional list of player strategies can be provided. This is a hashref of the same type of strategies that are given to the constructor.

SEE ALSO

The eg/ and t/ scripts in this distribution.

"A Gentle Introduction to Game Theory"

http://www.amazon.com/Gentle-Introduction-Theory-Mathematical-World/dp/0821813390

http://books.google.com/books?id=8doVBAAAQBAJ

AUTHOR

Gene Boggs <gene@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by Gene Boggs.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.