def perform_priority_moves(state, interactive):
to_move = [pos for cell, pos in state.board.traverse() if cell.content and cell.content[TYPE] == ROBOT
and cell.content['move'] in PRIORITY_MOVES]
random.shuffle(to_move)
while len(to_move) > 0:
pos = to_move.pop()
robot = state.board.get_item(pos).content
if robot['move'] == FORWARD_TWO:
direction = robot[FACING]
elif robot['move'] == SIDESTEP_LEFT:
direction = turn_direction(robot[FACING], False)
elif robot['move'] == SIDESTEP_RIGHT:
direction = turn_direction(robot[FACING], True)
pos = perform_move_in_direction(state, pos, direction, to_move, interactive)
if pos != None and robot['move'] == FORWARD_TWO:
pos = perform_move_in_direction(state, pos, direction, to_move, interactive)
if pos != None:
if robot[CHARGES] > 0:
robot[CHARGES] -= 1
else:
robot[LIFE] -= 1
if robot[LIFE] == 0:
record_death(robot, 'malfunction', interactive)
评论列表
文章目录