ahorn.TicTacToe package¶
Submodules¶
ahorn.TicTacToe.Actions module¶
-
class
ahorn.TicTacToe.Actions.
TicTacToeAction
(symbol, where)¶ Bases:
ahorn.GameBase.Action.Action
In Tac-Tac-Toe the only action is puttin an O or an X in a free space
- symbol: str
- Either “X” or “O”
- where: (int, int)
- A tuple with row and column index
-
execute
(state)¶ Execute the action.
Modifies the board of the state, and the current player index.
- state: TTTState
- The state which to modify
ahorn.TicTacToe.States module¶
-
class
ahorn.TicTacToe.States.
TicTacToeState
(players)¶ Bases:
ahorn.GameBase.State.State
Describes a Tic-Tac-Toe state
- players: List
- A list containing 2 Player objects
-
copy
(other)¶ Copy the content of another state into this state
Deep copy, i.e. modifying the copied state can not influence the content of the original state.
- other : State
- The state from which to copy the content
-
get_actor
()¶ Return the actor that must perform an action in this state.
Cycles between the first player and the second player
- Actor
- The player that must perform an action in this state.
-
get_legal_actions
(player)¶ Return the legal actions a player can take in this state.
- player: Player
- the player who wants to know which actions he can take
- actions: List
- a list of Actions
-
get_players
()¶ Return a list of all the players in the game.
- List<Player>
- A list of all the players in the game.
-
get_random
(player)¶ Tic-Tac-Toe is of complete information. Return a copy of this state.
- player: Player
- Not used
- State
- A copy of this state
-
get_utility
(player)¶ Return +1 if player won, -1 if player lost, 0 if draw.
If the state is final, returns the utility, else returns None
- player: Player
- The player for which to find the utility
- utility: int
- The utility received by the player, or None
-
is_final
()¶ Return true if there is an OOO or XXX on the board, or the board is full.
- bool
- True if the state is an OXO on the board, false otherwise
-
str
(player)¶ Returns a string containing the board, and the current player
- str
- String representation of this state.
Module contents¶
Tic-Tac-Toe is the simpelest of games.
The game is deterministic: there are no dice or random cards present. The game is of complete information: every players knows the board.
This module serves as an example on how to implement simple games.