Hex-Grid Utilities

C# Hex-Grid utilities for Board-Game Development

A tool-kit of utilities for building board- and strategy-games on a hexagonal grid, providing these features:

- Use of Canonical coordinates (ICoordsCanon interface) for many game calculations makes them clear to understand, and often obviously correct.
- Storage of board definition optimized by use of Rectangular coordinates (ICoordsUser interface) as array indices.
- Automatic (all-integer for efficiency in nested loops) conversion between Canonical, Recangular (from upper-left), and Custom coordinates (ICoordsCustom interface) available by implementing them all in a single struct with caching and lazy evaluation.
- Hex-picking (identifying the hex selected by the user).
- Path-finding against a step-cost function on entry hex and entry hexside.
- Field-of-View determination against elevated terrain
- Mouse-wheel zoom and scroll
- Faster path-finding at long range (but loses agent orientation)
- Map transposition
  • MazeMap: MazeMapPathFInding.PNG
  • TerrainMap: TerrainMapFOV.PNG

Got questions? Please leave a comment (or start a discussion thread) and I will get back to you as quickly as I can.

Feb. 23, 2013 - V 2.0:
  1. Abstracted MapBoard and MapDisplay functionality into separate classes;
  2. Corrected PathFinder to use -1 as Impassable flag instead of 999;
  3. Added demonstration of simple map transposition to HexGridExample; and
  4. Code clean-up for better exposition of principles.

Feb. 24, 2013 - V3.0:
  1. Finally fixed that horrible ficker on Resize and Scroll;
  2. Added TerrainMap example;
  3. Added demonstration of Shadow-Casting Field-of-View on both maps; and
  4. Removed reference web pages out of source download to make it a more reasonable size.

Apr 28, 2013 - V4.0 (Breaking Change - see release notes):
  1. Faster path-finding at longer ranges (controllable range cut-over);
  2. Mouse-wheel zoom;
  3. Mouse-wheel scroll;
  4. Map transposition;
  5. Improved code readability; and
  6. Other minor enhancements that I lost track of

Reviews and Ratings

If you downloaded this library and found it useful (and even if you didn't actually; I can take brickbats as well as bouquets), please select Review This Release on the Downloads page. You will be presented with a dialog box where you can review and rate the release. Specific issues can also be reported on the Issues tab.

I appreciate all feedback, and promise to read all comments and issues.
Many thanks to Eric Lippert for inspiring the path-finding and field-of-view implementation, by providing the original algorithms on a rectangular grid.

Last edited Tue at 3:16 AM by pgeerkens, version 32