Skip to content

cappylot/ChessKit

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

293 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ChessKit

codebeat badge docs badge Tests ChessKit pod

Lightweight and fast chess framework written in Swift.

ChessKit is used as a base framework for Ladoga chess engine.

Installation

The ChessKit framework is avalable for installation via Swift Package Manager and CocoaPods.

Swift Package Manager

Add a dependency via Xcode, linking to https://github.com/aperechnev/ChessKit, or directly in your Package.swift file:

import PackageDescription

let package = Package(
    name: "MyPackage",
    platforms: [
        .macOS(.v10_12),
    ],
    dependencies: [
        .package(url: "https://github.com/aperechnev/ChessKit.git", from: "1.3.7"),
    ],
    targets: [
        .target(name: "MyPackage", dependencies: ["ChessKit"]),
    ]
)

To render a ready-to-use SwiftUI board with drag-and-drop support, depend on the ChessKitUI product:

.target(name: "MyPackage", dependencies: ["ChessKitUI"])

CocoaPods

To install ChessKit via CocoaPods, just add a dependencie to your Podfile:

target 'MyApp' do
  pod 'ChessKit'
end

Getting Started

ChessKit is well covered by documentation. But anyway here you can find an example describing how to start working with ChessKit faster.

import ChessKit

let italianGameFen = "r1bqk1nr/pppp1ppp/2n5/2b1p3/2B1P3/5N2/PPPP1PPP/RNBQK2R w KQkq - 4 4"
let italianGamePosition = FenSerialization.default.deserialize(fen: italianGameFen)
let game = Game(position: italianGamePosition)

print("Number of available moves: \(game.legalMoves.count)")

game.make(move: "b2b4")
let evansGambitFen = FenSerialization.default.serialize(position: game.position)
print("Evans gambit fen: \(evansGambitFen)")

game.make(move: Move(string: "c5b4"))
let evansGambitAcceptedFen = FenSerialization.default.serialize(position: game.position)
print("Evans gambit accepted fen: \(evansGambitAcceptedFen)")

print("List of moves in game: \(game.movesHistory)")
print("List of pieces on board: \(game.position.board.enumeratedPieces())")

SwiftUI board with legal move highlights

ChessKitUI ships a drop-in ChessBoardView that uses the same move generator under the hood. Highlights appear when selecting a piece; moves can be made by tapping or dragging a piece to its destination.

import SwiftUI
import ChessKitUI

struct ContentView: View {
    @StateObject private var board = ChessBoardViewModel()

    var body: some View {
        VStack(spacing: 12) {
            ChessBoardView(viewModel: board)
                .frame(width: 360, height: 360)
            Text(board.turn == .white ? "White to move" : "Black to move")
                .font(.headline)
        }
        .padding()
    }
}

Custom piece images

ChessBoardView loads piece assets by name from your app target. Add SVG (or PDF/PNG) assets titled wp, wn, wb, wr, wq, wk and their black counterparts bp, bn, bb, br, bq, bk to your asset catalog; the board will render those images automatically.

How To Contribute

Please follow the git-flow notation and make sure that all tests are passing before contributing. Your questions and pull requests are welcome.

Versioning

We are using semantic versioning.

License

ChessKit is released under the MIT license. See LICENSE for details.

About

Lightweight and fast chess framework written in Swift.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Swift 98.9%
  • Ruby 1.1%