Only loop through directions when a peg is present.

This commit is contained in:
Josh Holtrop 2021-02-28 15:12:40 -05:00
parent 7dc37d4ede
commit 7db1769723

View File

@ -53,11 +53,13 @@ class Solver
{
for (int col = 0; col <= row; col++)
{
if (board.peg_present(row, col))
{
Board.Position position = Board.Position(row, col);
for (Board.Direction direction = Board.Direction.FIRST;
direction < Board.Direction.COUNT;
direction++)
{
Board.Position position = Board.Position(row, col);
Board new_board = board.move(position, direction);
if (new_board !is null)
{
@ -70,6 +72,7 @@ class Solver
}
}
}
}
if (!found_valid_move)
{
end_game(board, moves);