Sternhalma.Pathfinding (Sternhalma v0.1.1) View Source
Provides functions for pathfinding in the context of a game board.
Pathfinding comes into play when determining if a proposed move is valid.
A path is considered valid if:
- The finishing cell is empty and a direct neighbor of the starting cell
- The finishing cell is empty and is reachable via one or more "jump" moves
A jump is only possible if there's a marble in between the current cell and an empty cell.
Marbles can be jumped any number of times, as long as the direction of the jump doesn't change while not on an empty cell. It is valid to change directions once an empty cell is reached.
Link to this section Summary
Functions
Return the cells that are reachable one jump move away from the given position.
Find and return a list of cells between the given start and finish cells.
Link to this section Types
Specs
path() :: %{required(Sternhalma.Cell.t()) => :done | Sternhalma.Cell.t()}
Specs
visited() :: %{required(Sternhalma.Hex.t()) => true}
Link to this section Functions
Specs
jumpable_neighbors(Sternhalma.Hex.t(), Sternhalma.Board.t()) :: [ Sternhalma.Cell.t() ]
Return the cells that are reachable one jump move away from the given position.
See Hex.neighbors/1 or Hex.neighbor/2 for finding neighbors in general.
Specs
path(Sternhalma.Board.t(), Sternhalma.Cell.t(), Sternhalma.Cell.t()) :: [ Sternhalma.Cell.t() ]
Find and return a list of cells between the given start and finish cells.
If there is not a valid path between the two, an empty list is returned.
The shortest path possible is returned.