Header file for the maze data structure and public functions. More...
#include <stdint.h>
#include <stdbool.h>
Go to the source code of this file.
Data Structures | |
union | maze_bitmask_compressed |
Used for sending the maze over serial or WiFi. More... | |
struct | maze_gap_bitmask |
This struct contains the maze gap bitmasks for serialisation. More... | |
struct | maze_grid |
This struct contains the maze grid information. More... | |
struct | maze_grid_cell |
This struct contains the node information. More... | |
struct | maze_navigator_state |
This struct contains the state of a navigator in the maze. More... | |
struct | maze_point |
This struct contains the coordinates of a point. More... | |
Macros | |
#define | MAZE_INVERT_BITMASK(x) ((0xFu - x) & 0xFu) |
This macro inverts an 4-bit bitmask. More... | |
Typedefs | |
typedef union maze_bitmask_compressed | maze_bitmask_compressed_t |
Used for sending the maze over serial or WiFi. | |
typedef struct maze_gap_bitmask | maze_gap_bitmask_t |
This struct contains the maze gap bitmasks for serialisation. | |
typedef struct maze_grid_cell | maze_grid_cell_t |
This struct contains the node information. More... | |
typedef struct maze_grid | maze_grid_t |
This struct contains the maze grid information. More... | |
typedef struct maze_navigator_state | maze_navigator_state_t |
This struct contains the state of a navigator in the maze. | |
typedef struct maze_point | maze_point_t |
This struct contains the coordinates of a point. More... | |
Enumerations | |
enum | maze_cardinal_direction_t { MAZE_NORTH = 0 , MAZE_EAST = 1 , MAZE_SOUTH = 2 , MAZE_WEST = 3 , MAZE_NONE = 255 } |
This enum contains the possible directions. More... | |
enum | maze_relative_direction_t { MAZE_FRONT , MAZE_RIGHT , MAZE_BACK , MAZE_LEFT } |
This enum contains the relative directions of instructions from the navigator's perspective. More... | |
enum | maze_wall_direction_t { MAZE_NO_WALLS = 0 , MAZE_FRONT_WALL = 1 , MAZE_RIGHT_WALL = 2 , MAZE_BACK_WALL = 4 , MAZE_LEFT_WALL = 8 } |
This enum contains bitmasks for the walls. Useful when updating more than one wall at a time. More... | |
Functions | |
void | maze_clear_heuristics (maze_grid_t *p_grid) |
Clears the maze heuristics. This sets the F, G, and H values of each node to UINT32_MAX for the A* and floodfill algorithm. More... | |
maze_grid_t | maze_create (uint16_t rows, uint16_t columns) |
Create a maze with the specified number of rows and columns. More... | |
int16_t | maze_deserialise (maze_grid_t *p_grid, maze_gap_bitmask_t *p_no_walls_array) |
Deserialises the maze from a bitmask array. maze_serialise. More... | |
void | maze_destroy (maze_grid_t *p_grid) |
Destroys the maze by freeing the memory allocated to the grid array. More... | |
maze_grid_cell_t * | maze_get_cell_at_coords (maze_grid_t *p_grid, const maze_point_t *p_coordinates) |
Get the cell at the specified coordinates. More... | |
maze_grid_cell_t * | maze_get_cell_in_dir (maze_grid_t *p_grid, maze_grid_cell_t *p_from, maze_cardinal_direction_t direction) |
Get the cell in the specified direction from a specific cell. More... | |
maze_cardinal_direction_t | maze_get_dir_from_to (const maze_point_t *p_point_a, const maze_point_t *p_point_b) |
Get the direction from p_point_a to p_point_b if they are adjacent. More... | |
int8_t | maze_get_nav_dir_offset (const maze_navigator_state_t *p_navigator) |
Get the offset from the navigator's current direction to any other possible direction. More... | |
maze_relative_direction_t | maze_get_relative_dir (const maze_cardinal_direction_t direction_from, const maze_cardinal_direction_t direction_to) |
Gets the relative direction from the current direction to the desired cardinal direction. More... | |
char * | maze_get_string (maze_grid_t *p_grid) |
Get the string representation of the maze for pretty printing. More... | |
void | maze_initialise_empty_walled (maze_grid_t *p_grid) |
Initialises an empty maze. This sets the coordinates of each node, all heuristic values to 0, and all pointers to NULL. This is useful for the A* algorithm. More... | |
void | maze_insert_nav_str (const maze_grid_t *p_grid, const maze_navigator_state_t *p_navigator, char *maze_str) |
Inserts the navigator character into the maze string for pretty printing. More... | |
uint32_t | maze_manhattan_dist (const maze_point_t *p_point_a, const maze_point_t *p_point_b) |
Calculates the manhattan distance between two points. More... | |
void | maze_nav_modify_walls (maze_grid_t *p_grid, maze_navigator_state_t *p_navigator, uint8_t aligned_wall_bitmask, bool is_set, bool is_unset) |
Modifies the walls of the navigator's current node. More... | |
int16_t | maze_nav_to_buffer (const maze_navigator_state_t *p_navigator, uint8_t *p_buffer, uint16_t buffer_size) |
Serialises the navigator state into a uint8_t buffer. The buffer is set with the navigator's coordinates, orientation, start node, and end node coordinates in that order. More... | |
maze_gap_bitmask_t | maze_serialise (maze_grid_t *p_grid) |
Serialises the maze into a bitmask array. maze_deserialise. More... | |
int16_t | maze_serialised_to_buffer (const maze_gap_bitmask_t *p_bitmask, uint8_t *p_buffer, uint16_t buffer_size) |
Serialises the maze into a uint8_t buffer. More... | |
void | maze_uint16_to_uint8_buffer (uint16_t value, uint8_t *p_buffer) |
Helper function to convert a uint16_t to a uint8_t buffer. More... | |
Header file for the maze data structure and public functions.
#define MAZE_INVERT_BITMASK | ( | x | ) | ((0xFu - x) & 0xFu) |
This macro inverts an 4-bit bitmask.
[in] | x | Bitmask to invert. |
typedef struct maze_grid_cell maze_grid_cell_t |
This struct contains the node information.
typedef struct maze_grid maze_grid_t |
This struct contains the maze grid information.
typedef struct maze_point maze_point_t |
This struct contains the coordinates of a point.
This enum contains bitmasks for the walls. Useful when updating more than one wall at a time.
Enumerator | |
---|---|
MAZE_NO_WALLS | No walls. |
MAZE_FRONT_WALL | Front wall. |
MAZE_RIGHT_WALL | Right wall. |
MAZE_BACK_WALL | Back wall. |
MAZE_LEFT_WALL | Left wall. |
void maze_clear_heuristics | ( | maze_grid_t * | p_grid | ) |
Clears the maze heuristics. This sets the F, G, and H values of each node to UINT32_MAX for the A* and floodfill algorithm.
[in,out] | p_grid | Pointer to the maze grid. |
References maze_grid::columns, maze_grid_cell::f, maze_grid_cell::g, maze_grid_cell::h, maze_grid_cell::is_visited, maze_grid::p_grid_array, and maze_grid::rows.
maze_grid_t maze_create | ( | uint16_t | rows, |
uint16_t | columns | ||
) |
Create a maze with the specified number of rows and columns.
[in] | rows | Number of rows in the maze. |
[in] | columns | Number of columns in the maze. |
References maze_initialise_empty_walled().
int16_t maze_deserialise | ( | maze_grid_t * | p_grid, |
maze_gap_bitmask_t * | p_no_walls_array | ||
) |
Deserialises the maze from a bitmask array. maze_serialise.
[in,out] | p_grid | Pointer to the maze grid. |
[in] | p_no_walls_array | Pointer to the bitmask array of maze gaps. |
References maze_grid::columns, maze_gap_bitmask::columns, maze_gap_bitmask::p_bitmask, maze_grid::p_grid_array, maze_grid::rows, and maze_gap_bitmask::rows.
void maze_destroy | ( | maze_grid_t * | p_grid | ) |
Destroys the maze by freeing the memory allocated to the grid array.
[in,out] | p_grid | Pointer to the maze grid. |
References maze_grid::columns, maze_grid::p_grid_array, and maze_grid::rows.
maze_grid_cell_t * maze_get_cell_at_coords | ( | maze_grid_t * | p_grid, |
const maze_point_t * | p_coordinates | ||
) |
Get the cell at the specified coordinates.
[in] | p_grid | Pointer to the maze grid. |
[in] | p_coordinates | Pointer to the coordinates. |
References maze_grid::columns, maze_grid::p_grid_array, maze_grid::rows, maze_point::x, and maze_point::y.
maze_grid_cell_t * maze_get_cell_in_dir | ( | maze_grid_t * | p_grid, |
maze_grid_cell_t * | p_from, | ||
maze_cardinal_direction_t | direction | ||
) |
Get the cell in the specified direction from a specific cell.
[in] | p_grid | Pointer to the maze grid. |
[in] | p_from | Pointer to the cell to get the next cell from. |
[in] | direction | Cardinal direction to get the next cell from. |
References maze_grid_cell::coordinates, MAZE_EAST, maze_get_cell_at_coords(), MAZE_NORTH, MAZE_SOUTH, MAZE_WEST, maze_point::x, and maze_point::y.
maze_cardinal_direction_t maze_get_dir_from_to | ( | const maze_point_t * | p_point_a, |
const maze_point_t * | p_point_b | ||
) |
Get the direction from p_point_a to p_point_b if they are adjacent.
[in] | p_point_a | Pointer to point a. |
[in] | p_point_b | Pointer to point b. |
References MAZE_EAST, MAZE_NONE, MAZE_NORTH, MAZE_SOUTH, MAZE_WEST, maze_point::x, and maze_point::y.
int8_t maze_get_nav_dir_offset | ( | const maze_navigator_state_t * | p_navigator | ) |
Get the offset from the navigator's current direction to any other possible direction.
[in] | p_navigator | Pointer to the navigator. |
References maze_navigator_state::orientation.
maze_relative_direction_t maze_get_relative_dir | ( | const maze_cardinal_direction_t | direction_from, |
const maze_cardinal_direction_t | direction_to | ||
) |
Gets the relative direction from the current direction to the desired cardinal direction.
direction_from | Cardinal direction to get the relative direction from. |
direction_to | Cardinal direction to get the relative direction to. |
char * maze_get_string | ( | maze_grid_t * | p_grid | ) |
Get the string representation of the maze for pretty printing.
[in] | p_grid | Pointer to the maze grid. |
References maze_grid::columns, maze_grid::p_grid_array, and maze_grid::rows.
void maze_initialise_empty_walled | ( | maze_grid_t * | p_grid | ) |
Initialises an empty maze. This sets the coordinates of each node, all heuristic values to 0, and all pointers to NULL. This is useful for the A* algorithm.
[in,out] | p_grid | Pointer to an empty maze created by maze_create. |
References maze_grid::columns, maze_grid_cell::coordinates, maze_grid_cell::f, maze_grid_cell::g, maze_grid_cell::h, maze_grid_cell::is_visited, maze_grid_cell::p_came_from, maze_grid::p_grid_array, maze_grid_cell::p_next, and maze_grid::rows.
void maze_insert_nav_str | ( | const maze_grid_t * | p_grid, |
const maze_navigator_state_t * | p_navigator, | ||
char * | p_maze_str | ||
) |
Inserts the navigator character into the maze string for pretty printing.
[in] | p_grid | Pointer to the maze grid. |
[in] | p_navigator | Pointer to the navigator. |
[in,out] | p_maze_str | Pointer to the maze string returned by maze_get_string. |
References maze_grid::columns, maze_grid_cell::coordinates, MAZE_EAST, MAZE_NORTH, MAZE_SOUTH, MAZE_WEST, maze_navigator_state::orientation, maze_navigator_state::p_current_node, maze_point::x, and maze_point::y.
uint32_t maze_manhattan_dist | ( | const maze_point_t * | p_point_a, |
const maze_point_t * | p_point_b | ||
) |
Calculates the manhattan distance between two points.
[in] | p_point_a | Pointer to first point. |
[in] | p_point_b | Pointer to second point. |
References maze_point::x, and maze_point::y.
void maze_nav_modify_walls | ( | maze_grid_t * | p_grid, |
maze_navigator_state_t * | p_navigator, | ||
uint8_t | aligned_wall_bitmask, | ||
bool | is_set, | ||
bool | is_unset | ||
) |
Modifies the walls of the navigator's current node.
[in,out] | p_grid | Pointer to the maze grid. |
[in] | p_navigator | Pointer to the navigator. |
[in] | aligned_wall_bitmask | Bitmask of the walls to set or unset. This is aligned to MAZE_NORTH. |
[in] | is_set | True if the walls are to be set. |
[in] | is_unset | True if the walls are to be unset. |
References maze_navigator_state::p_current_node.
int16_t maze_nav_to_buffer | ( | const maze_navigator_state_t * | p_navigator, |
uint8_t * | p_buffer, | ||
uint16_t | buffer_size | ||
) |
Serialises the navigator state into a uint8_t buffer. The buffer is set with the navigator's coordinates, orientation, start node, and end node coordinates in that order.
p_navigator | Pointer to the navigator state. |
p_buffer | Pointer to the buffer. |
buffer_size | Length of the buffer for checks. |
References maze_grid_cell::coordinates, maze_uint16_to_uint8_buffer(), maze_navigator_state::orientation, maze_navigator_state::p_current_node, maze_navigator_state::p_end_node, maze_navigator_state::p_start_node, maze_point::x, and maze_point::y.
maze_gap_bitmask_t maze_serialise | ( | maze_grid_t * | p_grid | ) |
Serialises the maze into a bitmask array. maze_deserialise.
[in] | p_grid | Pointer to the maze grid. |
References maze_grid::columns, maze_gap_bitmask::p_bitmask, maze_grid::p_grid_array, maze_grid_cell::p_next, and maze_grid::rows.
int16_t maze_serialised_to_buffer | ( | const maze_gap_bitmask_t * | p_bitmask, |
uint8_t * | p_buffer, | ||
uint16_t | buffer_size | ||
) |
Serialises the maze into a uint8_t buffer.
p_bitmask | Pointer to the maze gap bitmask. |
p_buffer | Pointer to the buffer. |
buffer_size | Size of the buffer. |
References maze_bitmask_compressed::bits, maze_gap_bitmask::columns, maze_uint16_to_uint8_buffer(), and maze_gap_bitmask::rows.
void maze_uint16_to_uint8_buffer | ( | uint16_t | value, |
uint8_t * | p_buffer | ||
) |
Helper function to convert a uint16_t to a uint8_t buffer.
value | Value to convert. |
p_buffer | uint8_t buffer of size 2. |