-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.js
124 lines (124 loc) · 2.72 KB
/
check.js
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
function check_able(pos, tar){
if (check_up(pos, tar)||check_down(pos, tar)||check_left(pos, tar)||check_right(pos, tar)||check_leftup(pos, tar)||check_leftdown(pos, tar)||check_rightup(pos, tar)||check_rightdown(pos, tar)) {
return true;
} else {
return false;
}
}
function check_up(pos, tar){
if (((pos>=0)&&(pos<=7))||(chessboard[pos]!='0')) {
return false;
}
find=pos-8;
limit=pos%8;
while ((find>=limit)&&(chessboard[find]==3-tar)) {
find-=8;
}
if ((find>=limit)&&(chessboard[find]==tar)&&(pos-find!=8)) {
return find;
} else {
return false;
}
}
function check_down(pos, tar){
if (((pos>=56)&&(pos<=63))||(chessboard[pos]!='0')) {
return false;
}
find=pos-(-8);
limit=56+pos%8;
while ((find<=limit)&&(chessboard[find]==3-tar)) {
find-=(-8);
}
if ((find<=limit)&&(chessboard[find]==tar)&&(find-pos!=8)) {
return find;
} else {
return false;
}
}
function check_left(pos, tar){
if ((pos%8==0)||(chessboard[pos]!='0')) {
return false;
}
find=pos-1;
limit=pos-pos%8;
while ((find>=limit)&&(chessboard[find]==3-tar)) {
find-=1;
}
if ((find>=limit)&&(chessboard[find]==tar)&&(pos-find!=1)) {
return find;
} else {
return false;
}
}
function check_right(pos, tar){
if ((pos%8==7)||(chessboard[pos]!='0')) {
return false;
}
find=pos-(-1);
limit=Math.floor(1+pos/8)*8-1;
while ((find<=limit)&&(chessboard[find]==3-tar)) {
find-=(-1);
}
// alert(limit+"."+find);
if ((find<=limit)&&(chessboard[find]==tar)&&(find-pos!=1)) {
return find;
} else {
return false;
}
}
function check_leftup(pos, tar){
if ((pos%8==0)||(pos<=7)||(chessboard[pos]!='0')) {
return false;
}
find=pos-9;
while ((find>7)&&(find%8!=0)&&(chessboard[find]==3-tar)) {
find-=9;
}
if ((find>7)&&(find%8!=0)&&(chessboard[find]==tar)&&(pos-find!=9)) {
return find;
} else {
return false;
}
}
function check_leftdown(pos, tar){
if ((pos%8==0)||(pos>=57)||(chessboard[pos]!='0')) {
return false;
}
find=pos-(-7);
while ((find<57)&&(find%8!=0)&&(chessboard[find]==3-tar)) {
find-=(-7);
}
if ((find<57)&&(find%8!=0)&&(chessboard[find]==tar)&&(find-pos!=7)) {
return find;
} else {
return false;
}
}
function check_rightup(pos, tar){
if ((pos%8==7)||(pos<7)||(chessboard[pos]!='0')) {
return false;
}
find=pos-7;
while ((find>=7)&&(find%8!=7)&&(chessboard[find]==3-tar)) {
find-=7;
}
if ((find>=7)&&(find%8!=7)&&(chessboard[find]==tar)&&(pos-find!=7)) {
return find;
} else {
return false;
}
}
function check_rightdown(pos, tar){
if ((pos%8==7)||(pos>=56)||(chessboard[pos]!='0')) {
return false;
}
find=pos-(-9);
while ((find<56)&&(find%8!=7)&&(chessboard[find]==3-tar)) {
find-=(-9);
}
if ((find<56)&&(find%8!=7)&&(chessboard[find]==tar)&&(find-pos!=9)) {
return find;
} else {
return false;
}
}