The boundary can be implied. This means there are only 15 columns of
vertical walls and 15 rows of horizontal walls. Each column or row has
16 partitions. The total number of bytes required is
, or 60 bytes.
Once again, you can linearize the walls. However, the linearization
now relies on which direction you want to look from a cell. For
example, the east wall of a cell at row
and column
has a
linear index of
in the vertical partition array.
The west wall of the same cell has a
linear index of
in the vertical partition array.
The north wall of the same cell has a
linear index of
in the horizontal partition array.
The south wall of the same cell has a
linear index of
in the horizontal partition array.
For efficiency, you can directly compute the byte number as 2*c + r/8 for the east partition of a cell, and use r % 8 to compute the bit number in that byte. Recall that most compilers are smart enough to use shifts (instead of multiply and divide) and bitwise and (instead of modulus).
The boundary partitions are special cases because they are always there. For example, all cells on column 0 have west partitions. If you use the previous equation to computer the linearized bit number of the west wall of a column zero cell, it yields a negative number.
It is best to write some subroutines to abstract the handling of partitions. In particular, you can define two subroutines:
Once you have these two functions, you can implement the logic to find reachable neighbors of a cell by checking which direction(s) does/do not have a parition blocking.