Git Product home page Git Product logo

multimcts's Introduction

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.

multimcts's People

Contributors

taylorvance avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.