def test_dijkstra(self):
     """Test dijkstras."""
     grid = Grid(5)
     grid.create_grid()
     hexagon = Hex(-1, 1, 0)
     grid.get_hextile((0, 0, 0)).terrain = Terrain(TerrainType.MOUNTAIN,
                                                   BiomeType.GRASSLAND)
     grid.get_hextile((0, 1, -1)).terrain = Terrain(TerrainType.MOUNTAIN,
                                                    BiomeType.GRASSLAND)
     grid.get_hextile((-1, 0, 1)).terrain = Terrain(TerrainType.MOUNTAIN,
                                                    BiomeType.GRASSLAND)
     result = [
         Hex(-1, 1, 0),
         Hex(-1, 2, -1),
         Hex(-2, 2, 0),
         Hex(-2, 1, 1),
         Hex(0, 2, -2),
         Hex(2, 0, -2),
         Hex(2, -1, -1),
         Hex(-2, 0, 2),
         Hex(2, -2, 0),
         Hex(1, -2, 1),
         Hex(0, -2, 2)
     ]
     dijkstra = [x for x in grid.dijkstra(hexagon, 2)]
     result = set(result).difference(dijkstra)
     self.assertEqual(set(), result)
 def test_subtracting_hex_from_hex(self):
     """Test subtracting hexs."""
     grid = Grid(5)
     grid.create_grid()
     hex_a = grid.get_hextile((1, 0, -1))
     hex_b = grid.get_hextile((-1, 2, -1))
     hex_result = Hex(2, -2, 0)
     self.assertEqual(grid.sub_coords(hex_a, hex_b), hex_result)
 def test_adding_hex_to_hex(self):
     """Test adding hexs."""
     grid = Grid(5)
     grid.create_grid()
     hex_a = grid.get_hextile((1, 0, -1))
     hex_b = grid.get_hextile((-1, 2, -1))
     hex_result = Hex(0, 2, -2)
     self.assertEqual(grid.add_coords(hex_a, hex_b), hex_result)
Esempio n. 4
0
def main():
    """Test functionality."""
    grid = Grid(9)
    hexagon = grid.get_hextile((0, 1, -1))
    print(hexagon)
    pointy = Layout((10, 10), (200, 200))
    cursor = pointy.hex_to_pixel(hexagon)
    print(cursor)
    print()
    ph = pointy.pixel_to_hex(cursor)
    result_tile = grid.hex_round((ph.x, ph.y, ph.z))
    r = grid.get_hextile(result_tile)
    print(r)
 def test_shortest_path(self):
     """Test shortest path."""
     grid = Grid(5)
     grid.create_grid()
     start = Hex(-1, 1, 0)
     end = Hex(1, -1, 0)
     grid.get_hextile((0, 0, 0)).terrain = Terrain(TerrainType.MOUNTAIN,
                                                   BiomeType.GRASSLAND)
     grid.get_hextile((0, 1, -1)).terrain = Terrain(TerrainType.MOUNTAIN,
                                                    BiomeType.GRASSLAND)
     grid.get_hextile((-1, 0, 1)).terrain = Terrain(TerrainType.MOUNTAIN,
                                                    BiomeType.GRASSLAND)
     result = [Hex(-1, 2, -1), Hex(2, -2, 0), Hex(1, -1, 0)]
     self.assertEqual(grid.shortest_path(start, end, 3), result)
 def test_rotate_left_of_hex(self):
     """Test rotate left."""
     grid = Grid(5)
     grid.create_grid()
     hex_a = grid.get_hextile((1, 0, -1))
     hex_result = Hex(1, -1, 0)
     self.assertEqual(grid.rotate_left(hex_a), hex_result)
 def test_getting_neighbour_of_hex_in_direction(self):
     """Test get neighbour in direction."""
     grid = Grid(5)
     grid.create_grid()
     hex_a = grid.get_hextile((1, -1, 0))
     hex_result = Hex(2, -1, -1)
     self.assertEqual(grid.get_neighbour_in_direction(hex_a, 1), hex_result)
 def test_scaling_of_hex(self):
     """Test hex scaling."""
     grid = Grid(5)
     grid.create_grid()
     hex_a = grid.get_hextile((0, 1, -1))
     hex_result = Hex(0, 2, -2)
     self.assertEqual(grid.scale(hex_a, 2), hex_result)
 def test_distance_between_hexes(self):
     """Test distance between hexs."""
     grid = Grid(5)
     grid.create_grid()
     hex_a = grid.get_hextile((-2, 0, 2))
     hex_b = grid.get_hextile((2, -2, 0))
     result = 4
     self.assertEqual(grid.hex_distance(hex_a, hex_b), result)
 def test_get_diagonals_of_hex(self):
     """Test get diagonals."""
     grid = Grid(7)
     grid.create_grid()
     hex_a = grid.get_hextile((0, -1, 1))
     result = [
         Hex(2, -2, 0),
         Hex(1, 0, -1),
         Hex(-1, 1, 0),
         Hex(-2, 0, 2),
         Hex(-1, -2, 3),
         Hex(1, -3, 2)
     ]
     self.assertEqual(grid.get_diagonals(hex_a), result)
 def test_getting_neighbours_of_hex(self):
     """Test get neighbours (adjacent tiles)."""
     grid = Grid(5)
     grid.create_grid()
     hex_a = grid.get_hextile((1, -1, 0))
     result = [
         Hex(2, -2, 0),
         Hex(2, -1, -1),
         Hex(1, 0, -1),
         Hex(0, 0, 0),
         Hex(0, -1, 1),
         Hex(1, -2, 1)
     ]
     self.assertEqual(grid.get_all_neighbours(hex_a), result)
 def test_vision(self):
     """Test vision."""
     grid = Grid(5)
     grid.create_grid()
     hexagon = Hex(-2, 2, 0)
     grid.get_hextile((-1, 1, 0)).terrain = Terrain(TerrainType.MOUNTAIN,
                                                    BiomeType.GRASSLAND)
     result = [
         Hex(-1, 1, 0),
         Hex(0, 2, -2),
         Hex(-2, 0, 2),
         Hex(-2, 1, 1),
         Hex(-2, 2, 0),
         Hex(-1, 0, 1),
         Hex(-1, 2, -1),
         Hex(0, 1, -1)
     ]
     self.assertEqual(set(grid.vision(hexagon, 2)), set(result))