Documentation ¶
Index ¶
- func TakePosition(pos Position, taker SpaceTaker) actions.Action
- type HeadedPlacement
- func (hp *HeadedPlacement) AtPoint() Point
- func (hp *HeadedPlacement) FollowPath(path Path, stepDt time.Duration) actions.Action
- func (hp *HeadedPlacement) Headed() bool
- func (hp *HeadedPlacement) Heading() Point
- func (hp *HeadedPlacement) MoveTo(dst Position, dt time.Duration) actions.Action
- func (hp *HeadedPlacement) Place(pos Position) bool
- func (hp *HeadedPlacement) Placed() bool
- func (hp *HeadedPlacement) Progress() float64
- type OnePosTaker
- type Path
- type PathFinder
- type Point
- type Position
- type Space
- type SpaceTaker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TakePosition ¶
func TakePosition(pos Position, taker SpaceTaker) actions.Action
TakePosition builds an action that tries to immediately take the given position with the given taker. If the position is taken, the action fails, interrupted.
Types ¶
type HeadedPlacement ¶
type HeadedPlacement struct {
// contains filtered or unexported fields
}
A HeadedPlacement is either:
- nowhere
- at a point
- moving from one point to another
func (*HeadedPlacement) AtPoint ¶
func (hp *HeadedPlacement) AtPoint() Point
AtPoint the current point of current the placement. As a special case it returns the zero value when the placement is not placed anywhere. Call Placed to distinguish that from a placement at that position.
func (*HeadedPlacement) FollowPath ¶
FollowPath creates an action that will move the heading along the path. Each step will take stepDt.
When first run, the action fails immediately if the heading is not at the initial position of the path.
func (*HeadedPlacement) Headed ¶
func (hp *HeadedPlacement) Headed() bool
Headed says whether the placement is headed somewhere. Nothing else is able to occupy the position where the placement is headed at the same time.
func (*HeadedPlacement) Heading ¶
func (hp *HeadedPlacement) Heading() Point
Heading is the point where the placement is headed. As a special case it returns the zero value when the placement is headed nowhere. Call Headed to distinguish that from a placement headed there.
func (*HeadedPlacement) MoveTo ¶
MoveTo creates an action that will try to move the placement to dst over a duration of dt. The action gets interrupted if the dst position is taken as it starts.
func (*HeadedPlacement) Place ¶
func (hp *HeadedPlacement) Place(pos Position) bool
Place tries to put the placement at the given position. The return value says whether this has succeded.
func (*HeadedPlacement) Placed ¶
func (hp *HeadedPlacement) Placed() bool
Placed says whether the placement takes up some position. Nothing else is be able to occupy the same position at the same time.
func (*HeadedPlacement) Progress ¶
func (hp *HeadedPlacement) Progress() float64
Progress says how far along the placement is in the move from the start position to the heading. This is 1 when the placement is not headed anywhere.
type OnePosTaker ¶
type OnePosTaker struct {
// contains filtered or unexported fields
}
A OnePosTaker is a space taker that occupies at most one grid position at a time.
func (*OnePosTaker) AtPoint ¶
func (taker *OnePosTaker) AtPoint() Point
AtPoint is the point at which the taken position is.
The zero value of the type is returned when the taker is not placed. Do not use that to check if the taker is placed. A taker might be taking the position at the zero point.
func (*OnePosTaker) ForceOff ¶
func (taker *OnePosTaker) ForceOff(pos Position)
ForceOff is part of the SpaceTaker interface.
func (*OnePosTaker) Leave ¶
func (taker *OnePosTaker) Leave()
Leave makes the taker leave a position if it has one taken.
func (*OnePosTaker) LetOnto ¶
func (taker *OnePosTaker) LetOnto(pos Position)
LetOnto is part of the SpaceTaker interface.
func (*OnePosTaker) Placed ¶
func (taker *OnePosTaker) Placed() bool
Placed says whether the space taker is taking a position.
type PathFinder ¶
type PathFinder struct {
// contains filtered or unexported fields
}
A PathFinder finds paths from one point to another.
func NewPathFinder ¶
func NewPathFinder(space *Space) PathFinder
NewPathFinder creates a path finder that searches for path through the specified space.
The path finder will be sensitive to what positions do and do not exist in the space. The space can be modified after the path finder is created - it will be aware of the updates.
func (PathFinder) FindPath ¶
func (pf PathFinder) FindPath(src, dst Position) (path Path, exists bool)
FindPath searches for a path from src to dst.
When a path cannot be found it reports so and returns a path containing exactly src. Otherwise it returns a viable path.
func (PathFinder) IsViable ¶
func (pf PathFinder) IsViable(path Path) bool
IsViable validates a path.
It will be false if the path contains positions from a different space. It will be false if the path contains positions that cannot be occupied. It will be false if the path contains two consecutive positions that are not neighbours.
type Position ¶
type Position struct {
// contains filtered or unexported fields
}
A Position within some space.
func (Position) AtPoint ¶
AtPoint is the point at which the position is in the space that contains it.7
func (Position) Create ¶
Create ensures that a position within a space exists. It fails when the position exists.
func (Position) Destroy ¶
Destroy ensures that a position within a space does not exist. It fails when the position does not exist or is taken.
func (Position) Free ¶
Free tries to mark the position as no longer taken. It fails if the position is not taken.
func (Position) Take ¶
func (pos Position) Take(taker SpaceTaker) bool
Take tries to mark the position as taken. It fails if the position does not exist or is free.
type Space ¶
type Space struct {
// contains filtered or unexported fields
}
A Space where things can exist and interact.
It is a subspace of a 2D grid. Which positions on the grid exist can change dynamically.
func (*Space) At ¶
At returns the position at the given point in the space.
Two position values returned for the same point in the space will be equal.
type SpaceTaker ¶
type SpaceTaker interface { // LetOnto tells the space taker that it is now taking up pos. LetOnto(pos Position) // ForceOff tells the space taker that it is no longer taking up pos. ForceOff(pos Position) }
A SpaceTaker is the thing that takes up a taken position.
A space taker can take up multiple positions at once.
func DummyTaker ¶
func DummyTaker() SpaceTaker
DummyTaker returns a space taker that only takes up the position it takes. It has no additional behaviour.