Linear + Diagonal moves

This commit is contained in:
cdricms
2024-06-27 18:09:01 +02:00
parent bc145da022
commit 8b5c2a592e
11 changed files with 179 additions and 108 deletions

View File

@@ -1,28 +1,28 @@
internal final class Queen: Piece, LinearMoves, DiagonalMoves {
internal weak var board: Board?
internal var kind: Kind = .Queen
final class Queen: Piece, LinearMoves, DiagonalMoves {
weak var board: Board?
var kind: Kind = .Queen
internal var unicodeRepresentation: String {
var unicodeRepresentation: String {
return color == .Black ? "" : ""
}
internal var color: Color
var color: Color
internal var position: Square.Position
var position: Square.Position
internal var pseudoLegalPositions: [Square.Position] {
var pseudoLegalPositions: [Square.Position] {
return getDiagonalMoves(from: position) + getLinearMoves(from: position)
}
internal var legalPositions: [Square.Position] {
var legalPositions: [Square.Position] {
return pseudoLegalPositions.filter { isLegal(on: $0) }
}
internal func move(to dst: Square.Position) -> Bool {
func move(to dst: Square.Position) -> Bool {
return false
}
internal func isLegal(on pos: Square.Position) -> Bool {
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 }
@@ -36,7 +36,7 @@ internal final class Queen: Piece, LinearMoves, DiagonalMoves {
return true
}
internal init(color: Color, on position: Square.Position) {
init(color: Color, on position: Square.Position) {
self.color = color
self.position = position
}