Like pointed out, let me explain a bit of the code. I have 2 for loops because i have a board of a game called Tablut. I have to check from the pawn position (row_index and column_index) if there is an obstacle on the left and on the right. So, the first loop take the row_index of the pawn, then check for every row on the right side and stop when it finds an obstacle. Then do the same for the left side. If i use a single loop i don't have a way to stop searching in one direction if found an obstacle and start looking in the other, because the break will stop the entire for. The loop are used to generate all the possible actions that a move can do inside the board in that turn. Action(Position(....)) is one action that the pawn can make.
So, basically, i check in the right and left direction, if the next tile is empty i can move there, so i create a new action and add it to a list of all the possible moves, if there is an obstacle, since i can't jump it, i stop the loop.
i have this for loop and i would like to optimize it for speed.
for row in range(row_index - 1, -1, -1):
if bitboard_util.get_bit(obstacle_bitboard, row, column_index) != 1:
action = Action(Position(row_index, column_index), Position(row, column_index), color)
all_available_moves_for_pawn.append(action)
else:
break
for row in range(row_index + 1, 9):
if bitboard_util.get_bit(obstacle_bitboard, row, column_index) != 1:
action = Action(Position(row_index, column_index), Position(row, column_index), color)
all_available_moves_for_pawn.append(action)
else:
break