CubicGrid.py 1.35 KB
Newer Older
Karol Actun's avatar
Karol Actun committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from grids.Grid import Grid


class CubicGrid(Grid):

    def __init__(self, size):
        super().__init__()
        self._size = size

    @property
    def size(self):
        return self._size

    @property
    def directions(self):
        return {"LEFT": (-1, 0, 0),
                "RIGHT": (1, 0, 0),
                "UP": (0, 1, 0),
                "DOWN": (0, -1, 0),
                "FORWARD": (0, 0, 1),
                "BACK": (0, 0, -1)}

    def get_box(self, width):
        locations = []
        for x in range(int(-width / 2), int(width / 2)):
            for y in range(int(-width / 2), int(width / 2)):
                for z in range(int(-width / 2), int(width / 2)):
                    locations.append((x, y, z))
        return locations

31
32
    def are_valid_coordinates(self, coordinates):
        if coordinates[0] % 1 == 0 and coordinates[1] % 1 == 0 and coordinates[2] % 1 == 0:
Karol Actun's avatar
Karol Actun committed
33
34
35
36
            return True
        else:
            return False

37
    def get_nearest_valid_coordinates(self, coordinates):
Karol Actun's avatar
Karol Actun committed
38
39
40
41
42
43
44
45
46
47
48
49
        return (round(coordinates[0]),
                round(coordinates[1]),
                round(coordinates[2]))

    def get_dimension_count(self):
        return 3

    def get_distance(self, start, end):
        return abs(start[0] - end[0]) + abs(start[1] - end[1]) + abs(start[2] - end[2])

    def get_center(self):
        return 0, 0, 0