day15

package
v0.0.0-...-a30599c Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fill

func Fill(c *Canvas) int

Fill spreads the tile destination to adjacent spaces until the entire canvas is filled. It returns the number of steps required to do so.

Types

type Canvas

type Canvas struct {
	// contains filtered or unexported fields
}

Canvas is an infinitely paintable 2D surface.

func NewCanvas

func NewCanvas() *Canvas

NewCanvas creates an empty canvas.

func (*Canvas) At

func (c *Canvas) At(p point.Point2D) int

At gets the color painted at a point.

func (*Canvas) Count

func (c *Canvas) Count() int

Count returns the number of points that have been painted at all.

func (*Canvas) CountColor

func (c *Canvas) CountColor(color int) int

CountColor returns the number of points painted with the given color.

func (*Canvas) Draw

func (c *Canvas) Draw(drawFn func(int, int, int))

Draw calls the provided drawFn for every square on the canvas, regardless of whether it has been painted to.

func (*Canvas) Height

func (c *Canvas) Height() int

Height returns the height of the canvas

func (*Canvas) Paint

func (c *Canvas) Paint(p point.Point2D, color int)

Paint paints a point with a color, extending the bounds of the canvas if needed.

func (*Canvas) PrintTo

func (c *Canvas) PrintTo(w io.Writer)

PrintTo prints the image on the canvas to the given writer.

func (*Canvas) Width

func (c *Canvas) Width() int

Width returns the width of the canvas

type Direction

type Direction int

Direction is a cardinal direction that the robot can be instructed to move in.

const (
	None Direction = iota
	North
	South
	West
	East
)

Constants for directions that can be given to the robot.

type Mapper

type Mapper struct {
	// contains filtered or unexported fields
}

Mapper is responsible for constructing a map of a location by controlling a robot with an Intcode program.

func NewMapper

func NewMapper(c *Canvas) *Mapper

NewMapper creates a new mapper using a given canvas to draw the map.

func (*Mapper) Start

func (m *Mapper) Start(input chan<- int, output <-chan int) point.Point2D

Start begins mapping using the given input and output channels. It returns the location of the destination.

type PathFinder

type PathFinder struct {
	// contains filtered or unexported fields
}

PathFinder finds paths between a start and goal point on a map.

func NewPathFinder

func NewPathFinder(canvas *Canvas, goal point.Point2D) *PathFinder

NewPathFinder creates a new path finder with a given map and goal.

func (*PathFinder) ShortestPath

func (pf *PathFinder) ShortestPath() []point.Point2D

ShortestPath finds the shortest path from (0, 0) to the path finder's goal. Returns the list of points that form the path, starting from the goal and ending with the start point, including both.

type Status

type Status int

Status is a status code that can be returned from the Intcode program.

const (
	// HitWall signals that the droid hit a wall and was not able to move.
	HitWall Status = iota
	// Moved signals that the droid moved in the requested direction but
	// did not find the destination.
	Moved
	// FoundDestination signals that the droid moved in the requested
	// direction and found the destination.
	FoundDestination
)

type Tile

type Tile int

Tile is a type of tile drawn on a map.

const (
	// TileUnknown is a tile that hasn't been discovered
	TileUnknown Tile = iota
	// TilePassable is a tile that the droid can enter
	TilePassable
	// TileWall is a tile that is an impassable wall
	TileWall
	// TileDestination is the tile with the goal
	TileDestination
	// TileStart is the location where the droid started
	TileStart
)

Jump to

Keyboard shortcuts

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