Skip to main content

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 (largely C-compiled) MCTS implementation
  • Support for any number of players/teams
  • Easily create AI for any board game

Usage

For your game, you will need to:

  • Represent a 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

You can install with pip.

pip install multimcts

To use MultiMCTS, you must first define your game by subclassing GameState and implementing the required methods (see the Tic-Tac-Toe example):

  • 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 your defined limit is reached. The following shows how to simulate a game using MCTS:

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

  1. Clone the MultiMCTS repo.
    git clone https://github.com/taylorvance/multimcts.git
    cd multimcts/
    
  2. Make changes to multimcts/mcts.pyx or other files. Then build a distribution.
    python setup.py sdist
    
  3. Install the updated package to use in your projects.
    pip install dist/multimcts-0.1.0.tar.gz
    
    Replace multimcts-0.1.0 with the actual filename and version from the dist/ directory.

Project details


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.1.tar.gz (157.9 kB view details)

Uploaded Source

Built Distribution

multimcts-0.4.1-cp39-cp39-macosx_10_9_universal2.whl (128.0 kB view details)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)

File details

Details for the file multimcts-0.4.1.tar.gz.

File metadata

  • Download URL: multimcts-0.4.1.tar.gz
  • Upload date:
  • Size: 157.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for multimcts-0.4.1.tar.gz
Algorithm Hash digest
SHA256 2f29d36b34c5b8b7df52ad99ceee3ebb416d3e0cbababf07942c31cb0465bbbc
MD5 c6358df5a35adfcc2bef0be7b2c21415
BLAKE2b-256 a08289ff9103b2b11a6a13f852d7e3fec36502b7db764c278864515f15f4b981

See more details on using hashes here.

File details

Details for the file multimcts-0.4.1-cp39-cp39-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for multimcts-0.4.1-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 b7c0eab8515b47a5304c594fec7a4b1c5adb1e62690388f88b43e6b197f2f06c
MD5 b393a5b53f68c6493db7efbb39e6cfc4
BLAKE2b-256 6ec56f745871036f2001819763bc328a81b01d851958a8b7221ec1c5a740b6c2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page