Files
swift-chess/Sources/Engine/Pieces/King.swift
2024-06-26 22:46:58 +02:00

44 lines
914 B
Swift

internal final class King: Piece {
internal weak var board: Board?
internal var kind: Kind = .King
internal var unicodeRepresentation: String {
return color == .Black ? "" : ""
}
internal var color: Color
internal var position: Square.Position
internal var pseudoLegalPositions: [Square.Position] {
return []
}
internal var legalPositions: [Square.Position] {
return pseudoLegalPositions.filter { isLegal(on: $0) }
}
internal func move(to dst: Square.Position) -> Bool {
return false
}
internal 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
}
internal init(color: Color, on position: Square.Position) {
self.color = color
self.position = position
}
}