-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposition.h
59 lines (49 loc) · 1.44 KB
/
position.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
#ifndef c4_position_h
#define c4_position_h
#include <stdint.h>
#define WIDTH 7
#define HEIGHT 6
#define MIN -(WIDTH * HEIGHT) / 2 + 3
#define MAX (WIDTH * HEIGHT) / 2 - 3
typedef struct position {
uint_fast64_t pos; // width * (height + 1) size bit mask containing one player's moves
uint_fast64_t mask; // contains both players' moves, used with pos to get the position
uint_fast64_t key;
} position;
/*
* checks if a column can be played
* column: 0-indexed column number from the left to play
* position: position to play in
*/
int playable(int column, position *pos);
/*
* plays a piece in the given column for the current player
* column: 0-indexed column number from the left to play
* position: position to play in
*/
void play(int column, position **pos);
/*
* checks if a position has been won
* position: position to play in
*/
int check_win(position *pos);
/*
* Checks if playing a move in a given column will win the game
* column: the column to play the move in
* position: the position to evaluate
*/
int check_will_win(int column, position *pos);
/*
* checks the number of moves played so far
* position: position to check
*/
int num_moves(position *pos);
/*
* Generates the best order in which to check columns for good moves
* Example output with width of 7: [3, 2, 4, 1, 5, 0, 6]
* width: number of columns to arrange
*/
int * generate_column_order(int width);
uint_fast64_t top_mask();
uint_fast64_t bottom_mask();
#endif