manager.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:robot-arena 作者: kenganong 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号