Every pathfinder needs a map to search. Ours is a grid, a rectangle of cells laid out in rows and columns, and today you build it and have it report its own size. Everything later carves paths and mazes through this one structure.
Create a grid of a fixed width and height and report both dimensions.
A pathfinder works over a map, and the simplest useful map is a grid: a
rectangle of cells addressed by column x and row y. Keeping the map an explicit
grid, rather than real-world geometry, is what makes every later result an exact
value you can check: a path is a list of cell coordinates, a cost is an integer, a
maze is a specific pattern of walls.
Today is deliberately tiny. A grid needs to know how wide and how tall it is,
because those dimensions bound every coordinate the search will ever touch. That
width by height rectangle is the entire world our pathfinder lives in, so
pinning it down precisely is where everything starts.
// the whole pathfinder searches inside this one gridtype Grid struct {W, H int}func NewGrid(w, h int) *Grid { return &Grid{W: w, H: h} }func (g *Grid) Width() int { return g.W }func (g *Grid) Height() int { return g.H }