Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/regexident/strategist
Algorithms for building strong immutable AIs for round-based games.
https://github.com/regexident/strategist
minimax monte-carlo-tree-search strategy-game-engine swift
Last synced: about 2 months ago
JSON representation
Algorithms for building strong immutable AIs for round-based games.
- Host: GitHub
- URL: https://github.com/regexident/strategist
- Owner: regexident
- License: mpl-2.0
- Created: 2016-06-12T21:16:42.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-04-07T21:35:50.000Z (over 4 years ago)
- Last Synced: 2024-10-19T18:26:58.932Z (3 months ago)
- Topics: minimax, monte-carlo-tree-search, strategy-game-engine, swift
- Language: Swift
- Size: 287 KB
- Stars: 39
- Watchers: 4
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![Logo](Jumbotron.png)
# Strategist
**Strategist** provides algorithms for building strong immutable AIs for round-based games.
## Provided Algorithms:
- **Minimax** Tree Search (with alpha-beta pruning)
- **Negamax** Tree Search (with alpha-beta pruning)
- **Monte Carlo** Tree Search## Example usage
#### Tic Tac Toe (Minimax Tree Search)
```swift
typealias Game = TicTacToeGame
typealias Player = TicTacToePlayer
typealias Policy = SimpleTreeSearchPolicy
typealias Strategy = MiniMaxTreeSearchlet players: [Player] = [.X, .O] // => [Human, Ai]
var game = Game(players: players)
let policy = Policy(maxMoves: 10, maxExplorationDepth: 10)
let strategy = Strategy(policy: policy)
while !game.evaluate().isFinal {
let move: TicTacToeMove
if game.currentPlayer == .White {
move = askAndWaitForHumanPlayersMove(game.currentPlayer)
} else {
move = strategy.randomMaximizingMove(game)!
}
game = game.update(move) // moves turn and game state forward
}
print("Game ended with \(game.currentPlayer)'s \(game.evaluate()).")
```#### Chess (Monte Carlo Tree Search)
```swift
typealias Game = ChessGame
typealias Heuristic = UpperConfidenceBoundHeuristic
typealias Policy = SimpleMonteCarloTreeSearchPolicy
typealias Strategy = MonteCarloTreeSearchlet players: [Player] = [.White, .Black] // => [Human, Ai]
var game = Game(players: players)
let heuristic = Heuristic(c: sqrt(2.0))
let policy = Policy(
maxMoves: 100,
maxExplorationDepth: 10,
maxSimulationDepth: 10,
simulations: 100,
pruningThreshold: 1000,
scoringHeuristic: heuristic
)
var strategy = Strategy(
game: game,
player: players[0],
policy: policy
)
while !game.evaluate().isFinal {
let move: ChessMove
if game.currentPlayer == .White {
move = askAndWaitForHumanPlayersMove(game.currentPlayer)
} else {
while stillPlentyOfTime() {
strategy = strategy.refine()
}
move = strategy.randomMaximizingMove(game)!
}
strategy = strategy.update(move)
game = game.update(move)
}
print("Game ended with \(game.currentPlayer)'s \(game.evaluate()).")
```## Documentation
Online API documentation can be found here [here](https://regexident.github.io/Strategist/).
## Installation
### Swift Package Manager
.Package(url: "https://github.com/regexident/Strategist.git")
### Carthage ([site](https://github.com/Carthage/Carthage))
github 'regexident/Strategist'
### CocoaPods ([site](http://cocoapods.org/))
pod 'Strategist'
## License**Strategist** is available under the [**MPL-2.0**](https://www.mozilla.org/en-US/MPL/2.0/) ([tl;dr](https://tldrlegal.com/license/mozilla-public-license-2.0-(mpl-2))) license (see `LICENSE` file).