internal

package
v0.0.0-...-efefdc7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Up = 1 << iota
	Down
	Left
	Right
)

Maze cell configurations The paths of the Maze is represented in the binary representation.

View Source
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

View Source
var Ascii = &Format{
	Wall:      "##",
	Path:      "  ",
	Cursor:    "@@",
	ExitDown:  "VV",
	ExitRight: ">>",
	ExitLeft:  "<<",
	ExitUp:    "^^",
}

Ascii format

View Source
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

View Source
var Directions = []int{Up, Down, Left, Right}

Directions is the set of all the directions

View Source
var Opposite = map[int]int{Up: Down, Down: Up, Left: Right, Right: Left}

Opposite directions

Functions

func Run

func Run(args []string) int

Types

type Config

type Config struct {
	Width  int
	Height int
	Format *Format
	Seed   int64
	Output io.Writer
}

Config is the command configuration

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 NewMaze

func NewMaze(height int, width int, xLoc int, yLoc int) *Maze

NewMaze creates a new Maze

func (*Maze) Connected

func (maze *Maze) Connected(point *Point, target *Point) bool

Connected judges whether the two points is connected by a path on the maze

func (*Maze) Contains

func (maze *Maze) Contains(point *Point) bool

Contains judges whether the argument point is inside Maze or not

func (*Maze) Generate

func (maze *Maze) Generate()

Generate the Maze

func (*Maze) Move

func (maze *Maze) Move(direction int)

Move the cursor

func (*Maze) Neighbors

func (maze *Maze) Neighbors(point *Point) (neighbors []int)

Neighbors gathers the nearest undecided points

func (*Maze) Next

func (maze *Maze) Next(point *Point) *Point

Next advances the Maze path randomly and returns the new point

func (*Maze) PointIsExit

func (maze *Maze) PointIsExit(point *Point) bool

Check for whether point on Maze is an exit "door" to another Maze

func (*Maze) Print

func (maze *Maze) Print(writer io.Writer, format *Format)

Print out the Maze to the IO writer

func (*Maze) Write

func (maze *Maze) Write(writer chan string, format *Format)

Write out the Maze to the writer channel

type Point

type Point struct {
	X, Y int
}

Point on a Maze

func (*Point) Advance

func (point *Point) Advance(direction int) *Point

Advance the point forward by the argument direction

func (*Point) Equal

func (point *Point) Equal(target *Point) bool

Equal judges the equality of the two points

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL