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,27 +1,27 @@
internal final class Rook: Piece, LinearMoves {
internal weak var board: Board?
internal var kind: Kind = .Rook
final class Rook: Piece, LinearMoves {
weak var board: Board?
var kind: Kind = .Rook
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 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 }
@@ -35,7 +35,7 @@ internal final class Rook: Piece, LinearMoves {
return true
}
internal init(color: Color, on position: Square.Position) {
init(color: Color, on position: Square.Position) {
self.color = color
self.position = position
}