Exemplo n.º 1
0
def main(argv):

    try:
        opts, _ = getopt.getopt(argv, "f:")
    except getopt.GetoptError:
        print('zombie_runner.py -i <name.json>')
        print('or no arguments to use input.json file name')
        print('zombie_runner.py ')
        sys.exit(2)

    input_file = opts[0][1] if len(opts) else 'input.json'

    try:
        z_config = Config.load_from_file(input_file)
    except IncorrectConfig as ice:
        print('Incorrect configuration detected.', ice)
        exit(2)
    except Exception as e:
        print('encountered and error while loading/analysing config.', e)
        exit(2)

    zombie_land = ZombieLand(z_config)
    score, positions = zombie_land.release_the_zombie()

    print('zombies score:', score)
    print('zombies positions:\n', positions)
Exemplo n.º 2
0
    def test_simple_3x3_grid_2_creatures_in_same_cell(self):
        # assert cascade infection
        config = {
            'size': 3,
            'zombie_start': (0, 0),
            'creatures': [(1, 1), (1, 1), (1, 0)],
            'moves': 'RD',
        }

        z_config = Config(config)
        zombie_land = ZombieLand(z_config)
        score, positions = zombie_land.release_the_zombie()
        self.assertEqual(score, 3)
        self.assertEqual(positions, [(1, 1), (2, 1), (2, 2)])
Exemplo n.º 3
0
    def test_simple_2x2_grid_1_creature_will_meet(self):
        # assert simple move and meeting creature
        config = {
            'size': 2,
            'zombie_start': (0, 0),
            'creatures': [(1, 0)],
            'moves': 'R',
        }

        z_config = Config(config)
        zombie_land = ZombieLand(z_config)
        score, positions = zombie_land.release_the_zombie()
        self.assertEqual(score, 1)
        self.assertEqual(positions, [(1, 0), (0, 0)])
Exemplo n.º 4
0
    def test_1x1_grid_no_creature_travel_edge(self):
        # assert edge traveling
        config = {
            'size': 1,
            'zombie_start': (0, 0),
            'creatures': [],
            'moves': 'DD',
        }

        z_config = Config(config)
        zombie_land = ZombieLand(z_config)
        score, positions = zombie_land.release_the_zombie()
        self.assertEqual(score, 0)
        self.assertEqual(positions, [(0, 0)])
Exemplo n.º 5
0
    def test_simple_2x2_grid_zombie_creature(self):
        # assert not meeting creatures
        config = {
            'size': 2,
            'zombie_start': (0, 0),
            'creatures': [(0, 0)],
            'moves': 'D',
        }

        z_config = Config(config)
        zombie_land = ZombieLand(z_config)
        score, positions = zombie_land.release_the_zombie()
        self.assertEqual(score, 1)
        self.assertEqual(positions, [(0, 1)])
Exemplo n.º 6
0
    def test_big_grid(self):
        # lets go crazy
        config = {
            'size': 500000,
            'zombie_start': (200000, 200001),
            'creatures': [(200000, 200000)],
            'moves': 'UDUD',
        }

        z_config = Config(config)
        zombie_land = ZombieLand(z_config)
        score, positions = zombie_land.release_the_zombie()
        self.assertEqual(score, 1)
        self.assertEqual(positions, [(200000, 200000), (200000, 200001)])
Exemplo n.º 7
0
    def test_simple_5x5_grid_complex_moves(self):

        config = {
            'size': 10,
            'zombie_start': (0, 4),
            'creatures': [(9, 4)],
            'moves': 'LLUUUUU',
        }

        z_config = Config(config)
        zombie_land = ZombieLand(z_config)
        score, positions = zombie_land.release_the_zombie()
        self.assertEqual(score, 1)
        self.assertEqual(positions, [(7, 9), (8, 9)])
Exemplo n.º 8
0
    def test_simple_3x3_grid_2_creatures_cascade_multi_move(self):
        # assert multi-move and cascade effect
        config = {
            'size': 3,
            'zombie_start': (0, 0),
            'creatures': [(1, 1), (2, 1)],
            'moves': 'RDLU',
        }

        z_config = Config(config)
        zombie_land = ZombieLand(z_config)
        score, positions = zombie_land.release_the_zombie()
        self.assertEqual(score, 2)
        self.assertEqual(positions, [(1, 1), (2, 1), (0, 0)])