Files
swift-chess/Sources/Engine/Pieces/King.swift
2024-06-29 20:32:40 +02:00

34 lines
731 B
Swift

final class King: Piece {
typealias Threats = (Piece?, Piece?)
var threats: Threats = (nil, nil)
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)
}
}