Sliding pieces moves are now illegal if it's after the enemy

This commit is contained in:
cdricms
2024-07-01 16:14:49 +02:00
parent d3503f1441
commit cf42721235
4 changed files with 24 additions and 1 deletions

View File

@@ -22,6 +22,14 @@ final class Bishop: Piece, DiagonalMoves {
} }
if last == nil { if last == nil {
legalPositions.append(position) 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
}
}
} }
} }
} }

View File

@@ -54,7 +54,6 @@ public enum Kind: String, CaseIterable {
} }
public class Piece: Hashable { public class Piece: Hashable {
#warning("TODO: To be removed, handle everything through the delegate")
public internal(set) var color: Color public internal(set) var color: Color
public internal(set) var halfMoveCount: UInt8 = 0 public internal(set) var halfMoveCount: UInt8 = 0
public var unicodeRepresentation: String { public var unicodeRepresentation: String {

View File

@@ -24,6 +24,14 @@ final class Queen: Piece, LinearMoves, DiagonalMoves {
if last == nil { if last == nil {
legalPositions.append(position) 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
}
}
} }
} }
} }

View File

@@ -22,6 +22,14 @@ final class Rook: Piece, LinearMoves {
} }
if last == nil { if last == nil {
legalPositions.append(position) 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
}
}
} }
} }
} }