Documentation ¶
Index ¶
- Constants
- Variables
- func Run(args []string) int
- type Config
- type Format
- type InfiniMaze
- type Maze
- func (maze *Maze) Connected(point *Point, target *Point) bool
- func (maze *Maze) Contains(point *Point) bool
- func (maze *Maze) Generate()
- func (maze *Maze) Move(direction int)
- func (maze *Maze) Neighbors(point *Point) (neighbors []int)
- func (maze *Maze) Next(point *Point) *Point
- func (maze *Maze) PointIsExit(point *Point) bool
- func (maze *Maze) Print(writer io.Writer, format *Format)
- func (maze *Maze) Write(writer chan string, format *Format)
- type Point
Constants ¶
const ( Up = 1 << iota Down Left Right )
Maze cell configurations The paths of the Maze is represented in the binary representation.
const (
VisitedOffset = 8
)
The solution path is represented by (Up|Down|Left|Right) << SolutionOffset. The user's path is represented by (Up|Down|Left|Right) << VisitedOffset.
Variables ¶
var Ascii = &Format{
Wall: "##",
Path: " ",
Cursor: "@@",
ExitDown: "VV",
ExitRight: ">>",
ExitLeft: "<<",
ExitUp: "^^",
}
Ascii format
var Color = &Format{
Wall: " ",
Path: "\x1b[7m \x1b[0m",
ExitDown: "\x1b[42;1mVV\x1b[0m",
ExitRight: "\x1b[42;1m>>\x1b[0m",
ExitLeft: "\x1b[42;1m<<\x1b[0m",
ExitUp: "\x1b[42;1m^^\x1b[0m",
Cursor: "\x1b[43;1m@@\x1b[0m",
}
Default Color format
Directions is the set of all the directions
Opposite directions
Functions ¶
Types ¶
type Format ¶
type Format struct { Wall string Path string Cursor string ExitDown string ExitRight string ExitLeft string ExitUp string }
Format is the printing format of the infiniMaze
type InfiniMaze ¶
type InfiniMaze struct { CurrentMaze *Maze //A Maze Struct containing the state of the currently visible Maze // contains filtered or unexported fields }
This struct holds state for the entire application
func NewInfiniMaze ¶
func NewInfiniMaze(config *Config) *InfiniMaze
func (*InfiniMaze) GenNewMazes ¶
func (infiniMaze *InfiniMaze) GenNewMazes(maze *Maze)
* This function checks if the current Maze has all of its adjoining mazes connected. If a direction does not have a Maze, first the delta is calculated and checked against the global maze registry. If a Maze is found, the two mazes are connected. If one is not found, the new Maze is created, then they are both connected.
func (*InfiniMaze) Move ¶
func (infiniMaze *InfiniMaze) Move(direction int)
This handles the users movement first so we can detect whether they entered a "door" to an adjoining maze. If they do, we swap the current maze, place the user on the right spot of the new maze, and generate any new mazes as needed. If they aren't entering a "door" we pass along the movement info to the current displayed maze.
type Maze ¶
type Maze struct { Directions [][]int //Each Point on the map is represented as an integer that defines the directions that can be traveled from that Point Height int //Height of Maze Width int //Width of Maze XLocation int //Global X position within InfiniMaze YLocation int //Global Y position within InfiniMaze Exits [4]*Point //Point array for the four "doors" leading the adjoining Mazes Cursor *Point //Users location within the Maze NorthMaze *Maze //Reference to the Maze North of the current maze SouthMaze *Maze //Reference to the Maze South of the current maze WestMaze *Maze //Reference to the Maze West of the current maze EastMaze *Maze //Reference to the Maze East of the current maze }
Maze represents the configuration of a specific Maze within InfiniMaze
func (*Maze) PointIsExit ¶
Check for whether point on Maze is an exit "door" to another Maze