예제 #1
0
    def test_neighbors(self):
        g = Grid(hexagon_type=POINTY, coordinate_system=OFFSET_ODD_ROWS)
        g[1, 1] = 'center'
        g[1, 0] = 'adjacent 1'
        g[2, 0] = 'adjacent 2'
        g[3, 3] = 'not adjacent'

        n = g.neighbors((1, 1))
        self.assertSequenceEqual(n, ['adjacent 2', 'adjacent 1'])

        g = Grid(hexagon_type=POINTY, coordinate_system=CUBIC)
        g[0, 0, 0] = 'center'
        g[1, 0, -1] = 'adjacent 1'
        g[-1, 0, 1] = 'adjacent 2'
        g[0, 2, -2] = 'not adjacent'
        n = g.neighbors((0, 0, 0))
        self.assertSequenceEqual(n, ['adjacent 1', 'adjacent 2'])

        g = Grid()
        g[0, 0] = 'center'
        self.assertEqual([], g.neighbors((0, 0)))
예제 #2
0
    def test_ring(self):
        g = Grid(HexagonType.FLAT, CoordinateSystem.AXIAL)
        for i in range(5):
            for j in range(5):
                g[i, j] = None

        expected = [None] * 3
        self.assertCountEqual(g.ring((0, 0), 2), expected)

        expected = g.neighbors((1, 2))
        self.assertCountEqual(g.ring((1, 2), 1), expected)

        g = Grid(hexagon_type=HexagonType.FLAT,
                 coordinate_system=CoordinateSystem.CUBIC)
        for i in range(-3, 4):
            for j in range(-3, 4):
                c = Grid.convert((i, j), CoordinateSystem.AXIAL,
                                 CoordinateSystem.CUBIC)
                g[c] = None

        expected = [None] * 4
        self.assertCountEqual(g.ring((3, -6, 3), 3), expected)