Swift Package Index


Chess represented in swift


  • The latest stable release is 1.0.8. Released 14 days ago.
  • The last commit to main was 14 days ago.

Swift Version Compatibility

  • 1.0.8 and main
    5.3
    5.2
    5.1
    5.0
    4.2
Full build results

Platform Compatibility

  • 1.0.8 and main
    iOS
    macOS(Intel)
    macOS(ARM)
    Linux
    tvOS
    watchOS
Full build results

Chess

This package provides UI components and game logic for standard chess play. The code presents a unified pattern for the game interactions using Combine and SwiftUI.

You can find an example Xcode project in the "PlayChess" folder.

This app is also available in the App Store if you'd like to try it.

Getting Started

The main starting place for using swift-chess is the ChessStore

It houses a chess game, its board, and players. It provides the game and environment interface via a reducer pattern.

Here's an example of creating a ChessStore that would allow two people to play.

let white = Chess.HumanPlayer(side: .white)
let black = Chess.HumanPlayer(side: . black)
let game = Chess.Game(white, against: black)
let store = ChessStore(game: game)

You might then use the store as the environment variable for a BoardView.

Going Further

There is a lot to discover, you will find previews in the code, this can be helpful to get a visual guide.

Here's XCode showing the preview of SquareTargeted.swift.

When a user taps a square we show the possible moves on the board.

Contact

Find a bug? Need help w/ the docs?

Please use the issues here, or open a pull request.

If you have a question about the App Store version, you can find more info at chess.toys