예제 #1
0
    def checkIfNextStepCanBeAccomplished(self, aRecipe):
        step = aRecipe.content[0]  # next step to be done
        res = gvf.findNodesFromSector(step)

        if res != []:
            return True
        else:
            return False
예제 #2
0
    def searchForSector(self):
        if self.agType != "recipes":
            return

        if not self.canMove:
            return

        step = self.content[0]  # first step to be done

        res = gvf.findNodesFromSector(step)
        if common.verbose:
            if res == []:
                print(
                    "recipe %d cannot find a factory for the step of type %d" %
                    (self.number, step))
        else:
            if common.verbose:
                print(
                    "recipe %d found %d factory/ies for the step of type %d" %
                    (self.number, len(res), step))

        # for debug only!!!!!!!!!!!!!
        # if res!=[]:
        # for aNode in res: print "searchForSector:", aNode.number, aNode.sector
        # else: print "searchForSector: no node for sector", step

        if res != []:
            random.shuffle(res)
            if common.verbose:
                print("recipe %d moving to factory %d" %
                      (self.number, res[0].number))

                # future development: here res[0] simply contain a randomly chosen unit
                # (if in res we have more than a unique possibility)
                # it is possible to put here intelligence (as the effect of the)
                # action of the recipe, searching for data such as production costs of
                # the factories, their waiting lists, their quality standards, their
                # owners, etc.

            # create an edge from self.factoryInWhichRecipeIs to res[0]
            # or upgrading the weight of the link
            if self.factoryInWhichRecipeIs is not None:
                gvf.createEdge(self.factoryInWhichRecipeIs, res[0])
            self.factoryInWhichRecipeIs = res[0]

            # self here is the calling recipe
            res[0].addToRecipeWaitingList(self)