maze

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2017 License: MIT Imports: 8 Imported by: 0

README

maze Travis Build Status

maze

Usage

The maze command without the arguments prints the random maze to the standard output.

maze

maze

We can play the maze on the terminal with --interactive.

maze --interactive

maze

The --format color is a good option to print the colored maze. Also we can specify the size of the maze with --width and --height.

maze --width 20 --height 10 --format color

maze

We can toggle the solution with the s key. maze

If we change the font size of the terminal smaller, we get a large maze. maze

Installation

Homebrew
 $ brew install itchyny/maze/maze
Download binary from GitHub Releases

Releases・itchyny/maze - GitHub

Build from source
 $ go get -u github.com/itchyny/maze/cmd/maze

Bug Tracker

Report bug at Issues・itchyny/maze - GitHub.

Author

itchyny (https://github.com/itchyny)

License

This software is released under the MIT License, see LICENSE.

Special thanks

Special thanks to the termbox-go library.

References

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 (
	SolutionOffset = 4
	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 Color = &Format{
	Wall:               "\x1b[7m  \x1b[0m",
	Path:               "  ",
	StartLeft:          "S ",
	StartRight:         " S",
	GoalLeft:           "G ",
	GoalRight:          " G",
	Solution:           "\x1b[44;1m  \x1b[0m",
	SolutionStartLeft:  "\x1b[44;1mS \x1b[0m",
	SolutionStartRight: "\x1b[44;1m S\x1b[0m",
	SolutionGoalLeft:   "\x1b[44;1mG \x1b[0m",
	SolutionGoalRight:  "\x1b[44;1m G\x1b[0m",
	Visited:            "\x1b[42;1m  \x1b[0m",
	VisitedStartLeft:   "\x1b[42;1mS \x1b[0m",
	VisitedStartRight:  "\x1b[42;1m S\x1b[0m",
	VisitedGoalLeft:    "\x1b[42;1mG \x1b[0m",
	VisitedGoalRight:   "\x1b[42;1m G\x1b[0m",
	Cursor:             "\x1b[43;1m  \x1b[0m",
}

Color format

View Source
var Default = &Format{
	Wall:               "##",
	Path:               "  ",
	StartLeft:          "S ",
	StartRight:         " S",
	GoalLeft:           "G ",
	GoalRight:          " G",
	Solution:           "::",
	SolutionStartLeft:  "S:",
	SolutionStartRight: ":S",
	SolutionGoalLeft:   "G:",
	SolutionGoalRight:  ":G",
	Visited:            "..",
	VisitedStartLeft:   "S.",
	VisitedStartRight:  ".S",
	VisitedGoalLeft:    "G.",
	VisitedGoalRight:   ".G",
	Cursor:             "::",
}

Default 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

This section is empty.

Types

type Format

type Format struct {
	Wall               string
	Path               string
	StartLeft          string
	StartRight         string
	GoalLeft           string
	GoalRight          string
	Solution           string
	SolutionStartLeft  string
	SolutionStartRight string
	SolutionGoalLeft   string
	SolutionGoalRight  string
	Visited            string
	VisitedStartLeft   string
	VisitedStartRight  string
	VisitedGoalLeft    string
	VisitedGoalRight   string
	Cursor             string
}

Format is the printing format of the maze

type Maze

type Maze struct {
	Directions [][]int
	Height     int
	Width      int
	Start      *Point
	Goal       *Point
	Cursor     *Point
	Solved     bool
	Started    bool
	Finished   bool
}

Maze represents the configuration of a maze

func NewMaze

func NewMaze(height int, width int) *Maze

NewMaze creates a new maze

func (*Maze) Clear

func (maze *Maze) Clear()

Clear the solution

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 the 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) Print

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

Print out the maze to the IO writer

func (*Maze) PrintImage added in v0.0.1

func (maze *Maze) PrintImage(writer io.Writer, format *Format, scale int)

PrintImage outputs the maze to the IO writer as PNG image

func (*Maze) Solve

func (maze *Maze) Solve()

Solve the maze

func (*Maze) Undo

func (maze *Maze) Undo()

Undo the visited path

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 the 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

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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