def test_report_needs_input_date_and_pk(self): g = Goal() g.input = 'Ok' g.get_pk = lambda: 'pk' r = g.get_report() self.assertIsInstance(r, Record) self.assertEqual(r.date, g.input_date)
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.")
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 []
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
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]
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])
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
def test_goal_invalid_input_raises_exception(self): g = Goal() g.verify_input = mock.Mock(return_value=False) self.assertRaises(BadInput, g.set_input, 'kokok')
def test_goal_set_input_calls_verify_input(self): g = Goal() g.verify_input = mock.Mock(return_value=True) g.set_input('kekeke') g.verify_input.assert_called_once_with('kekeke') self.assertEqual(g.input, 'kekeke')
def test_goal_can_verify_input(self): g = Goal() g.verify_input = lambda x: bool(x) self.assertTrue(g.verify_input('koko'))
def test_report_creating_needs_pk(self): g = Goal() g.input = 'Ok' self.assertRaises(NotImplementedError, g.get_report)
def test_connector_preload_calls_execute(self): g = Goal('Kokoko?') g.get_pk = lambda: 'kokoko' with mock.patch('goals.Connector.executemany', mock.Mock()) as p: Connector(goals=[g]) self.assertEqual(len(p.call_args), 2)