- Must have between and including 2 and 4 child node
- Only the leafs don't have child
- Must have one parent node
- Only the root doesn't have a parent
- Each node must have a state
- The state of the grid at this point
- Should contains location of tile
0
- Must implement a method to generate new node from the previous one
struct Node {
state: State,
grid: Grid,
parent: Option<Node>,
}- The cost (
g score) of this node which is the number of moves needed to reach this state - The heuristic (
h score) which will depends on the heuristic function we use - The sum of the cost and the heuristic of this node (
f score)
struct State {
h: u16,
g: u32,
f: u32,
}- Represent the state of the whole puzzle for a given node
- Will be stored in each node
- Must implement a method to
movea tile inside the grid (swap the position of a tile with the tile0if they are directly next to each other) - Should keep the size of the puzzle or the greatest index we can have
- Should implement a method to generate a "snail" for the given puzzle size
struct Grid {
map: Vec<u16>,
z_pos: u16, // Absolute position
}- Contains all nodes for which we have already process all their child nodes
- Will be used to construct the final path across the nodes which will give us the moves we have to do to solve the puzzle
- Must be sorted by
f scorevalue (lowest first) or for two nodes with the samef scorevalue sorted by their heuristic values
- Must implement a main loop over the open list to unstack it
- For each node from the open list generate a new node for every possible move and push it into the open list
Up-> tile0goes upDown-> tile0goes downRight-> tile0goes rightLeft-> tile0goes left- The tile cannot go outside of the table (obviously)
| x0 | x1 | x2 | |
|---|---|---|---|
| y0 | 1 | 2 | 3 |
| y1 | 4 | 5 | 6 |
| y2 | 7 | 8 | 0 |
- closedList should probably be a BTreeSet (for read access speed)
- openList should probably be a BinaryHeap (for auto-sort and quick read access)
we probably need a tree to represent all the nodes and their parentno need to use a tree of any kind for this since we don't care about retrieving child from its parent (the only thing we care about is being able to retrieve a parent from one of its child)
- Limite on the research depending on
g scoreor/andh score