def perform_moves(state, interactive):
to_move = [cell.content for cell, pos in state.board.traverse() if cell.content and cell.content[TYPE] == ROBOT
and cell.content['move'] in [TURN_LEFT, TURN_RIGHT, U_TURN]]
for robot in to_move:
perform_turn(robot, robot['move'])
to_move = [pos for cell, pos in state.board.traverse() if cell.content and cell.content[TYPE] == ROBOT
and cell.content['move'] in [FORWARD, REVERSE]]
random.shuffle(to_move)
while len(to_move) > 0:
pos = to_move.pop()
robot = state.board.get_item(pos).content
if robot['move'] == FORWARD:
direction = robot[FACING]
elif robot['move'] == REVERSE:
direction = opposite_direction(robot[FACING])
perform_move_in_direction(state, pos, direction, to_move, interactive)
评论列表
文章目录