コード例 #1
0
ファイル: Eidos.py プロジェクト: leonardochang36/ai-airhockey
def is_inside_area51(paddle_pos, state):

    if utils.next_pos_from_state(state)['x'] + state[
            'puck_radius'] <= state['board_shape'][1] * 0.150:
        return True

    return False
コード例 #2
0
    def process_move_from_state(self):
        new_puck_pos = utils.next_pos_from_state(self.state)

        # after initial position check for idleness
        if self.in_initial_state is not None:
            # if puck position changed, OK
            if new_puck_pos['x'] != self.state['puck_pos']['x']:
                self.in_initial_state = None
            # if number of idle moves exceeded, penalize with goal
            elif self.in_initial_state >= self.max_idle_moves:
                goal_for = 'left' if self.state['puck_pos']['x'] > self.board.shape[1]/2 else 'right'
                self.process_goal_for(goal_for, puck_to=('left' if goal_for == 'left' else 'right'))
                return goal_for
            # if idle but idle moves not exceed, increment counter
            else:
                self.in_initial_state += 1

        # update pos in state
        self.state['puck_pos'] = new_puck_pos

        # if is goal
        if utils.is_goal(self.state) is not None:
            self.process_goal_for(utils.is_goal(self.state))
            return utils.is_goal(self.state)

        # update speed (and direction) in state
        self.state['puck_speed'] = utils.next_speed(self.state)
        return None
コード例 #3
0
def estimate_path(current_state, after_time):
    state = copy.copy(current_state)
    path = []
    while after_time > 0:
        state['puck_pos'] = utils.next_pos_from_state(state)
        if utils.is_goal(state) is not None:
            break
        if utils.next_after_boundaries(state):
            state['puck_speed'] = utils.next_after_boundaries(state)
        path.append((state['puck_pos'], state['puck_speed']))
        after_time -= state['delta_t']
    return path
コード例 #4
0
def estimate_path(current_state, after_time):
    """ Function that function estimates the next moves in a after_time window
    Returns:
        list: coordinates and speed of puck for next ticks
    """

    state = copy.copy(current_state)
    path = []
    while after_time > 0:
        state['puck_pos'] = utils.next_pos_from_state(state)
        if utils.is_goal(state) is not None:
            break
        if utils.next_after_boundaries(state):
            state['puck_speed'] = utils.next_after_boundaries(state)
        path.append((state['puck_pos'], state['puck_speed']))
        after_time -= state['delta_t']
    return path