32 lines
714 B
Swift
32 lines
714 B
Swift
final class Knight: Piece {
|
|
override var unicodeRepresentation: String {
|
|
return color == .Black ? "♞" : "♘"
|
|
}
|
|
|
|
override var pseudoLegalPositions: [Square.Position] {
|
|
[
|
|
position + (2, 1),
|
|
position + (2, -1),
|
|
position + (-2, 1),
|
|
position + (-2, -1),
|
|
position + (1, 2),
|
|
position + (1, -2),
|
|
position + (-1, 2),
|
|
position + (-1, -2),
|
|
].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: .Knight, on: position, with: color)
|
|
}
|
|
|
|
}
|