Esempio n. 1
0
    def gen_goals(self, verbose):
        if self.readSocket:
            data = self.readSocket.recv(size)
            if verbose >= 2:
                print("This was given by Meta-AQUA: ", data)

            pos1 = data.find("(BURNING (DOMAIN (VALUE ")
            pos2 = data.find("CONTROLS")
            if pos1 != -1:
                blockname = data[pos1 + 24:pos1 + 26]
                if verbose >= 2:
                    print("The block to extinguish is: " + blockname)
                block = None
                for b in blockset:
                    if b.id == blockname:
                        block = b
                        break

                if block:
                    return Goal(Goal.GOAL_NO_FIRE, [block])
                else:
                    print("No such block!!!")
            elif pos2 != -1:
                return Goal(Goal.GOAL_APPREHEND, ["Gui Montag"])
        else:
            print("No socket open to read Meta-AQUA data from.")
Esempio n. 2
0
	def predef_goals(self, world, iterations = 500):
		for object in world.objects:
			if world.is_true("on-table", [object]) and world.is_true("clear", [object]):
				C = Block(Block.SQUARE, object)
			elif world.is_true("on-table", [object]):
				A = Block(Block.SQUARE, object)
			elif world.is_true("clear", [object]):
				D = Block(Block.TRIANGLE, object)
			elif not world.is_true("table", [object]) and world.is_true("block", [object]):
				B = Block(Block.SQUARE, object)

		return [Goal(Goal.GOAL_ON, [C, B]), Goal(Goal.GOAL_ON, [D, C]), Goal(Goal.GOAL_ON, [D, B])] * iterations
Esempio n. 3
0
    def gen_goals(self, verbose):
        self.counter += 1
        if self.counter <= 1:
            return []

        world = self.mem.get(self.memKeys.MEM_STATES)[-1]
        blockset = blockstate.get_block_list(world)
        s = self.mem.get(self.memKeys.SOCKET_R)

        if verbose >= 2:
            print("In gengoal_fire.py")

        if s:
            text = s.recv(self.bufferSize)

            with open(self.logfile, 'a') as f:
                f.write(text)
                f.write("\n%s\n" % ("*" * 75))

            if text != "None\n":
                if verbose >= 2:
                    print("HERE IS TEXT: " + text)

                # parse text
                p = Parser()
                frames = p.makeframegraph(text)

                # create mapping
                noem = {}  # Node Operator Effect Mapping
                # Keys are node/frame names, values are lists of [operatorname, effect] pairs

                noem['CRIMINAL-VOLITIONAL-AGENT.4697'] = [[
                    'apprehend', OPERATOR_EFFECT_NEGATION
                ]]

                # Traverse
                t = Traverser(frames, noem)
                (frame, operator, effect) = t.traverse()

                if operator == "apprehend":
                    return Goal(Goal.GOAL_APPREHEND, ["Gui Montag"])
                else:
                    print("Unrecognized operator(!): " + str(operator) +
                          ", now producing standard extinguish goal.")
                    for block in blockset:
                        if block.onfire:
                            return Goal(Goal.GOAL_NO_FIRE, [block])
Esempio n. 4
0
 def gen_goals(self, verbose):
     arsonist = self.free_arsonist()
     anomalous = self.mem.get(self.memKeys.MEM_ANOM)
     anomalous = anomalous and anomalous[-1]
     if arsonist and anomalous:
         goal = Goal(Goal.GOAL_APPREHEND, [arsonist])
         goal.priority = 2  #highest used
         return [goal]
     return []
Esempio n. 5
0
 def gen_goals(self, verbose):
     world = self.mem.get(self.memKeys.MEM_STATES)[-1]
     block = self.random_fired_block(world)
     if not block:
         return []
     blocks = blockstate.get_block_list(world)
     for realblock in blocks:
         if realblock.id == block.name:
             block = realblock
             break
     goal = Goal(Goal.GOAL_NO_FIRE, [block])
     goal.priority = 1  #higher than stacking
     return [goal]
Esempio n. 6
0
def gen_world(num_players):
    w = World()
    enemies = random.choice(possible_enemies, num_players, replace=False)
    gls = draw_n_goals(num_players, types, enemies)
    for i in range(num_players):
        p = Player(i)
        p.name = enemies[i]
        p.strategy = random.choice(strategies)

        random.shuffle(gls)
        g = gls.pop()
        # Checking if destroy is not self-inflicted.
        if g.enemy != p.name:
            p.goal = g
        else:
            p.goal = Goal(random.choice(['territory18', 'territory24']))
        w.players.append(p)
    return w