utilities
Class Game

java.lang.Object
  |
  +--utilities.Game

public class Game
extends java.lang.Object

Holds a standard two player game. A game has several options. Strategic: not used by this class, but says whether the payoff depends on other players (this is not independently calculated by the class, you must set it). Stochastic: if the payoffs provided represent the mean of the payoffs returned or if the payoffs returned should be exactly the one in the matrix.

Author:
Kevin Zollman

Constructor Summary
Game(boolean so)
          Returns a game object.
Game(boolean so, MersenneTwister r)
          Returns a game object.
Game(int[][] m, boolean so)
          Returns a game object.
Game(int[][] m, boolean so, MersenneTwister r)
          Returns a game object.
Game(int[][] m, boolean so, MersenneTwister r, boolean st)
          Returns a game object
 
Method Summary
 int getExpectedPayoff(int r)
          Returns the expected payoff of strategy r against strategy 0.
 int getExpectedPayoff(int r, int c)
          Returns the expected payoff of strategy r against strategy c.
 int getHighestPayoff()
          Tells you the highest possible value that will be returned.
 int[][] getMatrix()
          Gets the payoff matrix
 double getNormPayoff(int r)
          Returnes a normalized payoff as a double between 0 and 1 of r played against strategy 0.
 double getNormPayoff(int r, int c)
          Returnes a normalized payoff as a double between 0 and 1 of r played against strategy c.
 int getPayoff(int r)
          Returns the payoff for strategy r against strategy 0, only usefully for non-strategic games.
 int getPayoff(int r, int c)
          Returns the payoff for strategy r against strategy c.
 double getProb(int r, int p)
          Tells you the probabiliy of receiving a particular payoff given that the player played strategy r against strategy 0.
 double getProb(int r, int c, int p)
          Tells you the probability of receiving a particular payoff given that the player played strategy r against c.
 MersenneTwister getRandom()
          Returns the random number generator used
 boolean getStochastic()
          A function to determine if the game is stochastic.
 int getStrats()
          Tells you the number of strategies
 boolean isStrategic()
          A function to say if the game is marked as strategic.
 void setBigPayoff(int bp)
          Sets the biggest possible payoff, and then recalculates the probabilites based on that.
 void setMatrix(int[][] m)
          Sets the payoff matrix.
 void setMatrix(int[][] m, int bp)
          Sets the payoff matrix.
 void setRandom(MersenneTwister r)
          Sets the random number generator
 void setStochastic(boolean s)
          A function to set if the game is stochastic.
 void setStrategic(boolean st)
          A function to set if the game is strategic.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Game

public Game(boolean so)
Returns a game object. Presumes the game is strategic.

Parameters:
so - a boolean to determine if the game is stochastic or not

Game

public Game(int[][] m,
            boolean so)
     throws ModelError
Returns a game object. Presumes the game is strategic.

Parameters:
m - is the matrix of the game
so - is a boolean to determine if the game is stochstic or not
Throws:
ModelError - if there is a problem with the matrix

Game

public Game(int[][] m,
            boolean so,
            MersenneTwister r)
     throws ModelError
Returns a game object. Presumes the game is strategic

Parameters:
m - the game matrix
so - a boolean to determin if the game is stochastic
r - the random number generator
Throws:
ModelError - if there is a problem with the matrix

Game

public Game(int[][] m,
            boolean so,
            MersenneTwister r,
            boolean st)
     throws ModelError
Returns a game object

Parameters:
m - the game matrix
so - a boolean to determine if the game is stochastic
r - the random number generator
st - a boolean to determine if the game is strategic
Throws:
ModelError - if there is a problem with the matrix

Game

public Game(boolean so,
            MersenneTwister r)
Returns a game object. Presumes the game is strategic.

Parameters:
so - a boolean to determine if the game is stochastic
r - the random number generator
Method Detail

setStrategic

public void setStrategic(boolean st)
A function to set if the game is strategic. A game is strategic if the payoffs are determined by the other actors. This is not used in the class at all, but is used by the individual class in order to decide if the game is played more than once.

Parameters:
st - A bolean to say if the game is strategic or not

isStrategic

public boolean isStrategic()
A function to say if the game is marked as strategic.

Returns:
if the game is strategic

setStochastic

public void setStochastic(boolean s)
A function to set if the game is stochastic. If the game is stochastic the payoff provided is the mean of a binomial distribution. If the game is not stochatic, the payoff returned is exactly the one in the matrix.

Parameters:
s - A boolean to say if the game is stochastic or not

getStochastic

public boolean getStochastic()
A function to determine if the game is stochastic.

Returns:
if the game is stochastic

getMatrix

public int[][] getMatrix()
Gets the payoff matrix

Returns:
the two dimensional integer matrix that represents the payoffs of the game

setMatrix

public void setMatrix(int[][] m)
               throws ModelError
Sets the payoff matrix. This function presumes that the stochastic value is already set. Matrices cannot have negative payoffs, this would screw up reinforcement learning. If the game is stochastic, it calculates the highest possible payoff as being the highest matrix payoff + the smalles matrix payoff. The distribution is then a binomial distribution, from 0 to the highest possible payoff with a mean of the value provided in the matrix.

Parameters:
m - A two dimensional integer array with the matrix
Throws:
ModelError - if the matrix is malformed

setMatrix

public void setMatrix(int[][] m,
                      int bp)
               throws ModelError
Sets the payoff matrix. Matrices cannot have negative payoffs, this would screw up reinforcement learning. The distribution of payoffs returned for stochastic games is a binomial distribution between 0 and bp with a mean of the value provided in the matrix

Parameters:
m - The payoff matrix
bp - The bigest possible payoff (for stochastic games).
Throws:
ModelError - if there is a problem with the matrix

setBigPayoff

public void setBigPayoff(int bp)
Sets the biggest possible payoff, and then recalculates the probabilites based on that. The payoffs returned are binomially distributed between 0 and bp

Parameters:
bp - the big payoff

getStrats

public int getStrats()
Tells you the number of strategies

Returns:
the number of strategies in the game

getHighestPayoff

public int getHighestPayoff()
Tells you the highest possible value that will be returned. In stochastic games this is the biggest possible value (different from the larges value in the matrix). In non- stochastic games this is the highest value in the matrix.

Returns:
the biggest possible payoff that will be returned

getProb

public double getProb(int r,
                      int c,
                      int p)
Tells you the probability of receiving a particular payoff given that the player played strategy r against c.

Parameters:
r - the player's strategy
c - the opponent's strategy
p - the payoff received
Returns:
the probability of the player getting that payoff given r and c

getProb

public double getProb(int r,
                      int p)
Tells you the probabiliy of receiving a particular payoff given that the player played strategy r against strategy 0. This should only be used for non-strategic games otherwise it gives you strange results.

Parameters:
r - the player's strategy
p - the payoff received
Returns:
the probability of that player getting that payoff given r

getRandom

public MersenneTwister getRandom()
Returns the random number generator used


setRandom

public void setRandom(MersenneTwister r)
Sets the random number generator


getPayoff

public int getPayoff(int r)
Returns the payoff for strategy r against strategy 0, only usefully for non-strategic games. The payoff returned will be between zero and the highest payoff. This will be the same for every call if the game is non-stochastic, but different if stochastic.

Parameters:
r - the strategy employed
Returns:
the payoff

getPayoff

public int getPayoff(int r,
                     int c)
Returns the payoff for strategy r against strategy c. The payoff returned will be between zero and the highest payoff. This will be the same for every call if the game is non-stochastic, but different if stochastic.

Parameters:
r - the strategy employed
c - the strategy of the opponent
Returns:
the payoff

getNormPayoff

public double getNormPayoff(int r)
Returnes a normalized payoff as a double between 0 and 1 of r played against strategy 0. This should only be used with non-strategic games. The payoff will be the same for every call if the game is non-stochastic, but different if stochastic.

Parameters:
r - the strategy
Returns:
a double in [0,1]

getNormPayoff

public double getNormPayoff(int r,
                            int c)
Returnes a normalized payoff as a double between 0 and 1 of r played against strategy c. The payoff will be the same for every call if the game is non-stochastic, but different if stochastic.

Parameters:
r - the strategy
c - the opponent's strategy
Returns:
a double in [0,1]

getExpectedPayoff

public int getExpectedPayoff(int r)
Returns the expected payoff of strategy r against strategy 0. This function is used to circumvent stochastic games and get what is actually in the supplied matrix. This function should only be used in non-strategic games

Parameters:
r - the strategy
Returns:
the expected payoff

getExpectedPayoff

public int getExpectedPayoff(int r,
                             int c)
Returns the expected payoff of strategy r against strategy c. This function is used to circumvent stochastic games and get what is actually in the supplied matrix.

Parameters:
r - the strategy
c - the opponent's strategy
Returns:
the expected payoff