ahorn package¶
Submodules¶
ahorn.Controller module¶
-
class
ahorn.Controller.
Controller
(initial_state, verbose=False)¶ Bases:
object
A controller is used to play a game
The controller servers as the main interface to playing games.
- players: List
- List of Player objects
- inititial_state: State
- State object from which to start the game
-
play
()¶ Plays the game untill a final state is reached
- final_state: State
- The final state
ahorn.Arena module¶
Compare the strength of different Players
-
class
ahorn.Arena.
Arena
(Game, players, n_games=50, confidence=0.9, verbose=False, verbose_seconds=5)¶ Bases:
object
In the arena you can test the strength of your Player on a given game
- Example:
> player_a, player_b = MCTSPlayer(), MCTSPlayer()
- > arena = Arena(
- game=ahorn.TicTacToe.TicTacToeState, players=[player_a, player_b], n_games=20, verbose=True
)
> arena.play()
- Game: State class
- The class of the game you want to play
- players: List<Player>
- The players you want to evaluate
- confidence: float
- The width of the confidence interval, default 90%
- verbose: bool
- Print some debug information
- verbose_seconds: float
- How many seconds between two prints, default 5
- utilities: dict<player, float>
- The average utility for each player.
-
static
bootstrap
(series, func=<function mean>, confidence=0.9)¶ Return the bootstrap confidence interval of a series.
- series: List<float>
- your data
- func: function
- function that digests your data, default mean
- confidence: float
- width of the confidence interval, default 0.9
- low: float
- lower bound of confidence interval
- mid: float
- median value of confidence interval
- high: float
- high bound of confidence interval
-
play
()¶ Evaluate the strength of a player on a game.
If verbose=True, will print intermediate results.
- result: dict<player, utility>
- the average utility of each player
Module contents¶
Ahorn¶
A game description framework and game playing AI library, written entirely in Python.
Quickstart¶
import ahorn, ahorn.Actors, ahorn.TicTacToe player_a, player_b = ahorn.Actors.MCTSPlayer(), ahorn.Actors.MCTSPlayer() starting_state = ahorn.TicTacToe.TicTacToeState([player_a, player_b]) controller = ahorn.Controller(starting_state, verbose=True) controller.play()
Installation¶
pip3 install -r requirements.txt python3 setup.py install python3 run.py # should start playing a game
Running the tests¶
python3 -m pytest tests
Adding a new game¶
A game is described by states and actions. To describe a new game, subclass ahorn.GameBase.State and ahorn.GameBase.Action. Take a look at the example: ahorn.TicTacToe.
Adding new AI¶
- Ahorn comes with a generic AI based on the Monte Carlo Tree Search algorithm:
- ahorn.Actors.MCTSPlayer.
To create a new AI, subclass ahorn.GameBase.Player. Take a look at the example: ahorn.Actors.RandomPlayer.