Exemplo n.º 1
0
def partition_location(game_state: GameState):
    """
    :param game_state:
    :return: not wall positions for red and blue respectively
    """
    width = game_state.getWalls().width
    height = game_state.getWalls().height
    halfway = width // 2

    red_movable = []
    blue_movable = []

    for x in range(0, width):
        for y in range(0, height):
            if game_state.hasWall(x, y):
                continue
            if x < halfway:
                red_movable.append((x, y))
            else:
                blue_movable.append((x, y))

    return red_movable, blue_movable
Exemplo n.º 2
0
    def registerInitialState(self, gameState: GameState):
        super().registerInitialState(gameState)

        self.red_movable, self.blue_movable = utility.partition_location(
            gameState)
        self.all_movable = gameState.getWalls().asList(False)
        self.neighbors = utility.calculate_neighbors(gameState,
                                                     self.all_movable)
        self.dead_end_path = utility.calculate_dead_end(
            self.all_movable, self.neighbors)
        self.dead_end_path_length = dead_end_path_length_calculation(
            self.dead_end_path)
        self.red_boundary = utility.agent_boundary_calculation(
            self.red_movable, True)
        self.blue_boundary = utility.agent_boundary_calculation(
            self.blue_movable, False)

        if not BasicAgent.INITIAL_TARGET:
            BasicAgent.INITIAL_TARGET = utility.initial_offensive_position_calculation(
                self.red_boundary, self.blue_boundary, self,
                utility.get_agents_positions(gameState, 0),
                utility.get_agents_positions(gameState, 1), gameState)
Exemplo n.º 3
0
    def __init__(self, startingGameState: GameState,
                 captureAgent: CaptureAgent):
        self.expanded = 0
        self.startingGameState = startingGameState
        self.captureAgent: CaptureAgent = captureAgent
        self.enemies = self.captureAgent.getOpponents(startingGameState)
        self.walls = startingGameState.getWalls()
        self.intialPosition = self.startingGameState.getAgentPosition(
            self.captureAgent.index)
        self.gridWidth = self.captureAgent.getFood(startingGameState).width
        self.gridHeight = self.captureAgent.getFood(startingGameState).height
        if self.captureAgent.red:
            self.boundary = int(self.gridWidth / 2) - 1
            self.myPreciousFood = self.startingGameState.getRedFood()
        else:
            self.boundary = int(self.gridWidth / 2)
            self.myPreciousFood = self.startingGameState.getBlueFood()

        (self.viableBoundaryPositions,
         self.possibleEnemyEntryPositions) = self.getViableBoundaryPositions()

        self.GOAL_POSITION = self.getGoalPosition()
        self.goalDistance = self.captureAgent.getMazeDistance(
            self.GOAL_POSITION, self.intialPosition)