28 lines
679 B
Swift
28 lines
679 B
Swift
final class Pawn: Piece {
|
|
override var pseudoLegalPositions: [Square.Position] {
|
|
let sign: Int8 = color == .Black ? -1 : 1
|
|
return [
|
|
position + (1 * sign, 0),
|
|
position + (2 * sign, 0),
|
|
position + (1 * sign, 1),
|
|
position + (1 * sign, -1),
|
|
].filter { $0.index != nil }
|
|
}
|
|
|
|
override var legalPositions: [Square.Position] {
|
|
pseudoLegalPositions.filter { isLegal(on: $0) }
|
|
}
|
|
|
|
override var unicodeRepresentation: String {
|
|
color == .Black ? "♟" : "♙"
|
|
}
|
|
|
|
override func isLegal(on pos: Square.Position) -> Bool {
|
|
super.isLegal(on: pos)
|
|
}
|
|
|
|
init(with color: Color, on position: Square.Position) {
|
|
super.init(kind: .Pawn, on: position, with: color)
|
|
}
|
|
}
|