49 lines
1.1 KiB
Swift
49 lines
1.1 KiB
Swift
final class Rook: Piece, LinearMoves {
|
|
|
|
override var unicodeRepresentation: String {
|
|
return color == .Black ? "♜" : "♖"
|
|
}
|
|
|
|
override var pseudoLegalPositions: [Square.Position] {
|
|
return getLinearMoves(from: position)
|
|
}
|
|
|
|
override func getLegalPosition() {
|
|
legalPositions = []
|
|
var last: Square.Position? = nil
|
|
for position in pseudoLegalPositions {
|
|
if !isLegal(on: position) {
|
|
last = position
|
|
continue
|
|
}
|
|
|
|
if !LinearDirection.isLegal(last: &last, current: position) {
|
|
last = nil
|
|
}
|
|
if last == nil {
|
|
legalPositions.append(position)
|
|
if let square = delegate?.getSquareInfo(on: position),
|
|
let piece = square.piece
|
|
{
|
|
if piece.color != color {
|
|
delegate?.notify(.piecePinned(from: self, on: piece))
|
|
last = position
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
override func isLegal(on pos: Square.Position) -> Bool {
|
|
super.isLegal(on: pos)
|
|
}
|
|
|
|
init(with color: Color, on position: Square.Position) {
|
|
super.init(kind: .Rook, on: position, with: color)
|
|
self.color = color
|
|
self.kind = .Rook
|
|
self.position = position
|
|
}
|
|
|
|
}
|