Sliding pieces moves are now illegal if after piece of same color

This commit is contained in:
cdricms
2024-06-30 21:06:03 +02:00
parent 02de114d74
commit d3503f1441
8 changed files with 225 additions and 54 deletions

View File

@@ -8,6 +8,24 @@ final class Bishop: Piece, DiagonalMoves {
return getDiagonalMoves(from: position)
}
override func getLegalPosition() {
legalPositions = []
var last: Square.Position? = nil
for position in pseudoLegalPositions {
if !isLegal(on: position) {
last = position
continue
}
if !DiagonalDirection.isLegal(last: &last, current: position) {
last = nil
}
if last == nil {
legalPositions.append(position)
}
}
}
override func isLegal(on pos: Square.Position) -> Bool {
super.isLegal(on: pos)
}