コード例 #1
0
 def __init__(self, axial_coordinates, color, radius, hollow = False):
     self.axial_coordinates = np.array([axial_coordinates])
     self.cube_coordinates = hx.axial_to_cube(self.axial_coordinates)
     self.position = hx.axial_to_pixel(self.axial_coordinates, radius)
     self.color = color
     self.radius = radius
     self.image = make_hex_surface(color, radius, hollow = hollow)
コード例 #2
0
 def __init__(self, axial_coordinates, radius, tile_id):
     super(HexTile, self).__init__()
     self.axial_coordinates = np.array([axial_coordinates])
     self.cube_coordinates = hx.axial_to_cube(self.axial_coordinates)
     self.position = hx.axial_to_pixel(self.axial_coordinates, radius)
     self.radius = radius
     self.tile_id = tile_id
コード例 #3
0
ファイル: test_conversions.py プロジェクト: RedFT/Hexy
def test_cube_to_pixel_conversion():
    axial_coords = hx.cube_to_axial(coords)
    cube_coords = hx.axial_to_cube(axial_coords)
    pixel_coords = hx.cube_to_pixel(cube_coords, radius)
    pixel_to_cube_coords = hx.pixel_to_cube(pixel_coords, radius)
    pixel_to_cube_to_axial_coords = hx.cube_to_axial(pixel_to_cube_coords)

    assert np.array_equal(cube_coords, pixel_to_cube_coords)
コード例 #4
0
ファイル: selection_tile.py プロジェクト: RedFT/HexTiler
 def __init__(self, axial_coordinates, border_color, radius):
     self.axial_coordinates = np.array([axial_coordinates])
     self.cube_coordinates = hx.axial_to_cube(self.axial_coordinates)
     self.position = hx.axial_to_pixel(self.axial_coordinates, radius)
     self.color = border_color
     self.radius = radius
     self.image = make_hex_surface((0, 0, 0, 140),
                                   self.radius,
                                   self.color,
                                   hollow=True)
コード例 #5
0
    def get_valid_moves(self, hex):
        dist = hex.piece.movement_d
        center = hex.get_axial_coords()

        moves = []
        frontier = Queue()

        Directions = np.array(["NW", "NE", "SE", "SW", "E", "W"])

        move = np.array([center[0], center[1], 0, hex.piece.direction],
                        dtype=object)
        frontier.put(move)

        while not frontier.empty():
            current = frontier.get()

            r = current[0]
            q = current[1]
            cost = current[2]
            direction = current[3]

            found = False
            for i in moves[::-1]:
                if np.array_equal(current[0:2], i[0:2]) and current[3] == i[3]:
                    if current[2] < i[2]:
                        del i
                    else:
                        found = True
                        break

            if found:
                continue

            for dir in Directions:
                move_cost = cost + v2_angle(eval(direction), eval(dir))
                if move_cost <= dist:
                    move = np.array([r, q, move_cost, dir], dtype=object)
                    moves.append(move)

                    cube_current = hx.axial_to_cube(np.array([current[0:2]]))
                    neighbor = (cube_current + eval(dir))[0]

                    if move_cost + 1 <= dist:
                        neighbor_move = np.array(
                            [neighbor[0], neighbor[2], move_cost + 1, dir],
                            dtype=object)

                        if (np.array_equal(self[neighbor_move[0:2]], []) or
                                self[neighbor_move[0:2]][0].piece.player != 0):
                            continue
                        frontier.put(neighbor_move)

        moves = np.array(moves, dtype=object)
        return moves
コード例 #6
0
ファイル: test_conversions.py プロジェクト: RedFT/Hexy
def test_the_converted_coords_and_dataset_coords_retrieve_the_same_data():
    axial_coords = hx.cube_to_axial(coords)
    cube_coords = hx.axial_to_cube(axial_coords)
    pixel_coords = hx.cube_to_pixel(cube_coords, radius)
    pixel_to_cube_coords = hx.pixel_to_cube(pixel_coords, radius)
    pixel_to_cube_to_axial_coords = hx.cube_to_axial(pixel_to_cube_coords)

    # check that we can correctly retrieve hexes after conversions
    hm[axial_coords] = coords
    retrieved = hm[pixel_to_cube_to_axial_coords]

    assert np.array_equal(retrieved, coords)
コード例 #7
0
    def get_valid_attacks(self, hex):
        center = hex.get_axial_coords()
        center_direction = eval(hex.piece.direction)
        center_start = np.array([center[0], center[1], 0])
        moves = np.array([center_start])

        frontier = Queue()
        frontier.put(center_start)

        Directions = np.array(["NW", "NE", "SE", "SW", "E", "W"])

        while not frontier.empty():
            current = frontier.get()

            if current[2] > hex.piece.attack_d:
                continue

            cube_current = hx.axial_to_cube(np.array([current[0:2]]))
            neighbors = np.array([
                hx.get_neighbor(cube_current, hx.NW),
                hx.get_neighbor(cube_current, hx.NE),
                hx.get_neighbor(cube_current, hx.SE),
                hx.get_neighbor(cube_current, hx.SW),
                hx.get_neighbor(cube_current, hx.E),
                hx.get_neighbor(cube_current, hx.W)
            ])

            index = 0
            for next_nb in neighbors:
                direction_cube = eval("hx." + Directions[index])
                index += 1
                found = False

                for i in moves[::-1]:
                    if np.array_equal(next_nb[0][::2], i[0:2]):
                        found = True
                        break

                if found:
                    continue
                else:
                    if current[2] + 1 + v2_angle(
                            center_direction,
                            direction_cube) <= hex.piece.attack_d:
                        new_move = np.array([
                            next_nb[0][0], next_nb[0][2], current[2] + 1 +
                            v2_angle(center_direction, direction_cube)
                        ])
                        moves = np.vstack([moves, new_move])
                        frontier.put(new_move)

        return moves
コード例 #8
0
ファイル: test_conversions.py プロジェクト: RedFT/Hexy
def test_axial_to_cube_conversion():
    axial_coords = hx.cube_to_axial(coords)
    cube_coords = hx.axial_to_cube(axial_coords)

    assert np.array_equal(coords, cube_coords)
コード例 #9
0
hm = hx.HexMap()


def same_mat(A, B):
    if np.unique(A == B) == [True]:
        return True
    return False


radius = 10
coords = hx.get_spiral(np.array((0, 0, 0)), 1, 10)

# check axial <-> cube conversions work
axial_coords = hx.cube_to_axial(coords)
cube_coords = hx.axial_to_cube(axial_coords)

print same_mat(coords, cube_coords)

# check axial <-> pixel conversions work
pixel_coords = hx.axial_to_pixel(axial_coords, radius)
pixel_to_axial_coords = hx.pixel_to_axial(pixel_coords, radius)

print same_mat(axial_coords, pixel_to_axial_coords)

# check cube <-> pixel conversions work
pixel_coords = hx.cube_to_pixel(cube_coords, radius)
pixel_to_cube_coords = hx.pixel_to_cube(pixel_coords, radius)
pixel_to_cube_to_axial_coords = hx.cube_to_axial(pixel_to_cube_coords)

print same_mat(cube_coords, pixel_to_cube_coords)