Files
swift-chess/Sources/Engine/Pieces/King.swift
2024-06-27 18:09:01 +02:00

44 lines
815 B
Swift

final class King: Piece {
weak var board: Board?
var kind: Kind = .King
var unicodeRepresentation: String {
return color == .Black ? "" : ""
}
var color: Color
var position: Square.Position
var pseudoLegalPositions: [Square.Position] {
return []
}
var legalPositions: [Square.Position] {
return pseudoLegalPositions.filter { isLegal(on: $0) }
}
func move(to dst: Square.Position) -> Bool {
return false
}
func isLegal(on pos: Square.Position) -> Bool {
if let board = board, let s = board[pos] {
if let p = s.piece {
if p.color == color { return false }
if p.kind == .King {
// TODO: Notify board of check
return false
}
}
}
return true
}
init(color: Color, on position: Square.Position) {
self.color = color
self.position = position
}
}