-
Notifications
You must be signed in to change notification settings - Fork 0
/
place_stone_recersively.c
141 lines (128 loc) · 4.73 KB
/
place_stone_recersively.c
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
134
135
136
137
138
139
140
141
#include "gomoku.h"
// 在copy上落子或者取消落子
void place_stone_on_copy(int row, int col, int stone)
{
int i, j, pattern;
int temp_r, temp_c;
// 如果在棋盘外就不进行操作 (在minimax搜索的时候有用, 因为root的点是(-1,-1), 在界外的)
if (row < 0 || row >= BOARD_SIZE || col < 0 || col >= BOARD_SIZE)
return;
// 复制的棋盘
chessboard_copy[row][col] = stone;
// 打分用的六元组: 横向
for (i = max(0, col - TUPLE_NUMB + 1); i < min(TUPLE_SIZE, col + 1); i++)
{
temp_c = col - i;
tuple_copy_hori[row][temp_c][i] = stone;
pattern = 0;
for (j = 0; j < TUPLE_SIZE; j++) // 将每一个六元组按照八进制存储
{
pattern <<= 3;
pattern += tuple_copy_hori[row][temp_c][j];
}
point_copy_hori[row][temp_c] = get_grade_for_tuple(pattern);
}
// 打分用的六元组: 左下-右上
for (i = max(max(0, col - TUPLE_NUMB + 1), TUPLE_SIZE - 1 - row); i < min(min(TUPLE_SIZE, col + 1), BOARD_SIZE - row); i++)
{
temp_r = row - 5 + i;
temp_c = col - i;
tuple_copy_topr[temp_r][temp_c][i] = stone;
pattern = 0;
for (j = 0; j < TUPLE_SIZE; j++) // 将每一个六元组按照八进制存储
{
pattern <<= 3;
pattern += tuple_copy_topr[temp_r][temp_c][j];
}
point_copy_topr[temp_r][temp_c] = get_grade_for_tuple(pattern);
}
// 打分用的六元组: 纵向
for (i = max(0, row - TUPLE_NUMB + 1); i < min(TUPLE_SIZE, row + 1); i++)
{
temp_r = row - i;
tuple_copy_vert[temp_r][col][i] = stone;
pattern = 0;
for (j = 0; j < TUPLE_SIZE; j++) // 将每一个六元组按照八进制存储
{
pattern <<= 3;
pattern += tuple_copy_vert[temp_r][col][j];
}
point_copy_vert[temp_r][col] = get_grade_for_tuple(pattern);
}
// 打分用的六元组: 左上-右下
for (i = max(max(0, col - TUPLE_NUMB + 1), row - TUPLE_NUMB + 1); i < min(min(TUPLE_SIZE, col + 1), row + 1); i++)
{
temp_r = row - i;
temp_c = col - i;
tuple_copy_topl[temp_r][temp_c][i] = stone;
pattern = 0;
for (j = 0; j < TUPLE_SIZE; j++) // 将每一个六元组按照八进制存储
{
pattern <<= 3;
pattern += tuple_copy_topl[temp_r][temp_c][j];
}
point_copy_topl[temp_r][temp_c] = get_grade_for_tuple(pattern);
}
}
// 在真正的棋盘上落子或者取消落子
void place_stone_player(int row, int col, int stone)
{
int i, j, pattern;
int temp_r, temp_c;
// 复制的棋盘
inner_board_now[row][col] = stone;
// 打分用的六元组: 横向
for (i = max(0, col - TUPLE_NUMB + 1); i < min(TUPLE_SIZE, col + 1); i++)
{
temp_c = col - i;
tuple_set_hori[row][temp_c][i] = stone;
pattern = 0;
for (j = 0; j < TUPLE_SIZE; j++) // 将每一个六元组按照八进制存储
{
pattern <<= 3;
pattern += tuple_set_hori[row][temp_c][j];
}
point_hori[row][temp_c] = get_grade_for_tuple(pattern);
}
// 打分用的六元组: 左下-右上
for (i = max(max(0, col - TUPLE_NUMB + 1), TUPLE_SIZE - 1 - row); i < min(min(TUPLE_SIZE, col + 1), BOARD_SIZE - row); i++)
{
temp_r = row - 5 + i;
temp_c = col - i;
tuple_set_topr[temp_r][temp_c][i] = stone;
pattern = 0;
for (j = 0; j < TUPLE_SIZE; j++) // 将每一个六元组按照八进制存储
{
pattern <<= 3;
pattern += tuple_set_topr[temp_r][temp_c][j];
}
point_topr[temp_r][temp_c] = get_grade_for_tuple(pattern);
}
// 打分用的六元组: 纵向
for (i = max(0, row - TUPLE_NUMB + 1); i < min(TUPLE_SIZE, row + 1); i++)
{
temp_r = row - i;
tuple_set_vert[temp_r][col][i] = stone;
pattern = 0;
for (j = 0; j < TUPLE_SIZE; j++) // 将每一个六元组按照八进制存储
{
pattern <<= 3;
pattern += tuple_set_vert[temp_r][col][j];
}
point_vert[temp_r][col] = get_grade_for_tuple(pattern);
}
// 打分用的六元组: 左上-右下
for (i = max(max(0, col - TUPLE_NUMB + 1), row - TUPLE_NUMB + 1); i < min(min(TUPLE_SIZE, col + 1), row + 1); i++)
{
temp_r = row - i;
temp_c = col - i;
tuple_set_topl[temp_r][temp_c][i] = stone;
pattern = 0;
for (j = 0; j < TUPLE_SIZE; j++) // 将每一个六元组按照八进制存储
{
pattern <<= 3;
pattern += tuple_set_topl[temp_r][temp_c][j];
}
point_topl[temp_r][temp_c] = get_grade_for_tuple(pattern);
}
}