Games API Documentation



class GameState
: Encapsulates all relevant information about a game state, and provides methods for move and successor generation and terminal testing.
XXXGameState()
Get the initial game state for game XXX

getPlayers()
Get a tuple of player names, where element [0] is the current player
currentPlayer()
Get the name of the player who should make the next move

actions()
Get the list of legal actions from this state
successor(action)
Get the successor of this state on this action
successors()
Get the list of legal (action, successor) pairs from this state
shuffledSuccessors()
Same as successors() except returns results in random order

utility()
Tests whether the current state is terminal.
If so, returns a Dictionary mapping player names to utility values.
If not, returns None.
currentPlayerUtility()
Same as utility(), but returns only the utiltity of currentPlayer()

The remaining functions in GameState take care of equality testing, hashing, and record keeping; you can safely ignore them.  Most of the above functions are provided for convenience -- you only really need getPlayers(), successors(), and utility() to complete the assignment, but the others may make your job easier.


Some games: We defined a few games for you and your agents to play, which all implement the GameState interface.

tictactoe.TicTacToeGameState()
Get the initial game state for standard 3x3 Tic Tac Toe.  Player names are "X" and "O".  You don't need to know anything about the internals of this class.
nim.NimGameState(board = [7,7,7])
Get the initial game state for "normal play" Nim, in which players can take any number of objects from any single pile on a turn, and the goal is to take the last object.   By default, there are 3 piles, each with 7 objects; this can be overriden by passing in a list of piles.  Player names are "1" and "2".  All you need to know about the internals of this class is that it has a property board that represents the state of the remaining piles as a list of sizes. 
othello.OthelloGameState(boardSize = 8)
Get the initial game state for boardSize x boardSize Othello. Player names are "B" and "W".  All you need to know about the internals of this class is that it has a property board that represents the current board state as a two-dimensional list of blanks (" ") or player tokens ("B" or "W").  For example, othelloGameState.board[y][x] == "B" means that there is a Black piece at square (x,y).  

runGame(initialState, agents, display=True, displayStats=True):

Run a game from initialState with the given set of agents. 
  - initialState is a GameState
  - agents is a Dictionary of agents, which maps player names to agent functions
      (see game-agents.py and accompanying API)
  - display specifies whether the progress of the game should be printed or not.
  - displayStats specifies whether to print statistics about agent functions as the game proceeds
Returns a Dictionary of terminal utilities.

Example: to play 6x6 Othello against an agent that makes random moves, type

import games
import gameagents
import othello
games.runGame(othello.OthelloGameState(6),
              {"B" : gameagents.HumanGameAgent(),
               "W" : gameagents.RandomGameAgent()}, False, False)