Esempio n. 1
0
 def _create_full_cell(self):
     cell = Cell(Serialiser('location'), False, True)
     cell.avatar = Serialiser('avatar')
     cell.pickup = Serialiser('pickup')
     self.expected = {
         'avatar': 'avatar',
         'generates_score': True,
         'habitable': False,
         'location': 'location',
         'pickup': 'pickup',
         'partially_fogged': False
     }
     return cell
Esempio n. 2
0
def generate_map(height, width, obstacle_ratio):
    grid = [[Cell(Location(x, y)) for y in range(height)] for x in range(width)]
    world_map = WorldMap(grid)

    # We designate one non-corner edge cell as empty, to ensure that the map can be expanded
    always_empty_edge_x, always_empty_edge_y = get_random_edge_index(height, width)

    for x, y in shuffled(_get_edge_coordinates(height, width)):
        if (x, y) != (always_empty_edge_x, always_empty_edge_y) and random.random() < obstacle_ratio:
            cell = grid[x][y]
            cell.habitable = False
            #   So long as all habitable neighbours can still reach each other, then the map cannot get bisected
            if not _all_habitable_neighbours_can_reach_each_other(cell, world_map):
                cell.habitable = True

    return world_map
Esempio n. 3
0
 def get_cell(self, location):
     if location not in self._cell_cache:
         cell = Cell(location)
         cell.avatar = self._avatar
         self._cell_cache[location] = cell
     return self._cell_cache[location]
Esempio n. 4
0
 def get_cell(self, location):
     cell = Cell(location)
     cell.pickup = self._pickup
     return cell
Esempio n. 5
0
 def test_not_equal(self):
     cell1 = Cell(1)
     cell2 = Cell(2)
     self.assertNotEqual(cell1, cell2)
Esempio n. 6
0
 def test_equal(self):
     cell1 = Cell(1)
     cell2 = Cell(1)
     self.assertEqual(cell1, cell2)
Esempio n. 7
0
 def get_cell(self, location):
     if location not in self._cell_cache:
         cell = Cell(location)
         cell.avatar = self._avatar
         self._cell_cache[location] = cell
     return self._cell_cache[location]
Esempio n. 8
0
 def get_cell(self, location):
     default_cell = Cell(location, generates_score=(location.x % 2 == 1))
     return self._cell_cache.setdefault(location, default_cell)
Esempio n. 9
0
 def get_cell(self, location):
     return Cell(location)
Esempio n. 10
0
 def get_cell(self, location):
     return self._cell_cache.setdefault(location, Cell(location))
Esempio n. 11
0
 def get_cell(self, location):
     cell = Cell(location)
     cell.pickup = self._pickup
     return cell