Skip to main content
Bounty Awarded with 50 reputation awarded by bux
added 517 characters in body
Source Link

I assume you are storing map information in some kind of 2D array or something similar where you can easily check neighboring tile information. Any border tile will be missing at least 1 neighbor. You can then tell what direction based on which neighbors are missing, for example if you are missing neighbor tiles to the south and west you know it is the south-west border. If you are missing a neighbor to the north only then it is the north border, etc. This should work for an octagon no matter what size. Hope this helps.

Edit: The corner tiles between directions may require special edge case logic because you could classify them in two directions potentially (as pointed out by Zibelas below). Depends on how you would classify those, but you can see any corner tile always has two missing neighbors. So any tile with two missing neighbors you should check to see if it has a neighboring border tile and if so use that tile's direction instead.

Also when I say neighbor, I mean only to the west/east/north/south, not diagonally.

I assume you are storing map information in some kind of 2D array or something similar where you can easily check neighboring tile information. Any border tile will be missing at least 1 neighbor. You can then tell what direction based on which neighbors are missing, for example if you are missing neighbor tiles to the south and west you know it is the south-west border. If you are missing a neighbor to the north only then it is the north border, etc. This should work for an octagon no matter what size. Hope this helps.

I assume you are storing map information in some kind of 2D array or something similar where you can easily check neighboring tile information. Any border tile will be missing at least 1 neighbor. You can then tell what direction based on which neighbors are missing, for example if you are missing neighbor tiles to the south and west you know it is the south-west border. If you are missing a neighbor to the north only then it is the north border, etc. This should work for an octagon no matter what size. Hope this helps.

Edit: The corner tiles between directions may require special edge case logic because you could classify them in two directions potentially (as pointed out by Zibelas below). Depends on how you would classify those, but you can see any corner tile always has two missing neighbors. So any tile with two missing neighbors you should check to see if it has a neighboring border tile and if so use that tile's direction instead.

Also when I say neighbor, I mean only to the west/east/north/south, not diagonally.

Source Link

I assume you are storing map information in some kind of 2D array or something similar where you can easily check neighboring tile information. Any border tile will be missing at least 1 neighbor. You can then tell what direction based on which neighbors are missing, for example if you are missing neighbor tiles to the south and west you know it is the south-west border. If you are missing a neighbor to the north only then it is the north border, etc. This should work for an octagon no matter what size. Hope this helps.