Files
swift-chess/Sources/Engine/Pieces/King.swift
cdricms b04ecceb9f yes
2024-09-16 15:20:02 +02:00

47 lines
914 B
Swift

final class King: Piece {
typealias Threats = (Piece?, Piece?)
internal private(set) var threats: Threats = (nil, nil)
func insertThreat(_ piece: Piece) {
if threats.0 == nil {
threats.0 = piece
return
}
if threats.1 == nil {
threats.1 = piece
return
}
}
override var unicodeRepresentation: String {
return color == .Black ? "" : ""
}
override var pseudoLegalPositions: [Square.Position] {
[
position + (1, 0),
position + (1, 1),
position + (0, 1),
position + (-1, 1),
position + (-1, 0),
position + (-1, -1),
position + (0, -1),
position + (1, -1),
].filter { $0.index != nil }
}
override func isLegal(on pos: Square.Position) -> Bool {
guard super.isLegal(on: pos) else {
return false
}
// Do stuff
return true
}
init(with color: Color, on position: Square.Position) {
super.init(kind: .King, on: position, with: color)
}
}