-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJudge.cpp
executable file
·81 lines (69 loc) · 1.92 KB
/
Judge.cpp
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
#include "Judge.h"
static bool rowWin(const short row) {
const short row1 = row & (row << 1);
const short row2 = row1 & (row1 << 2);
return row2;
}
static bool get(const Board &board, const int x, const int y, const char p) {
return (board.rows[x] >> ((p - 1) * 16)) & (1 << y);
}
bool win(const int x, const int y, const int M, const int N, const Board &board, const char p) {
//横向检测
int i, j;
const short row = board.rows[x] >> ((p - 1) * 16);
if (rowWin(row)) {
return true;
}
/*
* 0000ABCXDEF0
* 000ABCXDEF00
* 00ABCXDEF000
* 0ABCXDEF0000
*/
//纵向检测
const short col = board.cols[y] >> ((p - 1) * 16);
if (rowWin(col)) {
return true;
}
//左下-右上
int count = 0;
for (i = x, j = y; i < M && j >= 0; i++, j--)
if (!get(board, i, j, p))
break;
count += (y - j);
for (i = x, j = y; i >= 0 && j < N; i--, j++)
if (!get(board, i, j, p))
break;
count += (j - y - 1);
if (count >= 4)
return true;
//左上-右下
count = 0;
for (i = x, j = y; i >= 0 && j >= 0; i--, j--)
if (!get(board, i, j, p))
break;
count += (y - j);
for (i = x, j = y; i < M && j < N; i++, j++)
if (!get(board, i, j, p))
break;
count += (j - y - 1);
if (count >= 4)
return true;
return false;
}
bool win(const int x, const int y, const HeavyBoard &board, const char p) {
return rowWin(board.rows[x] >> ((p - 1) * 16)) ||
rowWin(board.cols[y] >> ((p - 1) * 16)) ||
rowWin(board.slanted_left[x + y] >> ((p - 1) * 16)) ||
rowWin(board.slanted_right[x - y + 11] >> ((p - 1) * 16));
}
bool isTie(const int N, const char *top) {
bool tie = true;
for (int i = 0; i < N; i++) {
if (top[i] > 0) {
tie = false;
break;
}
}
return tie;
}