edu.stanford.multiagent.gamer
Class Game

java.lang.Object
  |
  +--edu.stanford.multiagent.gamer.ParameterizedObject
        |
        +--edu.stanford.multiagent.gamer.Game
Direct Known Subclasses:
ArmsRace, BertrandOligopoly, CongestionGame, CournotDuopoly, DispersionGame, GeometricGame, GraphicalGame, GuessTwoThirdsAve, LocalEffectGame, LocationGame, MajorityVoting, MatrixGame, NPlayerChicken, NPlayerPrisonersDilemma, PureCoordinationMatrix, TimingGame, ZeroSumGame

public abstract class Game
extends ParameterizedObject

Abstract class that describes the basic game entity.


Field Summary
protected static Parameters.ParamInfo actions
           
protected static double DEFAULT_HIGH
           
protected static double DEFAULT_LOW
           
protected static Parameters.ParamInfo intMult
           
protected static Parameters.ParamInfo intPayoffs
           
protected static Parameters.ParamInfo players
           
protected static Parameters.ParamInfo pMaxPayoff
           
protected static Parameters.ParamInfo pMinPayoff
           
protected static Parameters.ParamInfo pNormalize
           
protected static Parameters.ParamInfo symActions
           
 
Fields inherited from class edu.stanford.multiagent.gamer.ParameterizedObject
parameters
 
Constructor Summary
protected Game()
          The consctructor.
 
Method Summary
 void generate()
          The generate interface.
 double getAutoNormPayoff(int[] outcome, int player)
          Formats automatically to normalization between 0 and 1 with double payoffs, regardless of parameters.
 java.lang.String getDescription()
          Returns Game Description (Name, Params, etc)
protected abstract  java.lang.String getGameHelp()
          Return help screen information about the given game class.
 java.lang.String getHelp()
          Returns the help screen
 java.lang.String getName()
          Returns just the name of the game.
 double getNormPayoff(int[] outcome, int player)
          Formats and outputs the payoff after normalization according to set flags.
 int[] getNumActions()
          Returns an array containing the number of actions that each player has.
 int getNumActions(int player)
          Returns the number of actions of the given player or a vector of Integers with the numbers of actions.
 int getNumPlayers()
          Returns the number of players in this game
 java.lang.String getOutputPayoff(double payoff)
          Formats and outputs a payoff value according to set flags.
 java.lang.String getOutputPayoff(int[] outcome, int player)
          Formats and outputs the payoff according to set flags.
 java.util.Vector getPayoff(int[] outcome)
          Collects payoffs into a vector.
abstract  double getPayoff(int[] outcome, int player)
          Returns a payoff for a given player.
 java.lang.String getRangeHelp()
          Adds range help information to games which use the range DEFAULT_LOW through DEFAULT_HIGH.
 void initialize()
          Initializes using preset parameter values
protected  void parseActions()
          Parses only the parameter for the number of actions, allowing either the same number for all players, or different numbers for each.
protected  void parsePlayersActions()
          Parses action/player parameters and sets them.
protected  void parsePlayersSameNumberActions()
          Parses action/player parameters and sets them.
protected  void parseSameNumberActions()
          Parses only the parameter for number of actions.
protected  void setDescription(java.lang.String description)
          Sets the description string for the game which will be output as part of the help string.
protected  void setName(java.lang.String name)
          Sets the name of the game.
 void setNormMinAndMax()
          Collects all payoffs (one at a time) and figures out the min and max.
protected  void setNumActions(int nActions)
          Sets same number of actions for each player.
protected  void setNumActions(int[] nActions)
          Sets the number of actions for each player when each player may have a different number of actions.
protected  void setNumPlayers(int nPlayers)
          Sets the number of players in the game.
 void writeGame(java.io.PrintWriter out)
          Writes output in the format specific to this game.
 
Methods inherited from class edu.stanford.multiagent.gamer.ParameterizedObject
checkParameters, doGenerate, getBooleanParameter, getDoubleParameter, getLongParameter, getParamDescription, getParameter, getParameters, getStringParameter, randomizeParameters, setParameter, setParameter, setParameters, setParameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LOW

protected static final double DEFAULT_LOW
See Also:
Constant Field Values

DEFAULT_HIGH

protected static final double DEFAULT_HIGH
See Also:
Constant Field Values

players

protected static Parameters.ParamInfo players

actions

protected static Parameters.ParamInfo actions

symActions

protected static Parameters.ParamInfo symActions

intPayoffs

protected static Parameters.ParamInfo intPayoffs

intMult

protected static Parameters.ParamInfo intMult

pMinPayoff

protected static Parameters.ParamInfo pMinPayoff

pMaxPayoff

protected static Parameters.ParamInfo pMaxPayoff

pNormalize

protected static Parameters.ParamInfo pNormalize
Constructor Detail

Game

protected Game()
        throws java.lang.Exception
The consctructor. Must be called by all subclasses.

Throws:
java.lang.Exception
Method Detail

getDescription

public java.lang.String getDescription()
Returns Game Description (Name, Params, etc)

Overrides:
getDescription in class ParameterizedObject

setDescription

protected void setDescription(java.lang.String description)
Sets the description string for the game which will be output as part of the help string.

Parameters:
description - a description of the game

getName

public java.lang.String getName()
Returns just the name of the game. Should not have any line breaks.


setName

protected void setName(java.lang.String name)
Sets the name of the game.

Parameters:
name - the name of the class of games generated by a given game class

getNumPlayers

public int getNumPlayers()
Returns the number of players in this game


setNumPlayers

protected void setNumPlayers(int nPlayers)
Sets the number of players in the game.

Parameters:
nPlayers - the number of players

getNumActions

public int getNumActions(int player)
Returns the number of actions of the given player or a vector of Integers with the numbers of actions.

Parameters:
player - the index of the player whose actions should be returned

getNumActions

public int[] getNumActions()
Returns an array containing the number of actions that each player has.


setNumActions

protected void setNumActions(int nActions)
                      throws java.lang.Exception
Sets same number of actions for each player. The number of players in the game must have been set before calling this.

Parameters:
nActions - the number of actions each player has
java.lang.Exception

setNumActions

protected void setNumActions(int[] nActions)
                      throws java.lang.Exception
Sets the number of actions for each player when each player may have a different number of actions.

Parameters:
nActions - an array containing the number of actions each player has
Throws:
java.lang.Exception

writeGame

public void writeGame(java.io.PrintWriter out)
               throws java.lang.UnsupportedOperationException
Writes output in the format specific to this game.

Parameters:
out - a PrintWriter to which output can be written
Throws:
java.lang.UnsupportedOperationException - if the given game subclass does not support proprietary output

initialize

public void initialize()
                throws java.lang.Exception
Initializes using preset parameter values

Overrides:
initialize in class ParameterizedObject
Throws:
java.lang.Exception

getHelp

public java.lang.String getHelp()
Returns the help screen

Specified by:
getHelp in class ParameterizedObject

getRangeHelp

public java.lang.String getRangeHelp()
Adds range help information to games which use the range DEFAULT_LOW through DEFAULT_HIGH.


generate

public void generate()
              throws java.lang.Exception
The generate interface. Calls the game specific doGenerate function.

java.lang.Exception

parseActions

protected void parseActions()
                     throws java.lang.Exception
Parses only the parameter for the number of actions, allowing either the same number for all players, or different numbers for each.

Throws:
java.lang.Exception

parsePlayersActions

protected void parsePlayersActions()
                            throws java.lang.Exception
Parses action/player parameters and sets them.

Throws:
java.lang.Exception

parseSameNumberActions

protected void parseSameNumberActions()
                               throws java.lang.Exception
Parses only the parameter for number of actions. Requires that all players have the same number of actions, in other words, number of actions is set by a single integer.

Throws:
java.lang.Exception - if it is not the case that all players have the same number of actions

parsePlayersSameNumberActions

protected void parsePlayersSameNumberActions()
                                      throws java.lang.Exception
Parses action/player parameters and sets them. Requires that all players have the same number of actions.

Throws:
java.lang.Exception - if it is not the case that all players have the same number of actions

getPayoff

public java.util.Vector getPayoff(int[] outcome)
Collects payoffs into a vector. Should be used with caution. Can be overwritten in subclasses if it is more efficient to get all payoffs for each outcome at once.

Parameters:
outcome - an array containing the action choices of all players at the given outcome

setNormMinAndMax

public void setNormMinAndMax()
Collects all payoffs (one at a time) and figures out the min and max. These will later be used for normalization. This is very inefficient since it goes through every payoff in the game. Should be overwritten in subclasses when normalization can be handled more efficiently.

Note that only base double max and min values are calculated here, not the converted integer max and min.


getOutputPayoff

public java.lang.String getOutputPayoff(int[] outcome,
                                        int player)
                                 throws java.lang.Exception
Formats and outputs the payoff according to set flags.

Parameters:
outcome - an array containing all players' action choices at the given outcome
player - tha player whose payoff should be returned
Throws:
java.lang.Exception

getOutputPayoff

public java.lang.String getOutputPayoff(double payoff)
                                 throws java.lang.Exception
Formats and outputs a payoff value according to set flags.

Parameters:
payoff - the value of the payoff to be formatted
Throws:
java.lang.Exception

getNormPayoff

public double getNormPayoff(int[] outcome,
                            int player)
Formats and outputs the payoff after normalization according to set flags.

Parameters:
outcome - an array containing all players' action choices at the given outcome
player - tha player whose payoff should be returned

getAutoNormPayoff

public double getAutoNormPayoff(int[] outcome,
                                int player)
Formats automatically to normalization between 0 and 1 with double payoffs, regardless of parameters.

Parameters:
outcome - an array containing all players' action choices at the given outcome
player - tha player whose payoff should be returned

getPayoff

public abstract double getPayoff(int[] outcome,
                                 int player)
Returns a payoff for a given player.

Parameters:
outcome - array of integers representing which actions have been chosen by each player
player - the player whose payoff to return

getGameHelp

protected abstract java.lang.String getGameHelp()
Return help screen information about the given game class.