Giter Site home page Giter Site logo

edwinveger / strategist Goto Github PK

View Code? Open in Web Editor NEW

This project forked from regexident/strategist

0.0 1.0 0.0 271 KB

Algorithms for building strong immutable AIs for round-based games.

License: Mozilla Public License 2.0

Swift 98.96% Ruby 1.04%

strategist's Introduction

Logo

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)

typealias Game = TicTacToeGame
typealias Player = TicTacToePlayer
typealias Policy = SimpleTreeSearchPolicy<Game>
typealias Strategy = MiniMaxTreeSearch<Game, Policy>

let 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)

typealias Game = ChessGame
typealias Heuristic = UpperConfidenceBoundHeuristic<Game>
typealias Policy = SimpleMonteCarloTreeSearchPolicy<Game, Heuristic>
typealias Strategy = MonteCarloTreeSearch<Game, Policy>

let 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.

Installation

Swift Package Manager

.Package(url: "https://github.com/regexident/Strategist.git")

Carthage (site)

github 'regexident/Strategist'

CocoaPods (site)

pod 'Strategist'

License

Strategist is available under the MPL-2.0 (tl;dr) license (see LICENSE file).

strategist's People

Contributors

regexident avatar

Watchers

James Cloos 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.