This skill should be used when the user needs to implement hex-based game boards, convert between hex coordinate systems, calculate hex distances, find hex neighbors, implement hex pathfinding, or draw hex maps. Trigger phrases include "hexagonal grids", "hex grid", "hex map", "honeycomb layout", "hex-based game", "hex pathfinding", "hex distance", "hex neighbors", "cube coordinates", "axial coordinates", "offset coordinates", "hex rotation", "hex ring", "hex spiral", "六边形网格", "六边形地图", "蜂窝布局", "蜂窝网格", "六边形坐标", "六边形寻路", "六边形距离", "六边形邻居", "立方坐标", "轴向坐标", "hex战棋", "蜂窝地图算法".
/plugin marketplace add 15195999826/LomoMarketplace/plugin install 15195999826-hex-grid-plugins-hex-grid@15195999826/LomoMarketplaceThis skill inherits all available tools. When active, it can use any tool Claude has access to.
references/algorithms.mdreferences/formulas.mdThis guide covers various ways to make hexagonal grids, the relationships between different approaches, and common formulas and algorithms. Based on concepts from the authoritative Red Blob Games Hexagonal Grids Guide.
Hexagons offer advantages over squares:
| System | Components | Storage | Algorithms | Best For |
|---|---|---|---|---|
| Offset | (col, row) | Easy | Hard | Rectangular storage |
| Cube | (q, r, s) | Redundant | Easy | All algorithms |
| Axial | (q, r) | Easy | Easy | General purpose |
| Doubled | (col, row) | Easy | Medium | Rectangular + algorithms |
Recommendation: Use axial as primary. Convert to cube for algorithms, offset for rectangular storage.
Three axes (q, r, s) with constraint: q + r + s = 0
Key properties:
max(|dq|, |dr|, |ds|)Two axes (q, r), deriving s as -q - r when needed.
Advantages:
Standard (col, row) with alternating rows/columns shifted:
Characteristics:
Alternative to offset that avoids parity issues:
col + row always evencol + row always evenAdvantage: Neighbors are consistent regardless of position.
Flat-top: Pointy-top:
___ /\
/ \ | |
\___/ \/
Choose based on:
Cube directions (6 neighbors):
[(+1,-1,0), (+1,0,-1), (0,+1,-1),
(-1,+1,0), (-1,0,+1), (0,-1,+1)]
To get neighbor: neighbor = hex + direction[i]
Diagonal neighbors (6 diagonals, distance 2):
[(+2,-1,-1), (+1,+1,-2), (-1,+2,-1),
(-2,+1,+1), (-1,-1,+2), (+1,-2,+1)]
Cube: max(|dq|, |dr|, |ds|)
Or equivalently: (|dq| + |dr| + |ds|) / 2
Axial: (|dq| + |dq + dr| + |dr|) / 2
for q in -N to +N:
for r in max(-N, -q-N) to min(+N, -q+N):
s = -q - r
yield center + (q, r, s)
Total hexes in range: 3*N*(N+1) + 1
Ring at distance N: Start at one corner, walk around (6*N hexes for N>0)
Spiral: Concatenate rings from 0 to N
60° clockwise (cube): (q,r,s) → (-r,-s,-q)
60° counter-clockwise (cube): (q,r,s) → (-s,-q,-r)
To rotate around arbitrary center: translate to origin, rotate, translate back.
Swap two coordinates:
(q,r,s) → (q,s,r)(q,r,s) → (s,r,q)(q,r,s) → (r,q,s)Flat-top:
x = size * (3/2 * q)
y = size * (sqrt(3)/2 * q + sqrt(3) * r)
Pointy-top:
x = size * (sqrt(3) * q + sqrt(3)/2 * r)
y = size * (3/2 * r)
Flat-top:
q = (2/3 * x) / size
r = (-1/3 * x + sqrt(3)/3 * y) / size
Pointy-top:
q = (sqrt(3)/3 * x - 1/3 * y) / size
r = (2/3 * y) / size
Then apply cube rounding (see Common Pitfalls).
Use A* with cube/axial distance as heuristic. The heuristic is admissible (never overestimates).
Cast rays to each potential target. Target is visible if no blocking hex lies on the line.
For toroidal (wrapping) maps, use modular arithmetic. Rectangular wraparound with offset coordinates is simpler than hexagonal wraparound.
When converting pixel → hex, simple rounding breaks q+r+s=0. Use this algorithm:
round all three, then reset the one with largest error:
if |q_diff| > |r_diff| and |q_diff| > |s_diff|:
q = -r - s
elif |r_diff| > |s_diff|:
r = -q - s
else:
s = -q - r
Offset neighbors depend on odd/even column/row. Use lookup tables, not formulas.
Lines through hex edges create ambiguity. Add epsilon to one endpoint before interpolation.
Establish conventions early. Convert explicitly at boundaries.
| Task | Approach |
|---|---|
| Store rectangular map | Offset in 2D array |
| Store sparse map | Axial in hash map |
| Calculate distance | Cube formula |
| Find path | A* with cube heuristic |
| Draw line | Cube interpolation + rounding |
| Get neighbors | Cube addition |
| Rotate/reflect | Cube coordinates |
| Pixel ↔ hex | Axial formulas + cube rounding |
For detailed formulas, algorithms, and pseudocode:
references/formulas.md - Complete formula reference for all conversionsreferences/algorithms.md - Detailed pseudocode for pathfinding, FOV, storageFor interactive diagrams and comprehensive explanations, consult: Red Blob Games: Hexagonal Grids
This is the definitive resource for hexagonal grid development, featuring interactive visualizations and code samples in multiple languages.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.