New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

blokus-engine

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blokus-engine

  • 0.2.0
  • PyPI
  • Socket score

Maintainers
1

Blokus Engine

blokus_ai

Project Outline

This repository contains several main sections. Most of the code is train a neural network using self-play and Monte Carlo Tree Search. During the process you have a neural network that acts as the brains of your players, and you have a game which is progressively getting played out. To simulate a game, all four players use the same network to determine which move they should take. They use MCTS to explore a tree of possible moves, and the game ultimately takes one path down this tree. Once the game is finished, the model can use all of this data it generated to train and improve itself. Then another game can be simulated using the better model to create more data. This is the basic cycle that allows the neural network to improve. To speed things up, you can have one neural network, and you can have multiple games going in parralel at the same time. This means you can batch requests from multiple games and you can generate more data at the same time. This project uses a client-server architecture where the neural network is hosted on a server, and the clients each query the server as they simulate a game. The server code uses Python and Pytorch, and that is all located in the model_server directory. Meanwhile each client uses Rust code in the self_play directory. This code is built on top of the blokus directory which contains all of the core game logic. Lastly, there is a GUI (that currently does not work yet) to play a game against the trained model.

Training Configuration

All of the configuration for training is done in the model/training.py config class. All of the values in this config are listed below, along with an example config file. The total number of games played during training is the number of clients times the number of games per client times the number of training rounds. For example if you have 10 clients, each generating 2 games worth of data per training round, and you train for 1 round, you will have 20 games worth of data. AlphaZero trained on 21 million games of Go.

VariableDescriptionAlphaZero Value
TRAINING_ROUNDSThe number of training rounds to run4,200
BUFFER_CAPACITYThe number of data points to store in the replay buffer1,000,000 games
LEARNING_RATEThe learning rate of the neural network.01 -> .0001 with scheduler
BATCH_SIZEThe number of data points per batch2,048
TRAINING_STEPSThe number of training steps to run each round700,000
NN_WIDTHThe number of filters in each convolutional layer256
NN_DEPTHThe number of residual blocks in the neural network20
NUM_CLIENTSThe number of clients to run5,000
GAMES_PER_CLIENTThe number of games each client generates per round1
SIMS_PER_MOVEThe number of simulations to run during MCTS to derive a policy800
SAMPLE_MOVESThe number of moves in a game that sample from the MCTS policy instead of picking the max to encourage exploration30
C_BASEConstant for UCB formula to balance exploration and exploitation19,652
C_INITConstant for UCB formula to balance exploration and exploitation1.25
DIRICHLET_ALPHAThe alpha parameter of the Dirichlet distribution which adds noise to the root node during MCTS to promote exploration0.03
EXPLORATION_FRACFraction used to mix noise and prior probability0.25

Usage:

GUI

To open the GUI in the browser run the model server and the proxy server then run: cd gui trunk serve --open

Training

To run a job on the HPC using 32 CPU cores, 240GB of memory, and an RTX2080 card, you can do:

sbatch -p mixed -N 1 -n 32 --mem=240G --gres=gpu:rtx2080:1 train.sh

References

  • https://sebastianbodenstein.com/post/alphazero/
  • https://arxiv.org/pdf/1712.01815.pdf
  • https://arc.net/folder/7FE3479D-1752-401F-9DC3-49AAD02B5DF3

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc