コード例 #1
0
    private void doWork(Work nextAiWork)
    {
        //Debug.Log("Updating ai resource display");
        //foreach (ResourceType rt in aiCurrentGameState.getAllResourceTypes())
        //{
        //    Debug.Log("RT: " + rt + ", " + aiCurrentGameState.getStockpile(rt));
        //    aiResourceDisplay.updateCountAndRPT(rt, aiCurrentGameState.getStockpile(rt), aiCurrentGameState.getChangePerTick(rt));
        //}
        Debug.Log("Doing work: " + nextAiWork.workType);
        switch (nextAiWork.workType)
        {
        case EWork.BuildBuilding:
            startBuildBuilding(BuildingFactory.buildNew(nextAiWork.buildingType, -1, -1), nextAiWork.frameWait);
            break;

        case EWork.BuyAndAssignWorker:
            Debug.Log("Worker for: " + nextAiWork.buildingType);
            if (aiCurrentGameState.canBuyWorker())
            {
                Debug.Log("can buy worker");
                aiCurrentGameState.buyAndAssignWorker(nextAiWork.buildingType);
                aiResourceDisplay.workerAssigned();
                aiResourceDisplay.addTotalWorker();

                switch (nextAiWork.buildingType)
                {
                case BuildingType.Bank:
                    bank++;
                    break;

                case BuildingType.SilverMine:
                    silver++;
                    break;

                case BuildingType.StoneMason:
                    stone++;
                    break;

                case BuildingType.WoodCutter:
                    wood++;
                    break;
                }
            }
            else
            {
                Debug.Log("cannot buy worker");
            }
            doNextWorkAi();
            break;

        case EWork.Wait:
            StartCoroutine(aiWait(nextAiWork.frameWait));
            break;

        default:
            doNextWorkAi();
            break;
        }
    }
コード例 #2
0
    public static HashSet <QGameState> getNeighbors(QGameState qEntry)
    {
        // For a given game state return all valid edges out of it

        HashSet <QGameState> result = new HashSet <QGameState>();
        BuildingGS           gs     = qEntry.gameState;

        // Branches related to workers
        if (gs.canBuyWorker())
        {
            // If we have the resources to build a new worker
            foreach (BuildingType bt in gs.getOpenSlots())
            {
                // One branch for every possible type of worker slot we can fill
                QGameState neighbor = QGameStateFactory.buyWorker(qEntry, bt);
                result.Add(neighbor);
            }
        }

        // The length of all the no-op edges we want to consider
        HashSet <int> waitTimes = new HashSet <int>()
        {
            10
        };

        // Branches related to Buildings
        // TODO: Why build a building if we can't populate it with a worker?
        foreach (BuildingType bt in BuildingFactory.allBuildings)
        {
            // One branch for every new possible building
            IBuilding possibleBuilding = BuildingFactory.buildNew(bt, -1, -1); // TODO: do we care about pos when doing A*?
            if (gs.canBuyBuilding(possibleBuilding))
            {
                // If we can build this building, then add a branch
                QGameState neighbor = QGameStateFactory.buyBuilding(qEntry, possibleBuilding);
                result.Add(neighbor);
            }
        }

        // Add in some no-op edges
        foreach (int waitTime in waitTimes)
        {
            result.Add(QGameStateFactory.waitTransition(qEntry, waitTime));
        }

        return(result);
    }
コード例 #3
0
 public bool canBuyWorker()
 {
     return(gameState.canBuyWorker());
 }