45 lines
1010 B
Swift
45 lines
1010 B
Swift
internal final class Queen: Piece, LinearMoves, DiagonalMoves {
|
|
internal weak var board: Board?
|
|
internal var kind: Kind = .Queen
|
|
|
|
internal var unicodeRepresentation: String {
|
|
return color == .Black ? "♛" : "♕"
|
|
}
|
|
internal var color: Color
|
|
|
|
internal var position: Square.Position
|
|
|
|
internal var pseudoLegalPositions: [Square.Position] {
|
|
return getDiagonalMoves(from: position) + getLinearMoves(from: position)
|
|
}
|
|
|
|
internal var legalPositions: [Square.Position] {
|
|
return pseudoLegalPositions.filter { isLegal(on: $0) }
|
|
}
|
|
|
|
internal func move(to dst: Square.Position) -> Bool {
|
|
|
|
return false
|
|
}
|
|
|
|
internal 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 {
|
|
// TODO: Notify board of check
|
|
return false
|
|
}
|
|
}
|
|
|
|
}
|
|
return true
|
|
}
|
|
|
|
internal init(color: Color, on position: Square.Position) {
|
|
self.color = color
|
|
self.position = position
|
|
}
|
|
|
|
}
|