目录
目录README.md

♟️ ChessKit

Test ChessKit codecov

A Swift package for implementing chess logic.

Usage

  • Add a package dependency to your Xcode project or Swift Package:

    .package(url: "https://github.com/chesskit-app/chesskit-swift", from: 
    "0.2.0")
  • Next you can import ChessKit to use it in your Swift code: ``` swift import ChessKit

// …


## Features

* Representation of chess elements
    * `Piece`
    * `Square`
    * `Move`
    * `Position`
    * `Board`
    * `Game`
    * Special moves (castling, en passant)
* Move validation
* Chess notation string parsing
    * PGN
    * FEN
    * SAN
    
## Examples

* Create a board with the standard starting position:
``` swift
let board = Board()
  • Create a board with a custom starting position using FEN:

    if let position = Position(fen: "rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2") {
      let board = Board(position: position)
    }
  • Move pieces on the board

    let board = Board()
    board.move(pieceAt: .e2, to: .e4)           // move pawn at e2 to e4
  • Check move legality

    let board = Board()
    print(board.canMove(pieceAt: .a1, to: .a8)) // returns false
  • Check legal moves

    let board = Board()
    print(board.legalMoves(forPieceAt: .e2))    // returns [.e3, .e4]
  • Parse FEN into a Position object ``` swift let fen = “rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2”

// use parser directly… let position = FENParser.parse(fen: fen)

// … or use Position initializer let position = Position(fen: fen)

// convert Position to FEN string let fenString = FENParser.convert(position: .standard)


* Similarly parse PGN (into `Game`) or SAN (into `Move`).
``` swift
PGNParser.parse(pgn: "1. e4 e5 2. Nf3")

// Parse the move text "e4" for white from the starting position
SANParser.parse(san: "e4", color: .white, in: .standard)

Author

@pdil

License

ChessKit is distributed under the MIT License.

关于
118.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号