class GameState
: Encapsulates all relevant information about a
game state, and provides methods for move and successor generation and
terminal testing.
XXXGameState()
getPlayers()
currentPlayer()
actions()
successor(action)
successors()
shuffledSuccessors()
utility()
currentPlayerUtility()
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()
nim.NimGameState(board = [7,7,7])
othello.OthelloGameState(boardSize = 8)
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)