Debian Codegraph @

DESIGN

raw
1
2 Triangular board representation
3 -------------------------------
4
5 Store as an W*H array, where each position represents a vertex on the board's
6 triangular divisions. The odd-numbered rows are shifted half a position to the
7 right of the even-numbered rows, and the rows are spaced so that the resulting
8 vertex positions actually form equilateral triangles.
9
10 Under this arrangement, given a point (x,y) in the array, the actual location
11 of the vertex is (x + (y%2)/2, y). To avoid confusion, we call the former
12 "board coordinates" and the latter "actual coordinates".
13
14 In board coordinates, the neighbours of any given point (x,y) are:
15
16 For even y: (x-1, y-1), (x, y-1)
17 (x-1, y), (x+1, y)
18 (x-1, y+1), (x, y+1)
19
20 For odd y: (x, y-1), (x+1, y-1)
21 (x-1, y), (x+1, y)
22 (x, y+1), (x+1, y+1)
23
24 The difference matrix between these two cases is:
25 [ (1,0) (1,0) ]
26 DM = [ (0,0) (0,0) ]
27 [ (1,0) (1,0) ]
28
29 I.e., for even y, we use the formulae given above, for odd y, we add DM to
30 the formulae for even y.
31
32 On every vertex in the board, there are 6 cardinal directions, corresponding
33 to the 6 vertices surrounding it. For convenience, we number them clockwise
34 starting from the vertex to the upper left. Each cardinal direction
35 corresponds, obviously, to each of the 6 neighbouring vertices described above.
36
37