-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtesteval.c
More file actions
executable file
·133 lines (105 loc) · 3.2 KB
/
testeval.c
File metadata and controls
executable file
·133 lines (105 loc) · 3.2 KB
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
131
132
133
#include <stdio.h>
#include <string.h>
#include "checkers.h"
/* function prototypes */
bitboard possible_moves(bitboard *board); // Returns possible moves for a field
void print_numbers(); // Prints out the field numbers for orientation
int main(int argc, char *argv[])
{
printf("here we go...\n");
int val;
bitboard b[N_BOARDS];
char *filename = "starts/testeval.wdp";
bool color=WHITE;
bool *colorp;
colorp = &color;
if (argc>1)
read_wdp(b, argv[1], colorp);
else
read_wdp(b, filename, colorp);
val = eval(b, color);
printf("\nTotal evaluation: %d\n\n", val);
printf("\nCurrent board:\n");
print_board(b);
printf("\nThreatened by white:\n");
bitboard x[N_BOARDS];
x[WHITE] = threatened(b, T_WHITE);
x[BLACK] = 0;
x[KING] = 0;
print_board(x);
printf("\nThreatened by black:\n");
x[WHITE] = 0;
x[BLACK] = threatened(b, T_BLACK);
print_board(x);
printf("\nFields to move to:\n");
x[WHITE] = possible_moves(b);
x[BLACK] = 0;
print_board(x);
}
/*
* possible_moves
*
* Computes a mask with those fields marked which existing bricks can move to
*
* Needs: Board configuration *board
*
* Returns: The mask
*/
bitboard possible_moves(bitboard *board)
{
const bitboard empty = ~(board[WHITE] | board[BLACK]);
bitboard to = board[BLACK]|board[WHITE];
bitboard retmask=0; /* Mask to return */
bitboard next=0, /* Mask to the current brick */
down=0, /* Mask to down neighbor */
up=0; /* Mask to up neighbor */
int i=0;
while (to) {
next = LAST_ONE(to);
for (i = 0; i < N_DIRS; i++) { /* Check both directions (NW/SE & NE/SW) */
/* Determine neighbors; down and up will be zero if the current brick
cannot move into this direction */
down = DOWN_NEIGHBOR((next&board[BLACK]) |
(next&board[WHITE]&board[KING]), i);
up = UP_NEIGHBOR((next&board[WHITE]) |
(next&board[BLACK]&board[KING]), i);
/* Add down neighbor if the brick can move downwards and the field is
either empty or occupied by an enemy and the field behind is empty. */
if (down & empty) {
retmask |= down;
} else {
if (((next&board[BLACK] && down&board[WHITE]) ||
(next&board[WHITE] && down&board[BLACK])) &&
(DOWN_NEIGHBOR(down, i) & empty))
retmask |= DOWN_NEIGHBOR(down, i);
}
/* Add up neighbor if the brick can move upwards and the field is
either empty or occupied by an enemy and the field behind is empty. */
if (up & empty) {
retmask |= up;
} else {
if (((next&board[BLACK] && up&board[WHITE]) ||
(next&board[WHITE] && up&board[BLACK])) &&
(UP_NEIGHBOR(up, i) & empty))
retmask |= UP_NEIGHBOR(up, i);
}
}
to ^= next;
}
return retmask;
}
/*
* print_numbers
*
* Prints out a numbered checkers board for orientation
*/
void print_numbers()
{
int i=0;
for (i=0; i<BOARD_SIZE; i++) {
if (((i)%4 == 0) && ((i)/4)%2 == 0) printf(" ");
printf("%2d", i+1);
printf(" ");
if (i%4 == 3) printf("\n");
}
}