Esempio n. 1
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);
    }