Model the Square
00:14 The square should also have a border pattern that describes the maze structure at that location. Depending on the purpose of the square, it may option optionally play a special role—for example, indicating the maze entrance.
01:26 Note that in addition to storing the square’s row and column indices, you also keep track of its one-dimensional index within a flat sequence of squares. This way, the search algorithm can uniquely identify the squares.
A little redundancy can sometimes keep data encapsulated. When creating your
Square instance, you must specify its index, row, column, and border pattern, but the role is completely optional. If you skip the role in the initializer, then the square will assume
Role.NONE by default.
Become a Member to join the conversation.