コード例 #1
0
    def test_is_finished(self):
        """Checks if MoveAction correctly detects that it's finished."""
        action = MoveAction(5)
        self.robot.odometry.pose.pose.position.x = 5
        self.robot.odometry.pose.pose.position.y = 5

        self.assertTrue(action.is_finished(self.robot))
コード例 #2
0
    def test_is_not_finished(self):
        """Checks if MoveAction correctly detects that it's not finished."""
        action = MoveAction(5)
        self.robot.odometry.pose.pose.position.x = 3
        self.robot.odometry.pose.pose.position.y = 2

        self.assertFalse(action.is_finished(self.robot))
コード例 #3
0
    def test_is_not_finished(self):
        """Checks if MoveAction correctly detects that it's not finished."""
        action = MoveAction(5)
        self.robot.odometry.pose.pose.position.x = 3
        self.robot.odometry.pose.pose.position.y = 2

        self.assertFalse(action.is_finished(self.robot))
コード例 #4
0
    def test_start(self):
        """Checks if starting positions are set from robot."""
        action = MoveAction(5)
        action.start(self.robot)

        self.assertEqual(action.x_start, 1)
        self.assertEqual(action.y_start, 1)
コード例 #5
0
    def test_start(self):
        """Checks if starting positions are set from robot."""
        action = MoveAction(5)
        action.start(self.robot)

        self.assertEqual(action.x_start, 1)
        self.assertEqual(action.y_start, 1)
コード例 #6
0
    def test_is_finished(self):
        """Checks if MoveAction correctly detects that it's finished."""
        action = MoveAction(5)
        self.robot.odometry.pose.pose.position.x = 5
        self.robot.odometry.pose.pose.position.y = 5

        self.assertTrue(action.is_finished(self.robot))
コード例 #7
0
 def ev_controllerbuttondown(
         self, event: ControllerButtonDown) -> Optional[Action]:
     i = event.which
     controller = self.controllers[i]
     print("Button {} down on controller {} {}".format(
         event.button, i, controller))
     action: Optional[Action] = None
     if event.button == sdl2.SDL_CONTROLLER_BUTTON_DPAD_UP:
         action = MoveAction(0, -1)
     elif event.button == sdl2.SDL_CONTROLLER_BUTTON_DPAD_DOWN:
         action = MoveAction(0, 1)
     elif event.button == sdl2.SDL_CONTROLLER_BUTTON_DPAD_LEFT:
         action = MoveAction(-1, 0)
     elif event.button == sdl2.SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
         action = MoveAction(1, 0)
     self.dpad_state[event.button] = ButtonState(True, True)
     print(self.dpad_state)
     return action
コード例 #8
0
 def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
     action: Optional[Action] = None
     key = event.sym
     if key == tcod.event.K_UP or key == tcod.event.K_k:
         action = MoveAction(0, -1)
     elif key == tcod.event.K_DOWN or key == tcod.event.K_j:
         action = MoveAction(0, 1)
     elif key == tcod.event.K_LEFT or key == tcod.event.K_h:
         action = MoveAction(-1, 0)
     elif key == tcod.event.K_RIGHT or key == tcod.event.K_l:
         action = MoveAction(1, 0)
     elif key == tcod.event.K_b:
         action = ToggleBlockingAction()
     elif key == tcod.event.K_v:
         action = ToggleFovAction()
     elif key == tcod.event.K_ESCAPE:
         action = QuitAction()
     return action
コード例 #9
0
def player_act(player, level, game):
    command = game.get_command()

    if command.name == Command.MOVE:
        return MoveAction(*command.data)
    elif command.name == Command.PICKUP:
        return PickupAction()
    elif command.name == Command.DROP:
        return DropAction()

    return WaitAction()
コード例 #10
0
    def action_to_global_and_back(self, agent_action):
        """ Actions are also flipped on both axes """
        if isinstance(agent_action, MoveAction):
            state_action = MoveAction(Point(-agent_action.direction.X, -agent_action.direction.Y))
            
        else:
            agent_wall_pos = agent_action.position
            wall_pos = Point(constants.BOARD_SIZE - agent_wall_pos.X - 2, constants.BOARD_SIZE - agent_wall_pos.Y - 2)
            # orientation doesn't change
            state_action = WallAction(wall_pos, agent_action.orientation)

        return state_action
コード例 #11
0
ファイル: monster.py プロジェクト: osm3000/dungeons
def monster_act(monster, level, game):
    if monster.get(InFOV).in_fov:
        player = level.player
        monster_pos = monster.get(Position)
        player_pos = player.get(Position)
        distance = calc_distance(monster_pos.x, monster_pos.y, player_pos.x,
                                 player_pos.y)
        if distance < 2:
            return AttackAction(player)
        else:
            dx = int(round((player_pos.x - monster_pos.x) / distance))
            dy = int(round((player_pos.y - monster_pos.y) / distance))
            return MoveAction(dx, dy)

    return WaitAction()
コード例 #12
0
ファイル: game.py プロジェクト: samkovaly/quoridor-game-AI
    def move_action_from_mouse(self, mouse_position):
        """ returns a MoveAction based on the mouse position, this action may or may not be valid"""
        # get this squares grid X and Y
        selected_square_x = int(mouse_position.X / constants.SCREEN_SIZE *
                                constants.BOARD_SIZE)
        selected_square_y = int(mouse_position.Y / constants.SCREEN_SIZE *
                                constants.BOARD_SIZE)

        # Make a move action whos direction the the delta between the agent and the mouse click square.
        # Will determine if this action is valid later
        position = self.state.agent_positions[self.human_agent]
        new_position = Point(selected_square_x, selected_square_y)
        position_delta = Point(new_position.X - position.X,
                               new_position.Y - position.Y)
        move_action = MoveAction(position_delta)

        return move_action
コード例 #13
0
 def move(self, direction):
     self.actionQueue.append(MoveAction(direction))
コード例 #14
0
 def test_init(self):
     """Checks if distance is set correctly after initialising."""
     action = MoveAction(5)
     self.assertEqual(action.distance, 5)