Monte Carlo Tree Search for multiple teams
Project description
MultiMCTS
MultiMCTS is a Python package that implements the Monte Carlo Tree Search algorithm for board games played by any number of players. With MultiMCTS, you can create AI for any game merely by knowing the rules -- no strategy needed!
Features
- Efficient MCTS implementation
- Support for any number of players/teams
- Easily create AI for any board game
Game Implementation
For your game, you will need to:
- Represent the game state in code
- Identify all legal moves
- Determine if the game is over and who won
You do NOT need to:
- Understand strategy
- Have domain knowledge
- Evaluate the favorability of a game state
Installation
pip install multimcts
Usage
To use MultiMCTS, you must first define your game by subclassing GameState
and implementing the required methods (see examples):
get_current_team
-- Returns the current team.get_legal_moves
-- Returns a list of legal moves. Moves can be any data structure.make_move
-- Returns a copy of the current state after performing the given move (one from get_legal_moves).is_terminal
-- Returns whether the game is over.get_reward
-- Returns the reward given to the team that played the game-ending move.
Then you can use MCTS to search for the best move. It will search until some limit is reached.
state = mcts.search(MyGameState(), max_time=5, max_iterations=10000)
from multimcts import MCTS, GameState
class MyGameState(GameState):
# your implementation here...
pass
mcts = MCTS() # Create an MCTS agent.
state = MyGameState() # Set up a new game.
while not state.is_terminal(): # Continue until the game is over.
print(state) # Print the current game state (implementing GameState.__repr__ might be helpful).
state = mcts.search(state, max_time=1) # Play the best move found after 1 second.
print(state) # Print the final game state.
Development
- Clone the MultiMCTS repo.
git clone https://github.com/taylorvance/multimcts.git cd multimcts/
- Make changes to
multimcts/mcts.pyx
or other files. Then build a distribution.python setup.py sdist
- Install the updated package to use in your projects.
pip install dist/multimcts-0.1.0.tar.gz
Replacemultimcts-0.1.0
with the actual filename and version from thedist/
directory.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
multimcts-0.4.tar.gz
(158.1 kB
view hashes)
Built Distribution
Close
Hashes for multimcts-0.4-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 817ccbb1d1448352142018892d767fb0281872e16ad0ffb8ec0056bf93179d43 |
|
MD5 | dd4c7b60c9936be579e5b6ffda426ddf |
|
BLAKE2b-256 | 98f05431e68f40e28f03e4dbc2d699b41eb67bc78f08567117cf619ac5b82e25 |