Added two missing diagonals for sliding pieces
This commit is contained in:
parent
63b39dc761
commit
ef5c3bce84
|
@ -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 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 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 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))
|
func doublePush(piece: Piece): Location {.inline.} = (if piece.color == Black: (2, 0) else: (-2, 0))
|
||||||
proc testMoveOffsets(self: ChessBoard, move: Move): bool
|
proc testMoveOffsets(self: ChessBoard, move: Move): bool
|
||||||
|
@ -478,10 +480,8 @@ proc generateSlidingMoves(self: ChessBoard, location: Location): seq[Move] =
|
||||||
var
|
var
|
||||||
piece = self.grid[location.row, location.col]
|
piece = self.grid[location.row, location.col]
|
||||||
doAssert piece.kind in [Bishop, Rook, Queen], &"generateSlidingMoves called on a {piece.kind}"
|
doAssert piece.kind in [Bishop, Rook, Queen], &"generateSlidingMoves called on a {piece.kind}"
|
||||||
var directions: seq[Location] = @[piece.topRightDiagonal(), piece.topLeftDiagonal()]
|
var directions: seq[Location] = @[piece.topRightDiagonal(), piece.topLeftDiagonal(), piece.bottomLeftDiagonal(), piece.bottomRightDiagonal()]
|
||||||
echo piece, " ", location
|
|
||||||
for direction in directions:
|
for direction in directions:
|
||||||
echo "dir ", direction
|
|
||||||
# Slide in this direction as long as it's possible
|
# Slide in this direction as long as it's possible
|
||||||
var
|
var
|
||||||
square: Location = location
|
square: Location = location
|
||||||
|
@ -491,7 +491,6 @@ proc generateSlidingMoves(self: ChessBoard, location: Location): seq[Move] =
|
||||||
# End of board reached
|
# End of board reached
|
||||||
if not square.isValid():
|
if not square.isValid():
|
||||||
break
|
break
|
||||||
echo square
|
|
||||||
otherPiece = self.grid[square.row, square.col]
|
otherPiece = self.grid[square.row, square.col]
|
||||||
# A friendly piece is in the way
|
# A friendly piece is in the way
|
||||||
if otherPiece.color == piece.color:
|
if otherPiece.color == piece.color:
|
||||||
|
|
Loading…
Reference in New Issue