core

package
v0.0.0-...-8924883 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Main labyrinth functionality

Index

Constants

View Source
const (
	Empty cell = iota
	Wall
	Start
	Finish
	Path
	Unknown // should always be last for type validation
)

Enum for possible things placed in a cell

Variables

This section is empty.

Functions

This section is empty.

Types

type Coordinates

type Coordinates struct {
	X, Y int
}

Simply a coordinate pair to show the placement of a Cell

func (Coordinates) Distance

func (c Coordinates) Distance(dest Coordinates) float64

Calculate distance between two coordinates

func (Coordinates) IsValid

func (c Coordinates) IsValid(maxX, maxY uint) bool

Check that coordinates are within bounds

func (Coordinates) String

func (c Coordinates) String() string

String representation of coordinates struct

type Field

type Field struct {
	Width, Length uint
	Start, Finish Coordinates
	Configuration *configuration
	// contains filtered or unexported fields
}

Container for labyrinth and additional characteristics

func (*Field) At

func (f *Field) At(c Coordinates) (cell, error)

Get cell type at given coordinates

func (*Field) CountCells

func (f *Field) CountCells() map[cell]uint

Count all cell types in the labyrinth

func (Field) Error

func (Field) Error(s string) error

Formatted error for usage in Field

func (*Field) FillEmptyCellsWithWalls

func (f *Field) FillEmptyCellsWithWalls()

Replace paths with empty cells and fill the rest with walls

func (*Field) GetLabyrinth

func (f *Field) GetLabyrinth() [][]uint

Return serialized labyrinth data

func (*Field) Init

func (f *Field) Init(filename string) error

Set up configuration values from .toml file

func (*Field) LoadLabyrinth

func (f *Field) LoadLabyrinth(l [][]uint) error

Load labyrinth from input data

func (*Field) LoadLabyrinthFromFile

func (f *Field) LoadLabyrinthFromFile(file_path string) error

Deserialize and load labyrinth data from file

func (*Field) MakeEmpty

func (f *Field) MakeEmpty(leave_start_and_finish bool)

Clear up all cells except for start and finish if the flag is true

func (*Field) SaveLabyrinthToFile

func (f *Field) SaveLabyrinthToFile(file_path string) error

Save serialized labyrinth data to file in existing directory

func (*Field) Set

func (f *Field) Set(new_cell cell, c Coordinates) error

Change cell type at the chosen coordinates

func (*Field) SetSize

func (f *Field) SetSize(width, length uint)

Change the size of labyrinth Clears up all cells

func (*Field) SetStartAndFinish

func (f *Field) SetStartAndFinish(start, finish Coordinates)

Set start and finish points

func (*Field) Size

func (f *Field) Size() uint

Count the amount of all cells in labyrinth

func (Field) String

func (f Field) String() string

String representation of the entire labyrinth and its data

type Route

type Route struct {
	Start, End  *routeStep
	Length      uint
	BaseIndices []uint
}

Linked list to represent a route

func (*Route) Add

func (r *Route) Add(c Coordinates) error

Add a new routeStep to the route

func (Route) CopyUntil

func (r Route) CopyUntil(n uint) (Route, error)

Return a copy of the chosen route with n steps

func (Route) Error

func (Route) Error(s string) error

Formatted error for usage in Route

func (*Route) GetIterator

func (r *Route) GetIterator() func() (Coordinates, bool)

Return iterator to go over the entire Route

func (*Route) Init

func (r *Route) Init(c Coordinates) error

Initialize a route with one step

func (Route) String

func (r Route) String() string

String representation of Route

Jump to

Keyboard shortcuts

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