-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaze.h
54 lines (38 loc) · 981 Bytes
/
maze.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef INCLUDED_MAZE
#define INCLUDE_MAZE
#include <stddef.h>
#include <stdbool.h>
typedef enum {LEFT, TOP, RIGHT, BOTTOM} Direction;
#define DIR_MASK(dir) ( 1<<(dir) )
typedef enum {
LEFTm = DIR_MASK(LEFT),
TOPm = DIR_MASK(TOP),
RIGHTm = DIR_MASK(RIGHT),
BOTTOMm = DIR_MASK(BOTTOM)
} DirectionMask;
typedef struct QueueNode {
size_t i, j;
Direction dir;
struct QueueNode* next;
} QueueNode;
typedef struct {
QueueNode *head, *cur, *tail;
} Queue;
typedef struct {
unsigned ways :4,
visited :1;
} Cell;
typedef struct {
size_t w, h;
size_t unvisited_count;
Cell** cells;
Queue moves;
} Maze;
Maze* maze_generate(size_t w, size_t h);
void maze_delete(Maze* maze);
void maze_print(const Maze* maze, bool print_header);
void maze_print_skeletton(const Maze* maze, bool print_header);
bool queue_is_empty(const Queue* queue);
void queue_pop(size_t* i, size_t* j, Direction* dir, Queue* queue);
void queue_rewind(Queue* queue);
#endif