34 lines
731 B
Swift
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)
|
|
}
|
|
|
|
}
|