ship

package
v0.0.0-...-07010e4 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsInt

func AbsInt(n int) int

Types

type Dir

type Dir int
const (
	DirEast  Dir = 0
	DirSouth Dir = 90
	DirWest  Dir = 180
	DirNorth Dir = 270
)

func (Dir) Added

func (d Dir) Added(v int) Dir

func (Dir) String

func (d Dir) String() string

type Instruction

type Instruction struct {
	Op    Op
	Value int
}

func ParseInstruction

func ParseInstruction(s string) (Instruction, error)

func (Instruction) String

func (i Instruction) String() string

type Op

type Op rune
const (
	OpMvNorth   Op = 'N'
	OpMvSouth   Op = 'S'
	OpMvEast    Op = 'E'
	OpMvWest    Op = 'W'
	OpTurnLeft  Op = 'L'
	OpTurnRight Op = 'R'
	OpMvFwd     Op = 'F'
)

type Pos

type Pos struct {
	EW, NS int
}

func (Pos) Distance

func (p Pos) Distance(op Pos) int

func (Pos) String

func (p Pos) String() string

type Ship

type Ship struct {
	StartPos Pos
	Pos      Pos
	Dir      Dir
}

func New

func New(pos Pos, dir Dir) *Ship

func (*Ship) Distance

func (s *Ship) Distance() int

func (*Ship) Process

func (s *Ship) Process(inst Instruction)

func (*Ship) Report

func (s *Ship) Report() string

type ShipWithWaypoint

type ShipWithWaypoint struct {
	StartPos Pos
	Pos      Pos
	Waypoint Pos
}

func NewWithWaypoint

func NewWithWaypoint(pos Pos, waypoint Pos) *ShipWithWaypoint

func (*ShipWithWaypoint) Distance

func (s *ShipWithWaypoint) Distance() int

func (*ShipWithWaypoint) Process

func (s *ShipWithWaypoint) Process(inst Instruction)

func (*ShipWithWaypoint) Report

func (s *ShipWithWaypoint) Report() string

func (*ShipWithWaypoint) RotateWaypoint

func (s *ShipWithWaypoint) RotateWaypoint(deg int)

Jump to

Keyboard shortcuts

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