Added two missing diagonals for sliding pieces

This commit is contained in:
Mattia Giambirtone 2023-10-16 22:39:54 +02:00
parent 1610e7b4a6
commit eb77cf4b89
1 changed files with 3 additions and 4 deletions

View File

@ -108,6 +108,8 @@ proc generateMoves(self: ChessBoard, location: Location): seq[Move]
func topLeftDiagonal(piece: Piece): Location {.inline.} = (if piece.color == White: (-1, -1) else: (1, 1))
func topRightDiagonal(piece: Piece): Location {.inline.} = (if piece.color == White: (-1, 1) else: (1, -1))
func bottomLeftDiagonal(piece: Piece): Location {.inline.} = (if piece.color == White: (-1, -1) else: (1, 1))
func bottomRightDiagonal(piece: Piece): Location {.inline.} = (if piece.color == White: (1, 1) else: (-1, -1))
func forward(piece: Piece): Location {.inline.} = (if piece.color == Black: (1, 0) else: (-1, 0))
func doublePush(piece: Piece): Location {.inline.} = (if piece.color == Black: (2, 0) else: (-2, 0))
proc testMoveOffsets(self: ChessBoard, move: Move): bool
@ -478,10 +480,8 @@ proc generateSlidingMoves(self: ChessBoard, location: Location): seq[Move] =
var
piece = self.grid[location.row, location.col]
doAssert piece.kind in [Bishop, Rook, Queen], &"generateSlidingMoves called on a {piece.kind}"
var directions: seq[Location] = @[piece.topRightDiagonal(), piece.topLeftDiagonal()]
echo piece, " ", location
var directions: seq[Location] = @[piece.topRightDiagonal(), piece.topLeftDiagonal(), piece.bottomLeftDiagonal(), piece.bottomRightDiagonal()]
for direction in directions:
echo "dir ", direction
# Slide in this direction as long as it's possible
var
square: Location = location
@ -491,7 +491,6 @@ proc generateSlidingMoves(self: ChessBoard, location: Location): seq[Move] =
# End of board reached
if not square.isValid():
break
echo square
otherPiece = self.grid[square.row, square.col]
# A friendly piece is in the way
if otherPiece.color == piece.color: