Exemplo n.º 1
0
 def GoToLocationAction(self, a):
     goTo = self.action2Coord[a - ACTIONS_START_IDX_SCOUT]
     self.scoutInProgress = True
     self.goToLast = goTo
     return actions.FunctionCall(
         SC2_Actions.ATTACK_MINIMAP,
         [SC2_Params.NOT_QUEUED, SwapPnt(goTo)]), True
    def Action2SC2Action(self, obs, a, moveNum):
        if moveNum == 0:
            finishedAction = False
            if a == None:
                print("ERROR\n\n None\n\n")
            self.buildingSelected = self.SelectBuilding2Train(a)
            if self.buildingSelected != None:
                target = self.buildingSelected.m_screenLocation
                return actions.FunctionCall(
                    SC2_Actions.SELECT_POINT,
                    [SC2_Params.SELECT_SINGLE,
                     SwapPnt(target)]), finishedAction

        elif moveNum == 1:
            if 'build_queue' in obs.observation:
                self.CorrectQueue(obs.observation['build_queue'])

            finishedAction = True
            unit2Train = ACTION_2_UNIT[a]
            sc2Action = TerranUnit.ARMY_SPEC[unit2Train].sc2Action
            if sc2Action in obs.observation['available_actions']:
                self.sharedData.prevTrainActionReward = self.sharedData.unitTrainValue[
                    unit2Train]
                self.Add2Q(a)
                return actions.FunctionCall(
                    sc2Action, [SC2_Params.QUEUED]), finishedAction

        return SC2_Actions.DO_NOTHING_SC2_ACTION, True
Exemplo n.º 3
0
    def ActionCreateScv(self, obs, moveNum):
        if moveNum == 0:
            unitType = obs.observation['feature_screen'][SC2_Params.UNIT_TYPE]
            target = SelectBuildingValidPoint(unitType, Terran.CommandCenter)
            if target[0] >= 0:
                return actions.FunctionCall(
                    SC2_Actions.SELECT_POINT,
                    [SC2_Params.SELECT_SINGLE,
                     SwapPnt(target)]), False

        elif moveNum == 1:
            if SC2_Actions.TRAIN_SCV in obs.observation['available_actions']:
                terminal = self.rallyPointSet
                self.sharedData.scvBuildingQ.append(ScvCmd())
                return actions.FunctionCall(SC2_Actions.TRAIN_SCV,
                                            [SC2_Params.QUEUED]), terminal

        if moveNum == 2:
            if SC2_Actions.RALLY_SCV in obs.observation['available_actions']:
                coord = self.rallyCoordScv
                self.rallyPointSet = True
                return actions.FunctionCall(
                    SC2_Actions.RALLY_SCV,
                    [SC2_Params.NOT_QUEUED, coord]), True

        return SC2_Actions.DO_NOTHING_SC2_ACTION, True
    def BuildAdditionAction(self, obs, moveNum):
        buildingType = BUILD_ACTIONS.ACTION_2_BUILDING_TRANSITION[
            self.current_action][0]
        additionType = BUILD_ACTIONS.ACTION_2_BUILDING_TRANSITION[
            self.current_action][1]

        if moveNum == 0:
            # select building without addition
            self.building2AddIdx = self.SelectBuilding2Add(buildingType)
            if self.building2AddIdx >= 0:
                coord = self.sharedData.buildingCompleted[buildingType][
                    self.building2AddIdx].m_screenLocation
                return actions.FunctionCall(
                    SC2_Actions.SELECT_POINT,
                    [SC2_Params.SELECT_SINGLE,
                     SwapPnt(coord)]), False

        elif moveNum == 1:
            sc2Action = TerranUnit.BUILDING_SPEC[additionType].sc2Action

            if sc2Action in obs.observation['available_actions']:
                buildingCmdLocations = self.GetBuildingCmdAdditionLocations()
                coord = GetLocationForBuilding(obs, buildingType,
                                               self.notAllowedDirections2CC,
                                               buildingCmdLocations,
                                               additionType)
                if coord[0] >= 0:
                    buildCmd = BuildingCmdAddition(coord)
                    if additionType == Terran.BarracksReactor:
                        buildCmd.m_qHeadSize = 2

                    self.sharedData.buildCommands[additionType].append(
                        buildCmd)
                    del self.sharedData.buildingCompleted[buildingType][
                        self.building2AddIdx]
                    return actions.FunctionCall(
                        sc2Action,
                        [SC2_Params.QUEUED, SwapPnt(coord)]), True

        return SC2_Actions.DO_NOTHING_SC2_ACTION, True
Exemplo n.º 5
0
    def Action2SC2Action(self, obs, a, moveNum):
        if self.playAgent:
            if moveNum == 0:
                if SC2_Actions.SELECT_ARMY in obs.observation['available_actions']:
                    return actions.FunctionCall(SC2_Actions.SELECT_ARMY, [SC2_Params.NOT_QUEUED]), False

            elif moveNum == 1:

                self.sharedData.armyInAttack = self.ArmySelected(obs)
                CountSelectedLocationMat(obs, self.sharedData.superGridSize, self.sharedData.selfArmyMat)
                if len(self.sharedData.armyInAttack) > 0:
                    coordBattle = self.InBattle(obs)
                    if self.sharedData.inBattle:
                        self.attackPreformAction = True
                        self.moveNum = 0
                        return actions.FunctionCall(SC2_Actions.MOVE_CAMERA, [SwapPnt(coordBattle)]), False

                    elif SC2_Actions.ATTACK_MINIMAP in obs.observation['available_actions']:     
                        coord = self.AttackCoord(a, obs)
                        return actions.FunctionCall(SC2_Actions.ATTACK_MINIMAP, [SC2_Params.NOT_QUEUED, SwapPnt(coord)]), True
                    

            elif moveNum >= 2:
                if self.sharedData.inBattle:
                    if self.attackPreformAction:
                        sc2Action, terminal = self.subAgents[SUB_AGENT_ID_BATTLEMNGR].Action2SC2Action(obs, self.moveNum)
                        self.moveNum += 1
                        self.attackPreformAction = not terminal
                        return sc2Action, False
                    else:
                        return actions.FunctionCall(SC2_Actions.MOVE_CAMERA, [SwapPnt(self.sharedData.commandCenterLoc[0])]), True
        else:
            return self.subAgents[SUB_AGENT_ID_BATTLEMNGR].Action2SC2Action(obs, moveNum)
                    
        
        return SC2_Actions.DO_NOTHING_SC2_ACTION, True
Exemplo n.º 6
0
    def FirstStep(self, obs):
        super(SuperAgent, self).FirstStep(obs)

        self.move_number = 0
        self.sharedData.numStep = 0
        self.sharedData.numAgentStep = 0

        self.sharedData.__init__()

        cc_y, cc_x = (self.unit_type == Terran.CommandCenter).nonzero()
        if len(cc_y) > 0:
            middleCC = FindMiddle(cc_y, cc_x)
            cameraCornerNorthWest, cameraCornerSouthEast = GetScreenCorners(
                obs)
            miniMapLoc = Scale2MiniMap(middleCC, cameraCornerNorthWest,
                                       cameraCornerSouthEast)
            self.sharedData.commandCenterLoc = [miniMapLoc]
            self.sharedData.buildingCompleted[Terran.CommandCenter].append(
                Building(middleCC))

        self.sharedData.unitTrainValue = self.unitPower

        # actions:
        self.current_action = None

        # states:
        self.current_state = np.zeros(SUPER_STATE.SIZE, float)
        self.previous_scaled_state = np.zeros(SUPER_STATE.SIZE, float)
        self.current_scaled_state = np.zeros(SUPER_STATE.SIZE, float)

        self.accumulatedTrainReward = 0.0

        self.subAgentsActions = {}
        for sa in range(NUM_SUB_AGENTS):
            self.subAgentsActions[sa] = None
            self.subAgents[sa].FirstStep(obs)

        if len(self.sharedData.commandCenterLoc) >= 1:
            self.go2BaseAction = actions.FunctionCall(
                SC2_Actions.MOVE_CAMERA,
                [SwapPnt(self.sharedData.commandCenterLoc[0])])
        else:
            self.go2BaseAction = SC2_Actions.DO_NOTHING_SC2_ACTION

        self.maxSupply = False
Exemplo n.º 7
0
    def Action2SC2Action(self, obs, a, moveNum):
        if SC2_Actions.STOP in obs.observation['available_actions']:
            sc2Action = SC2_Actions.STOP_SC2_ACTION
        else:
            sc2Action = SC2_Actions.DO_NOTHING_SC2_ACTION

        if self.current_action > BaseAttackActions.DO_NOTHING:
            goTo = self.enemyBuildingGridLoc2ScreenLoc[
                self.current_action -
                BaseAttackActions.START_IDX_ATTACK].copy()
            if SC2_Actions.ATTACK_SCREEN in obs.observation[
                    'available_actions']:
                sc2Action = actions.FunctionCall(
                    SC2_Actions.ATTACK_SCREEN,
                    [SC2_Params.NOT_QUEUED,
                     SwapPnt(goTo)])

        return sc2Action, True
Exemplo n.º 8
0
    def Action2SC2Action(self, obs, a, moveNum):
        if moveNum == 0:
            if a < ACTIONS_END_IDX_SCOUT:
                if self.isScoutGroup:
                    return actions.FunctionCall(
                        SC2_Actions.SELECT_CONTROL_GROUP, [
                            SC2_Params.CONTROL_GROUP_RECALL,
                            CONTROL_GROUP_ID_SCOUT
                        ]), False
                else:
                    target = self.SelectScoutingUnit(obs)
                    if target[
                            0] >= 0 and SC2_Actions.SELECT_POINT in obs.observation[
                                'available_actions']:
                        return actions.FunctionCall(
                            SC2_Actions.SELECT_POINT,
                            [SC2_Params.SELECT_SINGLE,
                             SwapPnt(target)]), False

        elif moveNum == 1:
            if a < ACTIONS_END_IDX_SCOUT:
                if self.isScoutGroup:
                    if SC2_Actions.ATTACK_MINIMAP in obs.observation[
                            'available_actions']:
                        return self.GoToLocationAction(a)

                elif SC2_Actions.SELECT_CONTROL_GROUP in obs.observation[
                        'available_actions']:
                    self.isScoutGroup = True
                    return actions.FunctionCall(
                        SC2_Actions.SELECT_CONTROL_GROUP,
                        [SC2_Params.CONTROL_GROUP_SET, CONTROL_GROUP_ID_SCOUT
                         ]), False

        elif moveNum == 2:
            if a < ACTIONS_END_IDX_SCOUT:
                if SC2_Actions.ATTACK_MINIMAP in obs.observation[
                        'available_actions']:
                    return self.GoToLocationAction(a)

        return SC2_Actions.DO_NOTHING_SC2_ACTION, True
Exemplo n.º 9
0
    def ActionAdd2Group(self, obs, moveNum, toGroup, fromGroup):
        if moveNum == 0:
            return actions.FunctionCall(
                SC2_Actions.SELECT_CONTROL_GROUP,
                [SC2_Params.CONTROL_GROUP_RECALL, [fromGroup]]), False

        elif moveNum == 1:
            unitSelected = obs.observation['feature_screen'][
                SC2_Params.SELECTED_IN_SCREEN]
            unit_y, unit_x = SelectUnitValidPoints(unitSelected != 0)
            if len(unit_y) > 0:
                target = [unit_x[0], unit_y[0]]
                return actions.FunctionCall(
                    SC2_Actions.SELECT_POINT,
                    [SC2_Params.SELECT_SINGLE, target]), False

        elif moveNum == 2:
            scvStatus = list(obs.observation['single_select'])
            if len(scvStatus) == 1:
                if toGroup == SCV_GROUP_GAS1:
                    self.sharedData.scvGasGroups[0] = SCV_GROUP_GAS1
                elif toGroup == SCV_GROUP_GAS2:
                    self.sharedData.scvGasGroups[1] = SCV_GROUP_GAS2

                return actions.FunctionCall(SC2_Actions.SELECT_CONTROL_GROUP, [
                    SC2_Params.CONTROL_GROUP_APPEND_AND_STEAL,
                    [ALL_SCV_GROUPS[toGroup]]
                ]), False

        elif moveNum == 3:
            if SC2_Actions.HARVEST_GATHER in obs.observation[
                    'available_actions']:
                target = self.GroupTargetResources(
                    toGroup,
                    obs.observation['feature_screen'][SC2_Params.UNIT_TYPE])
                if target[0] >= 0:
                    return actions.FunctionCall(
                        SC2_Actions.HARVEST_GATHER,
                        [SC2_Params.QUEUED, SwapPnt(target)]), True

        return SC2_Actions.DO_NOTHING_SC2_ACTION, True
Exemplo n.º 10
0
    def BuildAction(self, obs, moveNum):
        buildingType = BUILD_ACTIONS.ACTION_2_BUILDING_TRANSITION[
            self.current_action]

        if moveNum == 0:
            if buildingType == Terran.Refinery:
                # round num refinery for non precision in float value
                numRefinery = round(
                    self.current_scaled_state[BUILD_STATE.REFINERY_IDX] +
                    self.current_scaled_state[
                        BUILD_STATE.IN_PROGRESS_REFINERY_IDX])
                group2Select = self.sharedData.scvGasGroups[int(numRefinery)]
            else:
                if self.NumBeforeProgress(buildingType) == 0:
                    group2Select = self.sharedData.scvMineralGroup
                else:
                    group2Select = None

            if group2Select != None:
                return actions.FunctionCall(
                    SC2_Actions.SELECT_CONTROL_GROUP,
                    [SC2_Params.CONTROL_GROUP_RECALL, [group2Select]]), False

            unitType = obs.observation['feature_screen'][SC2_Params.UNIT_TYPE]
            scv_y, scv_x = SelectUnitValidPoints(unitType == Terran.SCV)
            if len(scv_y) > 0:
                target = [scv_y[0], scv_x[0]]
                return actions.FunctionCall(
                    SC2_Actions.SELECT_POINT,
                    [SC2_Params.SELECT_ALL,
                     SwapPnt(target)]), False

        elif moveNum == 1:
            unitSelected = obs.observation['feature_screen'][
                SC2_Params.SELECTED_IN_SCREEN]
            unit_y, unit_x = SelectUnitValidPoints(unitSelected != 0)
            if len(unit_y) > 0:
                target = [unit_x[0], unit_y[0]]
                return actions.FunctionCall(
                    SC2_Actions.SELECT_POINT,
                    [SC2_Params.SELECT_SINGLE, target]), False

        elif moveNum == 2:
            finishedAction = buildingType == Terran.Refinery
            sc2Action = TerranUnit.BUILDING_SPEC[buildingType].sc2Action

            # preform build action. if action not available go back to harvest
            if sc2Action in obs.observation['available_actions']:
                buildingCmdLocations = self.GetBuildingCmdAdditionLocations()
                coord = GetLocationForBuilding(obs, buildingType,
                                               self.notAllowedDirections2CC,
                                               buildingCmdLocations)
                if coord[SC2_Params.Y_IDX] >= 0:
                    self.sharedData.buildCommands[buildingType].append(
                        BuildingCmd(coord))
                    return actions.FunctionCall(
                        sc2Action, [SC2_Params.NOT_QUEUED,
                                    SwapPnt(coord)]), finishedAction
            moveNum += 1

        if moveNum == 3:
            finishedAction = True
            if SC2_Actions.HARVEST_GATHER in obs.observation[
                    'available_actions']:
                unitType = obs.observation['feature_screen'][
                    SC2_Params.UNIT_TYPE]
                target = GatherResource(unitType,
                                        SC2_Params.NEUTRAL_MINERAL_FIELD)
                if target[0] < 0:
                    target = GatherResource(unitType, [Terran.Refinery])

                if target[0] >= 0:
                    return actions.FunctionCall(
                        SC2_Actions.HARVEST_GATHER,
                        [SC2_Params.QUEUED, SwapPnt(target)]), finishedAction

        return SC2_Actions.DO_NOTHING_SC2_ACTION, True
Exemplo n.º 11
0
    def Action2SC2Action(self, obs, a, moveNum):
        if SC2_Actions.STOP in obs.observation['available_actions']:
            sc2Action = SC2_Actions.STOP_SC2_ACTION
        else:
            sc2Action = SC2_Actions.DO_NOTHING_SC2_ACTION

        if a > ArmyAttackActions.DO_NOTHING:     
            goTo = self.enemyArmyGridLoc2ScreenLoc[a - ArmyAttackActions.START_IDX_ATTACK].copy()
            if SC2_Actions.ATTACK_SCREEN in obs.observation['available_actions']:
                sc2Action = actions.FunctionCall(SC2_Actions.ATTACK_SCREEN, [SC2_Params.NOT_QUEUED, SwapPnt(goTo)])
       
        self.isActionCommitted = True
        self.lastActionCommitted = a

        return sc2Action, True
Exemplo n.º 12
0
    def ActionCheckQueue(self, obs, moveNum):
        if moveNum == 0:
            found = self.FindQueue2Check()
            self.idxBuildingQueue2Check = 0
            if not found:
                return SC2_Actions.DO_NOTHING_SC2_ACTION, True
                   
        if self.idxBuildingQueue2Check > 0:
            self.CorrectQueue(obs.observation['build_queue'])

        buildingType = self.queue2Check[self.currQueue2Check]
        numBuildings = len(self.sharedData.buildingCompleted[buildingType])

        if self.idxBuildingQueue2Check >= numBuildings:
            additionType = self.addition2QueueCheck[self.currQueue2Check]
            idx = self.idxBuildingQueue2Check - numBuildings

            if idx >= len(self.sharedData.buildingCompleted[additionType]):
                self.buildingSelected = None
                self.currQueue2Check = (self.currQueue2Check + 1) % len(self.queue2Check)
                return SC2_Actions.DO_NOTHING_SC2_ACTION, True
            
            self.buildingSelected = self.sharedData.buildingCompleted[additionType][idx]
        else:
            self.buildingSelected = self.sharedData.buildingCompleted[buildingType][self.idxBuildingQueue2Check]

        self.idxBuildingQueue2Check += 1

        target = self.buildingSelected.m_screenLocation
        return actions.FunctionCall(SC2_Actions.SELECT_POINT, [SC2_Params.SELECT_SINGLE, SwapPnt(target)]), False
Exemplo n.º 13
0
    def ActionIdleWorkerImployment(self, obs, moveNum):
        if moveNum == 0:
            if SC2_Actions.SELECT_IDLE_WORKER in obs.observation['available_actions']:
                return actions.FunctionCall(SC2_Actions.SELECT_IDLE_WORKER, [SC2_Params.SELECT_ALL]), False
            
        elif moveNum == 1:
            scvStatus = GetSelectedUnits(obs)
            if len(scvStatus) > 0:
                return actions.FunctionCall(SC2_Actions.SELECT_CONTROL_GROUP, [SC2_Params.CONTROL_GROUP_APPEND_AND_STEAL, [self.sharedData.scvMineralGroup]]), False
            
        elif moveNum == 2:
            if SC2_Actions.HARVEST_GATHER in obs.observation['available_actions']:
                unitType = obs.observation['feature_screen'][SC2_Params.UNIT_TYPE]
                target = GatherResource(unitType, SC2_Params.NEUTRAL_MINERAL_FIELD)
                if target[0] < 0:
                    target = GatherResource(unitType, Terran.Refinery)
                
                if target[0] >= 0:
                    return actions.FunctionCall(SC2_Actions.HARVEST_GATHER, [SC2_Params.QUEUED, SwapPnt(target)]), True

        return SC2_Actions.DO_NOTHING_SC2_ACTION, True
Exemplo n.º 14
0
    def ActionBuildingCount(self, obs, moveNum):
        if moveNum == 0:  
            unitType = obs.observation['feature_screen'][SC2_Params.UNIT_TYPE]
            target = self.SelectBuildingPoint(unitType)
            if target[0] >= 0 and SC2_Actions.SELECT_POINT in obs.observation['available_actions']:
                return actions.FunctionCall(SC2_Actions.SELECT_POINT, [SC2_Params.SELECT_ALL, SwapPnt(target)]), False

        elif moveNum == 1 and not self.isActionFailed:
            # possible to exploit this move for another check
            self.UpdateBuildingCompletion(obs)
            return SC2_Actions.DO_NOTHING_SC2_ACTION, True

        return SC2_Actions.DO_NOTHING_SC2_ACTION, True
Exemplo n.º 15
0
    def ActionHarvestGas(self, obs, moveNum):
        if moveNum == 0:
            gasGroup = self.sharedData.scvGasGroups[self.gasGroup2SentScv]
            if gasGroup != None:
                return actions.FunctionCall(SC2_Actions.SELECT_CONTROL_GROUP, [SC2_Params.CONTROL_GROUP_RECALL, [gasGroup]]), False
        elif moveNum == 1:
            if SC2_Actions.HARVEST_GATHER in obs.observation['available_actions']:
                target = self.sharedData.buildingCompleted[Terran.Refinery][self.gasGroup2SentScv].m_screenLocation
                self.gasGroup2SentScv += 1
                return actions.FunctionCall(SC2_Actions.HARVEST_GATHER, [SC2_Params.QUEUED, SwapPnt(target)]), True

        return SC2_Actions.DO_NOTHING_SC2_ACTION, True
Exemplo n.º 16
0
    def CreateMineralsGroup(self, obs, moveNum):
        if moveNum == 0:
            # select scv
            unitType = obs.observation['feature_screen'][SC2_Params.UNIT_TYPE]
            unit_y, unit_x = SelectUnitValidPoints(unitType == Terran.SCV)                    
            if len(unit_y) > 0:
                target = [unit_x[0], unit_y[0]]
                return actions.FunctionCall(SC2_Actions.SELECT_POINT, [SC2_Params.SELECT_ALL, target]), False
        if moveNum == 1:
            scvStatus = GetSelectedUnits(obs)
            if len(scvStatus) > 0:
                self.sharedData.scvMineralGroup = self.resourceMngrSubAgent.GetMineralGroup()
                return actions.FunctionCall(SC2_Actions.SELECT_CONTROL_GROUP, [SC2_Params.CONTROL_GROUP_SET, [self.sharedData.scvMineralGroup]]), False
        elif moveNum == 2:
            if SC2_Actions.HARVEST_GATHER in obs.observation['available_actions']:
                unitType = obs.observation['feature_screen'][SC2_Params.UNIT_TYPE]
                target = GatherResource(unitType, SC2_Params.NEUTRAL_MINERAL_FIELD)
                if target[0] >= 0:
                    return actions.FunctionCall(SC2_Actions.HARVEST_GATHER, [SC2_Params.QUEUED, SwapPnt(target)]), True

        return SC2_Actions.DO_NOTHING_SC2_ACTION, True