def test_01_instantiate_sim(self):

        # make 3 agents
        a1 = mod_agt.Agent(name='a1', fldr=os.getcwd())
        a2 = mod_agt.Agent(name='a2', fldr=os.getcwd())
        a3 = mod_agt.Agent(name='a3', fldr=os.getcwd())
        # create 3 characters from the Character generator and assign to agents
        traits = character.CharacterCollection(ref_folder)
        a1.characteristics = traits.generate_random_character()
        a2.characteristics = traits.generate_random_character()
        a3.characteristics = traits.generate_random_character()

        world = planet.Planet('SimWorld',
                              num_seeds=5,
                              width=20,
                              height=15,
                              wind=0.3,
                              rain=0.10,
                              sun=0.3,
                              lava=0.4)
        actions = ['walk', 'run', 'fight', 'buy', 'sell', 'collect']
        s = simulator.SimAdventureGame('Test of SimWorld', world, [a1, a2, a3],
                                       actions)
        s.run()
        self.assertEqual(len(str(s)), 354)
 def __init__(self):
     p = planet.Planet('SimpleAIWorld', 5, 20, 10, 0.2, 0.2, 0.2, 0.5)
     traits = character.CharacterCollection(os.getcwd() + os.sep + 'data')
     #self.a1 = traits.generate_random_character()
     self.a1 = agt.Agent('Jack')
     self.a2 = agt.Agent('Jill')
     #print('type(self.a1) = ', type(self.a1))
     actions = ['walk', 'fight']
     self.s = simulator.Simulator('Test of SimWorld', p, [self.a1, self.a2], actions)
     self.s.run()  # with no params, it defaults to turn based mode
    def test_02_move_character(self):
        """
        add a single character to a world and move them around
        """
        traits = character.CharacterCollection(ref_folder)
        a1 = mod_agt.Agent(name='a2', fldr=os.getcwd())
        a1.characteristics = traits.generate_random_character()
        world = planet.Planet('SimWorld',
                              num_seeds=5,
                              width=70,
                              height=10,
                              wind=0.3,
                              rain=0.10,
                              sun=0.3,
                              lava=0.4)
        #world.build_random( 2, 30, 40, 1)

        actions = ['walk']
        s = simulator.SimAdventureGame('Test of SimWorld', world, [a1],
                                       actions)
        s.run()
        self.assertEqual(len(str(s)), 184)

        s.command({'name': 'walk', 'type': 'move', 'direction': [1, 1]}, a1)
        s.command({'name': 'run', 'type': 'run', 'direction': [2, 1]}, a1)
        s.command({'name': 'fight', 'type': 'fight', 'direction': [2, 1]}, a1)
    def test_11_game_of_life(self):
        traits = character.CharacterCollection(ref_folder)
        a1 = mod_agt.Agent(name='Life', fldr=os.getcwd())
        a1.characteristics = traits.generate_random_character(
        )  # No, this should not be a adventure character
        world = planet.Planet('SimWorld',
                              num_seeds=5,
                              width=20,
                              height=15,
                              wind=0.3,
                              rain=0.10,
                              sun=0.3,
                              lava=0.4)
        actions = ['walk']
        s = simulator.SimAdventureGame('Test of Game of Life', world, [a1],
                                       actions)

        s.run()
        #print(s)

        self.assertTrue(len(str(s)) > 10)

        tst_world, tst_status, tst_log = s.get_state()
        print('game of life state tst_world= ', tst_world)
        print('game of life state tst_status= ', tst_status)
        print('game of life state tst_log= ', tst_log)
        self.assertTrue(len(str(tst_world)) > 10)
        self.assertEqual(tst_status, 'Waiting for Command')
        self.assertEqual(tst_log, [])
Beispiel #5
0
def TEST():
    agt = mod_agt.Agent('Testing Map Agent')
    print(agt)
    test_file = root_fldr + os.sep + 'aikif' + os.sep + 'agents' + os.sep + 'test_map.csv'
    mapping = {
        'name': 'recipes',
        'col_list': ['ingredient', 'quant', 'calories'],
        'ingredient': '',
        'quant': '',
        'calories': ''
    }
    map_agt = AgentMapDataFile('recipes', test_file, mapping)
    print(map_agt)
    def test_04_verify_agents(self):
        """
        check that a failed verify agent works
        simulator.Simulator('BadSim', name, world, agents, agent_locations, actions)
        """
        world = worlds.World(40, 20, ['.', 'X', '#'])
        world.build_random(8, 40, 70, 30)
        agt1 = mod_agt.Agent(name='agt_9001', fldr=os.getcwd())
        agt2 = mod_agt.Agent(name='agt_9002', fldr=os.getcwd())
        agents = [agt1, agt2]

        agt1.set_coords({'x': 2, 'y': 1, 'z': 0, 't': 0})
        agt2.set_coords({'x': 3, 'y': 4, 'z': 0, 't': 0})

        actions = ['walk']

        s04 = simulator.Simulator('sim04', world, agents, actions)
        self.assertTrue(s04._verify_agents())

        # now add a duplicate agent name
        agents.append(agt1)
        #print('DUPLICATE AGENT LIST = ', [str(a) for a in agents])
        self.assertFalse(s04._verify_agents())
 def test_21_sim_adventure_game(self):
     traits = character.CharacterCollection(ref_folder)
     a21 = mod_agt.Agent(name='a1', fldr=os.getcwd())
     a21.characteristics = traits.generate_random_character()
     world = planet.Planet('SimWorld',
                           num_seeds=5,
                           width=20,
                           height=15,
                           wind=0.3,
                           rain=0.10,
                           sun=0.3,
                           lava=0.4)
     actions = ['walk']
     s = simulator.SimAdventureGame('Test of SimAdventureGame', world,
                                    [a21], actions)
     s.run()
     print(s)
     self.assertEqual(len(str(s)), 192)