Battle Analysis: Hexagon Grid Calculator


The Hexagon Grid is a cartesian coordinate system is used for hexagon math.

The hexagons are given a hexagon point coordinate using the hexagon center location on the hexagon grid.

Now, analytic geometry is used for all math calculations.

The Hexagon Grid Calculator (docs) calculates the adjacent hexagon coordinates

Movement is calculated by adjusting the coordinates:

Note: The movement to adjacent hexagons DOES NOT require a check to see if the column is even or odd.

Note: Some of the hexagon grid coordinates land on the center of hexside lines. This coordinate is used to record its terrain.

The Hexagon Grid Calculator can determine if the grid coordinate is a center or a hexside.

The Hexagon Map Calculator calculates the hexagon point:

The adjacent hexsides are calculated by adjusting the coordinates from the hexagon center point:

Hexagon Name

The wargame map has labels on the hexagons to identify them.

The hexagon name is calculated from the hexagon point coordinate (x,y).

Note: This hexagon name is NOT a coordinate.

As the mouse moves, the hexagon point coordinate is calculated from the pixels on the map.

The Hexagon Grid is a simple cartesian x,y coordinate system used for wargame calculations.

hexagon point coordinate (x,y) → hexagon name

hexagon name → hexagon point coordinate (x,y)

Zone of Control ZOC

Zone of Control is calculated using the unit's hexagon point. Although the unit is placed on the map, the location of the unit is an attribute of the unit.

 ZocCalculator.prototype.unitIsZOC = function(index) {
  var isZOC = false;
  var los = new LineOfSight();
  var unitForce = this.force.getUnitForce(index);
  for (var i = 0; i < this.force.units.length; i++) {
   var force = this.force.getUnitForce(i);
   los.setOriginAndEndPoint(this.force.getUnitHexagonPoint(index), this.force.getUnitHexagonPoint(i));
   if (los.getRange() == 1){
    if(force != unitForce){
     isZOC = true;
   return isZOC;

The wargame consists of several components:
  1. Hexagon Library: hexagon math for unit placement, range, bearing and line of sight
  2. Battlefield: wargame map and unit images for display and recording mouse events
  3. Wargame Commands: process mouse events into wargame commands
  4. Wargame Rules: process commands using rules
  5. Wargame Components: wargame, terrain, force, map
  6. Wargame Data: wargame, terrain, map size, and order of battle data.
  7. Wargame Calculators: special rules concerning movement, combat, and victory