-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.h
73 lines (55 loc) · 1.36 KB
/
game.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include<stdio.h>
#include<pthread.h>
#define ANSI_COLOR_RED "\x1b[31m"
#define ANSI_COLOR_GREEN "\x1b[32m"
#define ANSI_COLOR_RESET "\x1b[0m"
typedef int * Array;
typedef int ** Matrix;
typedef struct vector {
int di, dj;
} Vector;
typedef struct cell {
int i, j;
int di, dj;
} Cell;
typedef Cell * Snake;
typedef struct dirchange {
int di, dj, index;
} Dirchange;
typedef struct node {
Dirchange change;
struct node *next;
} Node;
typedef struct apple_node {
int i, j;
struct apple_node *next;
} AppleNode;
typedef struct queue {
Node *head;
Node *tail;
} Queue;
typedef Vector Apple;
typedef struct game {
AppleNode *apples;
Snake s;
Queue q;
pthread_mutex_t lock;
int changes_len;
int rows, columns;
int len;
int collision_detected;
} Game;
void init_game(Game *g, int rows, int columns, int start_len);
void init_cell(Cell *c, int i, int j, int di, int dj);
void init_queue(Queue *q);
Node *create_node(Dirchange change);
void enqueue(Queue *q, Dirchange change);
Dirchange peak(Queue *q);
Dirchange dequeue(Queue *q);
int is_empty(Queue *q);
int length(Game *g);
int occupied_by_snake(Game *g, int i, int j);
int occupied_by_apple(Game *g, int i, int j);
void add_random_apple(Game *g);
void add_random_apple_with_possibility(Game *g, int bound, int attempts);
void step_back(Game *g);