Exemple #1
0
    def test_pubkey_fetch(self):
        sig = util.sign(self.consultant_privkey, False, "add_pubkey")
        self.server.add_pubkey(b64encode(sig), self.client_id, b64encode(self.tree_id), self.client_pubkey)

        #then fetch it
        #sig = util.sign(self.client_privkey, False, "fetch_pubkey", self.client_id, b64encode(self.tree_id))
        sig = util.sign(self.client_privkey, False, "fetch_pubkey")
        expected = self.client_pubkey
        result = self.server.fetch_pubkey(b64encode(sig), self.client_id, b64encode(self.tree_id))
        self.assertEqual(expected, result)
Exemple #2
0
    def test_pubkey_del(self):
        #first add the key
        sig = util.sign(self.consultant_privkey, False, "add_pubkey")
        self.server.add_pubkey(b64encode(sig), self.client_id, b64encode(self.tree_id), self.client_pubkey)

        #then remove it
        #sig = util.sign(self.consultant_privkey, False, "del_pubkey", self.client_id, b64encode(self.tree_id))
        sig = util.sign(self.consultant_privkey, False, "del_pubkey")
        expected = "Removed key for client {id}".format(id=self.client_id)
        result = self.server.del_pubkey(b64encode(sig), self.client_id, b64encode(self.tree_id))
        self.assertEqual(expected, result)
    def check_expired(self, game_info: GameInformation) -> bool:
        # expired if ball is of wrong half or on direct trajectory toward goal
        # check if ball on defensive half
        ball_location = game_info.ball.location
        if util.sign(ball_location.y) != util.sign(game_info.me.team):
            self.expired = True
        # check direction of ball movement
        ball_direction = game_info.ball.velocity


        return self.expired
Exemple #4
0
    def test_clear_keys(self):
        # first add the key
        sig = util.sign(self.consultant_privkey, False, "add_pubkey")
        self.server.add_pubkey(b64encode(sig), self.client_id, b64encode(self.tree_id), self.client_pubkey)
        # then fetch it
        sig = util.sign(self.client_privkey, False, "fetch_pubkey")
        expected = self.client_pubkey
        result = self.server.fetch_pubkey(b64encode(sig), self.client_id, b64encode(self.tree_id))
        self.assertEqual(expected, result)
 
        # then clear the keys
        sig = util.sign(self.consultant_privkey, False, "clear_keys")
        result = self.server.clear_keys(b64encode(sig))
        self.assertTrue(result)
Exemple #5
0
    def execute(self, game_info: GameInformation):
        """Attempts to drive into the ball in a direction that hits the ball towards the goal.

        Overrides the State class's execute function.
        The ground controller is automatically used.
        The target location is on the outside of the ball on a line connecting the ball and the opponents goal.

        Attributes:
            game_info: information detailing the current status of various game objects

        """

        team = util.sign(game_info.me.team)
        target_goal = util.GOAL_HOME * -team

        ball_to_goal = target_goal - game_info.ball.location
        # distance_to_goal = ball_to_goal.length()
        direction_to_goal = ball_to_goal.normalized()

        aim_location = game_info.ball.location - (direction_to_goal *
                                                  util.BALL_RADIUS)
        local_target = relative_location(game_info.me.location,
                                         game_info.me.rotation, aim_location)
        self.debug['target'] = aim_location

        self.next_controller_state = ground_controller(game_info, local_target)
Exemple #6
0
 def check_expired(self, game_info: GameInformation):
     """If the ball is not reasonably close to being between the car and the goal, the state expires"""
     ball_direction = game_info.ball.local_location
     goal_location = relative_location(
         game_info.me.location, game_info.me.rotation,
         util.GOAL_HOME * -util.sign(game_info.me.team))
     angle = ball_direction.ang_to(goal_location)
     if angle < (math.pi / 2):
         return False
     return True
Exemple #7
0
 def standing_on_platform(arbiter, space, data):
     enemy_body = arbiter.shapes[0].body
     position_x = arbiter.shapes[1].body.position.x
     enemy_body.max_walk_x = max(arbiter.shapes[1].get_vertices(),
                                 key=lambda k: k.x).x + position_x
     enemy_body.min_walk_x = min(arbiter.shapes[1].get_vertices(),
                                 key=lambda k: k.x).x + position_x
     enemy_body.current_max_velocity = arbiter.shapes[
         1].body.velocity.x + sign(
             enemy_body.velocity.x) * Enemy.max_relative_velocity
     enemy_body.touching_ground = arbiter.shapes[1].body
     return True
Exemple #8
0
 def standing_on_platform(arbiter, space, data):
     normal = Vec2d(0, -1)
     if Player.compare_velocity(arbiter.contact_point_set.normal, normal):
         player_body = arbiter.shapes[0].body
         player_body.still = Player.compare_velocity(
             arbiter.shapes[0].body.velocity,
             arbiter.shapes[1].body.velocity)
         player_body.current_max_velocity = arbiter.shapes[
         1].body.velocity.x + sign(
             player_body.velocity.x) * Player.running_velocity
         player_body.touching_ground = arbiter.shapes[1].body
     return True
Exemple #9
0
    def get_output(self, gamePacket: GameTickPacket) -> SimpleControllerState:
        """Calculates the next set of commands for the bot.
        
        This function should run 60 times a second, or once for every game tick. This function also calls a set
        of commands to draw debug information on screen.
        
        Args:
            gamePacket (GameTickPacket): set of current information about the game
            
        Returns:
            SimpleControllerState: the next set of commands for the bot
            
        """
        self.preprocess(gamePacket)
                
        if self.state.expired == True:
            if AimShot().checkAvailable(self) == True:
                self.state = AimShot()
                self.stateMessage = "Aiming"
            #if Shoot().checkAvailable(self) == True:
            #    self.state = Shoot()
            #    self.stateMessage = "Shooting"
            elif Defend().checkAvailable(self) == True:
                self.state = Defend()
                self.stateMessage = "Defending"
            else:
                self.state = BallChase()
                self.stateMessage = "Chasing"
        controller_state = self.state.execute(self)
        
        team = sign(self.team)
        ball_side = sign(self.ball.location.y)
        
        my_car = gamePacket.game_cars[self.index]
        message = f"{self.stateMessage} | Team {team} | Ball {ball_side} "
        action_display = message
        ball_path = predict_ball_path(self)
        draw_debug(self.renderer, my_car, gamePacket.game_ball, action_display, ball_path)

        return controller_state
Exemple #10
0
 def setUp(self):
     self.server = ServerProxy("http://localhost:8000", allow_none=True)
     self.consultant_id = 0
     self.consultant_privkey = "".join(open('./keys/consultant.pem').readlines())
     self.consultant_pubkey = "".join(open('./keys/consultant.pub.pem').readlines())
     self.client_privkey = "".join(open('./keys/client1.pem').readlines())
     self.client_pubkey = "".join(open('./keys/client1.pub.pem').readlines())
     self.client_id = 1
     self.tree_id = util.digest(self.client_id)
     # add a pubkey to the serv
     sig = util.sign(self.consultant_privkey, False, "add_pubkey")
     #call the server
     self.server.add_pubkey(b64encode(sig), self.client_id, b64encode(self.tree_id), self.client_pubkey)
Exemple #11
0
 def execute(self, agent):
     self.checkExpired(agent)
     team = util.sign(agent.team)
     ball_path = predict_ball_path(agent)
     danger = False
     for loc in ball_path:
         if(math.fabs(loc.y) > math.fabs(util.FIELD_LENGTH / 2)):
             danger = True
     target_location = agent.ball.local_location
     if danger:
         #aim to hit ball to the side
         #detect of ball is east or west of bot
         east_multiplier = util.sign(agent.ball.location.x - agent.me.location.x)
         #aim for side of the ball
         aim_location = agent.ball.location + Vec3(east_multiplier * util.BALL_RADIUS, 0, 0)
         target_location = relative_location(agent.me.location, agent.me.rotation, aim_location)
     elif agent.ball.local_location.length() > 1500:
         #get in goal
         target_location = relative_location(agent.me.location, agent.me.rotation, util.GOAL_HOME * team)
     elif agent.ball.local_location.length() < 500:
         return shotController(agent, util.GOAL_HOME * -team)
     return groundController(agent, target_location)
Exemple #12
0
    def execute(self, game_info):
        # aim to hit ball to the side
        # detect of ball is east or west of bot
        east_multiplier = util.sign(game_info.me.location.x -
                                    game_info.ball.location.x)
        # aim for side of the ball
        aim_location = game_info.ball.location + Vec3(
            east_multiplier * util.BALL_RADIUS, 0, 0)
        target_location = relative_location(game_info.me.location,
                                            game_info.me.rotation,
                                            aim_location)
        self.debug['target'] = aim_location

        self.next_controller_state = ground_controller(game_info,
                                                       target_location)
Exemple #13
0
 def execute(self, agent):
     """Attempts to hit the ball in a way that pushes it toward the goal"""
     self.checkExpire(agent)
     
     team = util.sign(agent.team)
     targetGoal = util.GOAL_HOME * -team
     
     ball_to_goal = targetGoal - agent.ball.location
     #distance_to_goal = ball_to_goal.length()
     direction_to_goal = ball_to_goal.normalized()
     
     aim_location = agent.ball.location - (direction_to_goal * util.BALL_RADIUS)
     local_target = relative_location(agent.me.location, agent.me.rotation, aim_location)
     
     return groundController(agent, local_target)
Exemple #14
0
 def check_expired(self, game_info: GameInformation) -> bool:
     if util.sign(game_info.ball.location.y) != util.sign(
             game_info.me.team):
         self.expired = True
     return self.expired
Exemple #15
0
    def execute(self, game_info):
        team = util.sign(game_info.me.team)

        self.next_controller_state = ground_controller(
            game_info, util.GOAL_HOME * team * -1)
Exemple #16
0
 def checkExpire(self, agent):
     """Determines if the state is no longer useful"""
     if util.sign(agent.ball.location.y) == util.sign(agent.team):
         self.expired = True
Exemple #17
0
 def checkAvailable(self, agent):
     """If the ball is between the car and the goal, it is possible to shoot"""
     ballDirection = agent.ball.local_location
     goal_location = relative_location(agent.me.location, agent.me.rotation, util.GOAL_HOME*-util.sign(agent.team))
     angle = ballDirection.ang_to(goal_location)
     if angle < (math.pi / 2):
         return True
     return False
Exemple #18
0
 def checkAvailable(self, agent):
     """Available when the ball is on the friendly side of the field"""
     if util.sign(agent.ball.location.y) == util.sign(agent.team):
         return True
     return False
Exemple #19
0
 def test_pubkey_add_twice(self):
     sig = util.sign(self.consultant_privkey, False, "add_pubkey")
     expected = "Tried to add key for client {0} twice!".format(self.client_id)
     self.server.add_pubkey(b64encode(sig), self.client_id, b64encode(self.tree_id), self.client_pubkey)
     result = self.server.add_pubkey(b64encode(sig), self.client_id, b64encode(self.tree_id), self.client_pubkey)
     self.assertEqual(expected, result)
Exemple #20
0
 def checkExpired(self, agent):
     if util.sign(agent.ball.location.y) != util.sign(agent.team):
         self.expired = True
Exemple #21
0
    def get_output(self, game_packet: GameTickPacket) -> SimpleControllerState:
        """Calculates the next set of commands for the bot.

        This function should run 60 times a second, or once for every game tick. This function also calls a set
        of commands to draw debug information on screen.

        Args:
            game_packet (GameTickPacket): set of current information about the game

        Returns:
            SimpleControllerState: the next set of commands for the bot

        """
        # debugging flags. debug mode tells whether to print messages to console, debug_change flags when a change
        # occurs that should trigger a debug message
        debug_mode = True
        debug_change = False

        # Keep our boost pad info updated with which pads are currently active
        # self.boost_pad_tracker.update_boost_status(game_packet)

        # clear active_sequence when kickoff is starting
        if self.kickoff_flag is False and game_packet.game_info.is_round_active and \
                game_packet.game_info.is_kickoff_pause:
            self.active_sequence = None

        self.preprocess(game_packet)

        game_info = GameInformation(self.me, self.ball)

        # if there is an active sequence then that gets priority and no other state or controller calculations are done
        if self.active_sequence is not None and not self.active_sequence.done:
            self.controller_state = self.active_sequence.tick(game_packet)
        # if there is no active sequence we proceed with normal state calculations
        else:
            """
            # kickoff state get priority
            if self.kickoff_flag:
                self.state = st.Kickoff()
                self.state_message = "Kickoff"
            # get new state if expired
            elif self.state.check_expired(game_info):
                debug_change = True
                if util.sign(self.ball.location.y) == util.sign(self.me.team):
                    self.state = st.Defend()
                    self.state_message = "Defend"
                elif util.sign(self.ball.location.y) != util.sign(self.me.team):
                    self.state = st.Shoot()
                    self.state_message = "Shoot"
                else:
                    self.state = st.BallChase()
                    self.state_message = "BallChase"
            """
            self.state = st.BallChase()
            self.state_message = "BallChase"
            # execute the current state
            self.state.execute(game_info)
            if self.state.has_sequence():
                self.active_sequence = self.state.get_sequence()
                self.controller_state = self.active_sequence.tick(game_packet)
            else:
                self.controller_state = self.state.get_next_controller_state()

        team = util.sign(self.team)
        ball_side = util.sign(self.ball.location.y)

        message = f"{self.state_message} | Team {team} | Ball {ball_side}"
        if debug_change and debug_mode:
            print(message)
        # action_display = message
        # ball_path = util.predict_ball_path(self)
        # turn_loops = get_turn_circle(self.me.velocity, self.me.location)
        self.draw_debug(message, self.state.get_debug()['target'])

        return self.controller_state
Exemple #22
0
 def execute(self, agent):
     team = util.sign(agent.team)
     self.expired = self.checkExpired(agent, team)
     
     return shotController(agent, util.GOAL_HOME*team*-1)
Exemple #23
0
 def check_expired(self, game_info: GameInformation) -> bool:
     """Determines if the state is no longer useful"""
     if util.sign(game_info.ball.location.y) == util.sign(
             game_info.me.team):
         self.expired = True
     return self.expired
Exemple #24
0
 def test_pubkey_add(self):
     sig = util.sign(self.consultant_privkey, False, "add_pubkey")
     #call the server
     expected = "Added key for client {0}".format(self.client_id)
     result = self.server.add_pubkey(b64encode(sig), self.client_id, b64encode(self.tree_id), self.client_pubkey)
     self.assertEqual(expected, result)
Exemple #25
0
 def checkAvailable(self, agent):
     """Determines if the state is an available option"""
     if util.sign(agent.ball.location.y) != util.sign(agent.team):
         return True
     else:
         return False