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

@@ -7,6 +7,27 @@ final class Queen: Piece, LinearMoves, DiagonalMoves {
return getDiagonalMoves(from: position) + getLinearMoves(from: position)
}
override func getLegalPosition() {
legalPositions = []
var last: Square.Position? = nil
for position in pseudoLegalPositions {
if !isLegal(on: position) {
last = position
continue
}
if !LinearDirection.isLegal(last: &last, current: position)
&& !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)
}