Files
swift-chess/Sources/Engine/Pieces/King.swift
2024-06-28 19:35:43 +02:00

33 lines
709 B
Swift

final class King: Piece {
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 var legalPositions: [Square.Position] {
return pseudoLegalPositions.filter { isLegal(on: $0) }
}
override func isLegal(on pos: Square.Position) -> Bool {
super.isLegal(on: pos)
}
init(with color: Color, on position: Square.Position) {
super.init(kind: .King, on: position, with: color)
}
}