Documentation ¶
Overview ¶
Package maze generates a 2D maze
Index ¶
Constants ¶
const ( // X Represents the X value of X,Y coordinates in a 2D maze X = iota // Y Represents the Y value of X,Y coordinates in a 2D maze Y )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Direction ¶
type Direction = int
Direction is an enum representing 4 possible values Up, Down, Left and Right
type Maze ¶
type Maze struct {
// DimX and DimY are the dimensions of the maze
DimX, DimY int
// Cells is a slice of DimX * DimY maze cells, each cell has an array of two booleans represnting the existance of the passages Right and Down
// If DimX is 5 then the x,y coordinates of cell of index 7 are 2,1 (index % DimX, index/DimY)
// If the passage to the right of the cell is open then the first boolean is true
// If the passage down from the cell is open then the second boolean is true.
Cells [][2]bool
}
Maze represents a 2D maze. The zero value is a very uninteresting case of a maze with no cells. Use New to generate a valid maze of the desired dimensions.
func New ¶
New generates a random maze using Prim's algorithm (non-simplified) The maze doesn't contain cycles, to generate a cycle remove any wall at random
func (Maze) CellFromCoords ¶
CellFromCoords takes x,y coordinates and returns the correrlating cell
func (Maze) CoordsFromCell ¶
CoordsFromCell takes a cell and returns its x,y coordinates
func (Maze) PathDown ¶
PathDown returns true if the path between the current cell and the cell below is open
func (Maze) PathRight ¶
PathRight returns true if the path between the current cell and the cell to its right is open
func (*Maze) RemoveWall ¶
RemoveWall doesn't validate the existence of the wall to remove - use at own peril