-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheckers.h
130 lines (107 loc) · 4.44 KB
/
checkers.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#ifndef HEADER
#define HEADER
#include <stdbool.h>
#define ll long long
typedef struct board game_state; //game state
typedef struct pieces pawn;
typedef struct undo_stack log;
typedef struct node node;
#define topRight 1
#define bottomRight 2
#define topLeft 3
#define bottomLeft 4
// WHITE = 15, BLACK = 0;
//At start of game white occupies row 0,1,2 and black occupies row 5,6,7.
int difficulty = 0; // 0 - hardest, 1 - medium , 2 - easy
#define sb 8 //size of board
const int tp = (sb / 2) * ((sb - 2) / 2); // total pieces
#define colorFlip(i) (i ^ (1 << 0) ^ (1 << 1) ^ (1 << 2) ^ (1 << 3))
// if i is WHITE, converts it to black and vice-versa
int bot_mode = WHITE; // -1: 2 player mode ; 0: Black is bot ; 15: White is bot
typedef struct
{
int score;
int index;
} nodeb; //this struct is for bot heap implementation
struct pieces
{
int x;
int y;
int allegiance; // Whose team is it on?
bool is_king; // Is it king yet?
};
typedef struct coords
{
int x;
int y;
} coords;
struct board
{
pawn white[(sb / 2) * ((sb - 2) / 2)]; // stores info about 12 white elements
pawn black[(sb / 2) * ((sb - 2) / 2)]; // stores info about 12 black elements
coords hover[2];
int cur_turn; // Whose turn is it at this particular state // 0 is for black , 15 is for white
};
struct node
{
node *array[(sb / 2) * ((sb - 2) / 2)][4]; // at each turn , at max all 12 pieces of that color can move in at max 4 dirn
node *next_board;
node *prev_board; // will store address of previous posn
game_state board; // will store the current board
int depth; // will store the depth of each node from root node(depth ==0)
};
struct undo_stack // stores the data using doubly linked list
{
game_state g;
struct undo_stack *next;
struct undo_stack *prev;
};
typedef struct he
{
int index;
ll d;
} he;
game_state c_state;
bool is_multi_capture_possible(game_state g); // to check if multiple captures are possible while calculating score by bot
void start(log *head);
void restart(log *head);
void Quit(log *head);
void menu(log *head);
void draw(game_state *g, log *head);
int toss(void);
void instruction();
void clear_stack(log *head); // used in restart function to empty the stack
//update board
// horizontal and vertical will tell in which direction we have to move the pawn p
bool move_entries(game_state *g, pawn p, int horizontal, int vertical); // Function to move one of the pawns
bool isOccupied(game_state *g, int x, int y); // checks if coordinates (x ,y) are occupied on board
bool is_present(game_state *g, pawn P); // returns true if P is present on board
bool capturePossible(game_state *g, pawn P, int direction);
// checks if capture is possible from P in a direction
// direction can be one of the four: topLeft, bottomLeft, topRight and bottomRight
bool simple_Move_Possible(game_state *g, pawn P, int direction);
log *CreateEmptyStackNode();
void push(log *head, game_state *preState);
void print_board(game_state *P);
game_state undo(log *head); // undo the last move taken
void review(log *head); // prints all the boards in the game
void add_board(game_state p, log *head); // after every move , add game state to it
void rule(void); //just prints rule book
bool isLegal(pawn p, pawn new_pos, game_state *g); // returns true if a move from coordinates of p to coordinates of new_pos is "legal"
void result(game_state *P, log *head); //tells the result of the game // will simply print a string
void print_all_possible_next_move(node *current); // given a game state , what all possible can be achieved in next move
void point_to_null(node *p); // take ptr to node and initialize each of its child to null
void reached_how(node *final); // will tell how we reached a particular board position // every node contains address of its parent node
void filling_node(node *current, game_state p, int k);
// takes a node , find which colors turn it is , and then fills the array accodingly if the move can be played by that color
void print_k_state(game_state p, int k);
void controller(log *head);
void siftup(int index);
void DownHeap(int index);
void insert(he elem);
he Extract_max();
long double bot_helperb(game_state g_o, int lim);
void botb();
long double bot_helperw(game_state g_o, int lim);
void botw();
#endif