com.bolinfest.prisonerbot
Class SimplePayoffMatrix

java.lang.Object
  extended by com.bolinfest.prisonerbot.SimplePayoffMatrix
All Implemented Interfaces:
PayoffMatrix

public class SimplePayoffMatrix
extends Object
implements PayoffMatrix

SimplePayoffMatrix is a simple PayoffMatrix that can be created from an array of integers.

Author:
mbolin

Field Summary
 
Fields inherited from interface com.bolinfest.prisonerbot.PayoffMatrix
CANONICAL_PAYOFF_MATRIX
 
Constructor Summary
SimplePayoffMatrix(int[][] p, String name, String description)
          Create a possibly unsymmetric payoff matrix.
SimplePayoffMatrix(int t, int r, int p, int s, String name, String description)
          This creates a symmetric payoff matrix that conforms to the T > R > P > S principle.
 
Method Summary
 int[] calculatePayoff(Choice firstPlayerChoice, Choice secondPlayerChoice)
          Get the payoff for a given set of choices.
 int[] getAllPayoffs()
           
 String getDescription()
           
 String getName()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimplePayoffMatrix

public SimplePayoffMatrix(int t,
                          int r,
                          int p,
                          int s,
                          String name,
                          String description)
This creates a symmetric payoff matrix that conforms to the T > R > P > S principle. In the "canonical" payoff matrix: T = 5, R = 3, P = 1, S = 0

These constraints are explained in the Prisoner's dilemma entry in the Wikipedia

Parameters:
t - the temptation to defect (what you get if the other player cooperates)
r - the reward for mutual cooperation
p - the punishment for mutual defection
s - the "sucker's payoff" (what you get when the other player defects)
Throws:
IllegalArgumentException - if t > r > p > s does not hold

SimplePayoffMatrix

public SimplePayoffMatrix(int[][] p,
                          String name,
                          String description)
Create a possibly unsymmetric payoff matrix. The argument for the "canonical" payoff matrix would be the following:
 int[][] p = { {3, 3}, {0, 5},
               {5, 0}, {1, 1}  };      
 

Parameters:
p - must be a 4x2 array whose values represent the Prisoner's Dilemma payoff matrix as follows:
              | B2 cooperate     | B2 defect        |
 ---------------------------------------------------- 
 B1 cooperate | p[0][0], p[0][1] | p[1][0], p[1][1] |
 ----------------------------------------------------
 B1 defect    | p[2][0], p[2][1] | p[3][0], p[3][1] |
 ----------------------------------------------------
 
Where for each entry (x, y) in the table, x is B1's payoff and y is B2's payoff.
Throws:
IllegalArgumentException - if the array is not 4x2
Method Detail

calculatePayoff

public int[] calculatePayoff(Choice firstPlayerChoice,
                             Choice secondPlayerChoice)
Description copied from interface: PayoffMatrix
Get the payoff for a given set of choices.

Specified by:
calculatePayoff in interface PayoffMatrix
Parameters:
firstPlayerChoice - the choice made by the first player
secondPlayerChoice - the choice made by the second player
Returns:
an int array of length 2 where the first element is the payoff for the first player and the second element is the payoff for the second player

getName

public String getName()
Specified by:
getName in interface PayoffMatrix
Returns:
the name of the PayoffMatrix

getDescription

public String getDescription()
Specified by:
getDescription in interface PayoffMatrix
Returns:
a description of the PayoffMatrix

getAllPayoffs

public int[] getAllPayoffs()
Specified by:
getAllPayoffs in interface PayoffMatrix

toString

public String toString()
Overrides:
toString in class Object