World Conquest Chronicles

World Conquest Chronicles

go-chess-minimax, v1.0

The library that implements a chess engine based on the minimax algorithm.

Major version.

Features

  • move searcher used the negamax algorithm;
  • searching termination:
    • by a deep;
    • by a time;
  • position evaluation only by a material (based on an evaluation function of Claude Shannon);
  • architecture features:
    • easily extensible and composable architecture of searching;
    • composable searching terminators.

Installation

$ go get github.com/thewizardplusplus/go-chess-minimax

Examples

chessminimax.NegamaxSearcher.SearchMove():

package main

import (
    "fmt"
    "log"

    minimax "github.com/thewizardplusplus/go-chess-minimax"
    "github.com/thewizardplusplus/go-chess-minimax/evaluators"
    "github.com/thewizardplusplus/go-chess-minimax/terminators"
    models "github.com/thewizardplusplus/go-chess-models"
    "github.com/thewizardplusplus/go-chess-models/pieces"
)

func main() {
    storage, err := models.ParseBoard("7K/8/7q/8/8/8/8/k7", pieces.NewPiece)
    if err != nil {
        log.Fatal(err)
    }

    var generator models.MoveGenerator
    var evaluator evaluators.MaterialEvaluator
    terminator := terminators.NewDeepTerminator(1)
    searcher := minimax.NewNegamaxSearcher(generator, terminator, evaluator)

    scoredMove, err := searcher.SearchMove(storage, models.White, 0)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("%+v\n", scoredMove)

    // Output: {Move:{Start:{File:7 Rank:7} Finish:{File:6 Rank:7}} Score:-9}
}

Benchmarks

chessminimax.NegamaxSearcher:

BenchmarkNegamaxSearcher_1Ply-8         1000       1992585 ns/op
BenchmarkNegamaxSearcher_2Ply-8           50      23746812 ns/op
BenchmarkNegamaxSearcher_3Ply-8            3     353803361 ns/op

Repository

Link: https://github.com/thewizardplusplus/go-chess-minimax/tree/v1.0.

Content: code.

License: MIT.