mirror of
https://github.com/MSWS/Chess.git
synced 2025-12-05 21:30:23 -08:00
feat: Adjust board traversal logic for active player direction
- Update board traversal logic to handle direction based on active player Introduce `startRow` and `rowDir` for flexible iteration, adjusting row iteration logic to vary starting points and directions based on whether the active player is Black. [board/move.go] - Added logic to handle board traversal direction based on the active player, introducing `startRow` and `rowDir` for flexible iteration. - Adjusted the row iteration logic to account for varying starting points and directions, depending on whether the active player is Black. - No changes were made to the underlying move generation or legality checks.
This commit is contained in:
@@ -249,7 +249,14 @@ func (game Game) GetMoves() []Move {
|
||||
|
||||
board := game.Board
|
||||
pieces := 0
|
||||
for row := 0; row < len(board) && pieces < 16; row++ {
|
||||
startRow := 0
|
||||
rowDir := 1
|
||||
if game.Active == Black {
|
||||
startRow = 7
|
||||
rowDir = -1
|
||||
}
|
||||
|
||||
for row := startRow; row < len(board) && row >= 0 && pieces < 16; row += rowDir {
|
||||
for col := 0; col < len(board[row]) && pieces < 16; col++ {
|
||||
piece := board[row][col]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user