mctreesearch4j
mctreesearch4j: A Monte Carlo Tree Search Implementation for the JVM - Published in JOSS (2022)
Science Score: 46.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
✓Academic publication links
Links to: arxiv.org, zenodo.org -
✓Committers with academic emails
1 of 3 committers (33.3%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (12.8%) to scientific vocabulary
Scientific Fields
Repository
Basic Info
- Host: GitHub
- Owner: aqtech-ca
- License: mit
- Language: Kotlin
- Default Branch: main
- Size: 2.57 MB
Statistics
- Stars: 8
- Watchers: 3
- Forks: 1
- Open Issues: 8
- Releases: 2
Metadata Files
README.md
mctreesearch4j
An robust Implementation of the Monte Carlo Tree Search (MCTS) algorithm for the JVM.
Objective
Flexible implementations of Monte Carlo Tree Search (MCTS), combined with domain specific knowledge and hybridization with other search algorithms, can be a very powerful for the solution of problems in complex planning. We introduce mctreesearch4j, a standard MCTS implementation written as a standard JVM library following key design principles of object oriented programming. We define key class abstractions allowing the MCTS library to flexibly adapt to any well defined Markov Decision Process or turn-based adversarial game. Furthermore, our library is designed to be modular and extensible, utilizing class inheritance and generic typing to standardize custom algorithm definitions. We demonstrate that the design of the MCTS implementation provides ease of adaptation for unique heuristics and customization across varying Markov Decision Process (MDP) domains. In addition, the implementation is reasonably performant and accurate for standard MDP’s. In addition, via the implementation of mctreesearch4j, the nuances of different types of MCTS algorithms are discussed.
Structure
The library contains the implementation of the MCTS algorithm for single player and adversarial games. The project is compiled using gradle.
``` lib └── ... └── src.main.kotlin └── ca.aqtech.mctreesearch4j ├── MDP.kt ├── Node.kt ├── Solver.kt ├── StateNode.kt ├── StatefulSolver.kt ├── ActionNode.kt └── StatelessSolver.kt
```
The MCTS lib can be implemented by creating an interface implementing a Markov Decision Process (MDP) class, to communicate with the MCTS solver. The MCTS solver comes in two flavours StatefulSolver.kt and StatelessSolver.kt. The StatefulSolver.kt records both the action history and state, whereas the StatelessSolver.kt only records actions taken, and infers the state from actions taken.
Defining an MDP
MDP.kt defines the interface of the MDP. To run the MCTS solver, you must extend this MDP.kt class in any JVM language, and provide your specific definitions.
```kotlin
abstract class MDP
abstract fun reward(previousState: StateType?, action: ActionType?, state: StateType) : Double
/* Class method to return a reward (Double) given state transitions parameters */
abstract fun initialState() : StateType
/* Return the initial state of the MCTS (StateType) */
abstract fun isTerminal(state: StateType) : Boolean
/* Return boolean indicating if the state is terminal. */
abstract fun actions(state: StateType) : Iterable<ActionType>
/* Return an Iterable of legal actions given a current state. */
} ```
Examples
In the app/ folder of this repository, you may see various examples of game engines interfacing with the MDP controller.
Running Gradle examples via Gradle
It is possible to run the examples directly via Gradle. Simply select from the list of MDP / Games to run. Here is the list of arguments args:
ReversiGame: Initiates a game of Reversi between the user and AI, complete with user interface.ReversiAdversarialSim: Generates a simulation of competitive Reversi between 2 AI's.PushYourLuckSim: Initiates an MDP (Push Your Luck) and produces a policy for a single state.GridWorld: Initiates an MDP and produces a policy for a state in the game of GridWorld.Game2048: Initiates an MDP and produces a policy for a state in the game of the Game 2048.
To run the tasks via Gradle simply run,
bash
gradle run --args="{arg1} {arg2}"
Where arg1, arg2 for example are the strings representing the task to run, seperated by spaces. For example:
bash
gradle run --args="ReversiGame GridWorld"
Or simply to run one example,
bash
gradle run --args="ReversiGame"
Furthermore, there is an example of mctreesearch4j integrated with the game of Connect-4 in an example written in Scala.
Compiling the Core Library
To perform a local compilation of the core library located in the lib/ folder, the user must omit uploadArchives step defined in the gradle.build file, which signs the .jar artifcat via GPG key and uploads to Maven Central Repository. The GPG key is tied to the Maven release of this repository, and is not intended for local compilation. To compile a local .jar without signing it for release, simply run,
bash
gradle clean build -x uploadArchives
This will effectively exclude the upload to Maven step which is automated in this codebase, and allow the user to compile a local .jar for testing and experimentation. For a complete release to the Maven repository as a signed artifact, a PR to the main branch must be submitted, reviewed, and approved.
Maven Central
The JVM artifact is available directly via the Maven Central repository - mctreesearch4j. In principle, it has full compatibility with any JVM language.
Kotlin Integration (groovy)
groovy
dependencies {
implementation "ca.aqtech.mctreesearch4j:0.0.4"
}
Scala Integration (SBT)
sbt
libraryDependencies ++= Seq(
"ca.aqtech" % "mctreesearch4j" % "0.0.4"
)
Cite mctreesearch4j
Currently, to cite our framework, please cite our preprint:
@article{mctreesearch4j,
author = {Liu, Larkin and Luo, Jun Tao},
title = {An Extensible and Modular Design and Implementation of Monte Carlo Tree Search for the JVM},
journal = {arXiv},
year = {2021},
url = {https://arxiv.org/abs/2108.10061}
}
Owner
- Name: aqtech-ca
- Login: aqtech-ca
- Kind: organization
- Repositories: 2
- Profile: https://github.com/aqtech-ca
GitHub Events
Total
- Watch event: 2
Last Year
- Watch event: 2
Issues and Pull Requests
Last synced: 4 months ago
All Time
- Total issues: 19
- Total pull requests: 54
- Average time to close issues: about 1 month
- Average time to close pull requests: 6 days
- Total issue authors: 3
- Total pull request authors: 2
- Average comments per issue: 0.74
- Average comments per pull request: 0.52
- Merged pull requests: 47
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- larkz (17)
- TimKam (1)
- JunTaoLuo (1)
Pull Request Authors
- larkz (40)
- JunTaoLuo (14)
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- ca.aqtech.app:app-1.0-SNAPSHOT * implementation
- ca.aqtech:mctreesearch4j 0.0.4-dev implementation
- org.junit.jupiter:junit-jupiter-api 5.1.0 testImplementation
- org.junit.jupiter:junit-jupiter-engine 5.1.0 testRuntimeOnly
- org.jetbrains.kotlin:kotlin-stdlib-jdk8 * implementation