GithubHelp home page GithubHelp logo

nim-mcts's Introduction

nim-MCTS

Monte Carlo tree search with Upper Confidence bounds for Trees (UCT) for Nim

UCT searches for good moves, in a random way. Every iteration has three stages:

  1. Walk down the tree of tried moves, in upper confidence (UCT) order, until an untried move is found.

  2. When an untried move is found, play the game by randomly playing moves.

  3. When the game is finished, walk back up the tree, updating the upper confidence (UCT).

This algorithm will explore untried moves first, then moves that look promising for whichever player is choosing the move.

UCT is evaluated as wins/visits + UCTK*sqrt(2*log(visits)/visits)

UCTK is some constant, which will tune exploration vs exploitation. A higher constant will tend to favor more exploration (approaching infinity, it will pick the least visited node), while a zero value will simply pick the current best node.

I also added an option to run a heuristic search. TODO - read the literature, and find a good way to do this.

Using a very simple heuristic, I get a player using 5 search iterations to beat one using 1000 iterations in Othello. Which is a pretty good speedup.

Another speedup would be Zobrist hashing. This basically hashes seen nodes (since many games have multiple paths to the same state). Zobrist hashing using XORing of positions, so the entire hash need not be recalculated every move (when you move a piece, you XOR it out of its current position, then XOR it into the next position).

To run Othello:

nimrod compile --run -d:release --p:../ Othello.nim

nim-mcts's People

Contributors

peter-the-tea-drinker avatar

Stargazers

Nahuel Piguillem avatar Brad Pillow 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.