Skip to Main Content
Mazes for Programmers
book

Mazes for Programmers

by Jamis Buck
July 2015
Intermediate to advanced content levelIntermediate to advanced
286 pages
6h 31m
English
Pragmatic Bookshelf
Content preview from Mazes for Programmers

Implementing a Hex Grid

So far we’ve made regular grids and circular grids. Our next goal is to create a grid of hexagons, also called a hex grid for short. We’ll approach this by first considering a single cell, with an eye to understanding how it relates spatially to its neighbors. From there, we’ll take that information and implement the grid itself.

The cells aren’t difficult to implement. The trickiest part is just understanding how they all fit together. Let’s look at a simple hex grid here:

images/hex-grid.png

From that, we can see that each hexagon neighbors up to six other hexagons, one for each of north, south, northwest, northeast, southwest, and southeast. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Exercises for Programmers

Exercises for Programmers

Brian P. Hogan

Publisher Resources

ISBN: 9781680501315Errata Page