🤖 ChessKitEngine

ChessKitEngine Tests codecov

A Swift package for chess engines.

ChessKitEngine implements the Universal Chess Interface protocol for communication between chess engines and user interfaces built with Swift.

Usage

  • Add a package dependency to your Xcode project or Swift Package:
.package(url: "https://github.com/chesskit-app/chesskit-engine", from: "0.1.0")
  • Next you can import ChessKitEngine to use it in your Swift code:
import ChessKitEngine

// ...

Features

  • Initialize an engine and set response handler
let engine = Engine(type: .stockfish)

// set response handler
engine.receiveResponse = { response in
    print(response)
}

engine.start()
guard engine.isRunning else { return }

engine.send(command: .stop)
engine.send(command: .position(.startpos))
engine.send(command: .go(depth: 15))
  • Update engine position after a move is made
// FEN after 1. e4
let newPosition = "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1"

engine.send(command: .stop)
engine.send(command: .position(.fen(newPosition))
engine.send(command: .go(depth: 15))
  • Receive engine's analysis of current position
// receiveResponse is called whenever the engine publishes a response
engine.receiveResponse = { response in
    switch response {
    case let .info(info):
        print(info.score)   // engine evaluation score in centipawns
        print(info.pv)      // array of move strings representing best line
    default:
        break
}
  • Terminate engine communication
engine.stop()
  • Enable engine response logging
// Logging is off by default since engines can be very
// verbose while analyzing positions and returning evaluations.
engine.loggingEnabled = true

Supported Engines

The following engines are currently supported:

Author

@pdil

License

ChessKitEngine is distributed under the MIT License.

S
Description
♟️🤖 Swift package for UCI chess engines
Readme MIT 66 MiB
Languages
Swift 86.5%
Objective-C++ 5.2%
Objective-C 4.4%
C++ 3.1%
C 0.8%