SwiftShogi is a pure Swift shogi library with game management, bitboard-based board representation, and move generation/validation.
- Game management
- Board representation
- Move generation/validation
- SFEN parsing
- KIF parsing
- Pretty printing
To understand how to develop apps using SwiftShogi, you can refer to the following app.
- SwiftUIShogi - An example shogi app using SwiftUI
Initialize a game with SFEN:
var game = Game(sfen: .default)
To get all valid moves, use the validMoves()
method, and to get valid moves for a specified piece, use the validMoves(from:piece:)
method:
let moves = game.validMoves()
let pieceMoves = game.validMoves(
from: .board(.twoG),
piece: Piece(kind: .pawn(.normal), color: .black)
)
You can perform a move by calling the game's perform(_:)
method:
let move = Move(
source: .board(.twoG),
destination: .board(.twoF),
piece: Piece(kind: .pawn(.normal), color: .black)
)
try game.perform(move)
Add the SwiftShogi package to your target dependencies in Package.swift
:
import PackageDescription
let package = Package(
name: "YourProject",
dependencies: [
.package(
url: "https://github.com/hedjirog/SwiftShogi",
from: "0.1.0"
),
]
)
Then run the swift build
command to build your project.
MIT
Jiro Nagashima (@hedjirog)