Defining a number of small 2D char arrays
In libchthon, class
Map<T> is able to store 2D arrays of any type. Usually when it comes to testing maps (like FOV, rays, pathfinding) the simplest way to define such map is using strings:
But when there are a few maps like that, they’re consuming code lines. In the meantime, there are plenty of room just to the right of the map. Why not to use this space like that:
Folded up the strings are arranged alternately:
1, 2, 3, 1, 2, 3, 1, 2, 3, ... That is, strings that defines specified map are located at each
COUNT position stared from some index.
As I need the result as a string (or, rather, as an iterator pair, to save memory and time), I’ve found following algorithm:
- Create and iterator and point it at the start of the first line in the specified map (for second map it would be string with index 1).
- Forward it till the end of the current string.
- Find out next string (it would be in the
- If current position is on the last row (i.e. there is no next string), then point iterator at the end of the current (i.e. last) string. It’ll be an exact position of the iterator which should be returned from the
Incrementing operator of iterator, designed for such walkthrough: