36 lines
803 B
Swift
36 lines
803 B
Swift
final class Bishop: Piece, DiagonalMoves {
|
|
|
|
override var unicodeRepresentation: String {
|
|
return color == .Black ? "♝" : "♗"
|
|
}
|
|
|
|
override var pseudoLegalPositions: [Square.Position] {
|
|
return getDiagonalMoves(from: position)
|
|
}
|
|
|
|
override var legalPositions: [Square.Position] {
|
|
return pseudoLegalPositions.filter { isLegal(on: $0) }
|
|
}
|
|
|
|
override func move(to dst: Square.Position) {
|
|
}
|
|
|
|
override func isLegal(on pos: Square.Position) -> Bool {
|
|
if let board = board, let s = board[pos] {
|
|
if let p = s.piece {
|
|
if p.color == color { return false }
|
|
if p.kind == .King {
|
|
delegate?.notify(.kingInCheck(self))
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
init(with color: Color, on position: Square.Position) {
|
|
super.init(kind: .Bishop, on: position, with: color)
|
|
}
|
|
|
|
}
|