board

package
v0.0.0-...-b154a2b Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateArmyGraph

func CreateArmyGraph() *simple.UndirectedGraph

Types

type Manager

type Manager interface {
	Position(*Unit) *Position
	Positions() map[*Unit]Position
	Move(*Unit, Territory, int)
	Hold(*Unit, int)
	Bounce(*Unit)
	SetDefeated(*Unit)
	Conflict() []*Unit
	AtOrigin(*Unit) bool
}

Manager is a board manager that records positions of units on a board

type Position

type Position struct {
	Territory Territory
	Strength  int
	Cause     PositionEvent
}

Position describes the unit's board position

type PositionEvent

type PositionEvent int

PositionEvent describes the causes of a unit's position

const (
	// UnitPlaced unit added to the board at the beginning of the phase
	UnitPlaced PositionEvent = iota // TODO: decide better name for this
	// Held unit has been held by player
	Held
	// Moved unit has moved territories
	Moved
	// Bounced unit has bounced from territory
	Bounced
	// Defeated unit has been defeated
	Defeated
)

type PositionManager

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

PositionManager implements Manager

func NewPositionManager

func NewPositionManager() PositionManager

NewPositionManager constructor for PositionManager

func (PositionManager) AddUnit

func (m PositionManager) AddUnit(unit *Unit, territory Territory)

AddUnit places a unit on the board

func (PositionManager) AtOrigin

func (m PositionManager) AtOrigin(u *Unit) bool

AtOrigin determines if the unit is located at the phase starting position

func (PositionManager) Bounce

func (m PositionManager) Bounce(u *Unit)

Bounce bounces two or more units when there is no winner

func (PositionManager) Conflict

func (m PositionManager) Conflict() []*Unit

Conflict returns the first conflict found on the board

func (PositionManager) Defeated

func (m PositionManager) Defeated(u *Unit) bool

Defeated determines if the unit has been defeated

func (PositionManager) Hold

func (m PositionManager) Hold(u *Unit, strength int)

Hold holds the unit in the current position

func (PositionManager) Move

func (m PositionManager) Move(u *Unit, to Territory, strength int)

Move moves a unit from one territory to another

func (PositionManager) Position

func (m PositionManager) Position(u *Unit) *Position

Position returns the current board position of a unit

func (PositionManager) Positions

func (m PositionManager) Positions() map[*Unit]Position

Positions returns all positions managed

func (PositionManager) SetDefeated

func (m PositionManager) SetDefeated(u *Unit)

SetDefeated sets a unit's position as defeated

type Territory

type Territory struct {
	Abbr string
	Name string
	// contains filtered or unexported fields
}

func LookupTerritory

func LookupTerritory(abbr string) Territory

func (Territory) ID

func (t Territory) ID() int64

func (Territory) Is

func (t Territory) Is(cmp Territory) bool

func (Territory) IsNot

func (t Territory) IsNot(cmp Territory) bool

type Unit

type Unit struct {
	Country string
	Type    UnitType
}

type UnitType

type UnitType string
const (
	Army  UnitType = "army"
	Fleet UnitType = "fleet"
)

Jump to

Keyboard shortcuts

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