-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreverse.cpp
116 lines (114 loc) · 2.43 KB
/
reverse.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
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
#include<iostream>
using namespace std;
extern short now[][9];
extern short record[][9][9];
extern int turns;
bool my_reverse(int i,int j)//翻转棋子
{
bool judge=0;//1表示有翻转,0表示无翻转
short color=now[i][j];
int i_search=i,j_search=j;
int m=0,n=0;
//翻转下面
i_search++;
while((i_search<9)&&(now[i_search][j]==3-color))
i_search++;
if((i_search<9)&&(now[i_search][j]==color))
{
for(m=i+1;m<i_search;m++)
{
judge=1;
now[m][j]=3-now[m][j];
}
}
//翻转上面
i_search=i;
i_search--;
while((i_search>0)&&(now[i_search][j]==3-color))
i_search--;
if((i_search>0)&&(now[i_search][j]==color))
{
for(m=i-1;m>i_search;m--)
{
judge=1;
now[m][j]=3-now[m][j];
}
}
//翻转右面
j_search++;
while((j_search<9)&&(now[i][j_search]==3-color))
j_search++;
if((j_search<9)&&(now[i][j_search]==color))
{
for(n=j+1;n<j_search;n++)
{
judge=1;
now[i][n]=3-now[i][n];
}
}
//翻转左面
j_search=j-1;
while((j_search>0)&&(now[i][j_search]==3-color))
j_search--;
if((j_search>0)&&(now[i][j_search]==color))
{
for(n=j-1;n>j_search;n--)
{
judge=1;
now[i][n]=3-now[i][n];
}
}
//翻转左上
i_search=i-1;
j_search=j-1;
while((j_search>0)&&(i_search>0)&&(now[i_search][j_search]==3-color))
{i_search--;j_search--;}
if((j_search>0)&&(i_search>0)&&(now[i_search][j_search]==color))
{
for(m=i-1,n=j-1;m>i_search,n>j_search;m--,n--)
{
judge=1;
now[m][n]=3-now[m][n];
}
}
//翻转右上
i_search=i-1;
j_search=j+1;
while((j_search<9)&&(i_search>0)&&(now[i_search][j_search]==3-color))
{i_search--;j_search++;}
if((j_search<9)&&(i_search>0)&&(now[i_search][j_search]==color))
{
for(m=i-1,n=j+1;m>i_search,n<j_search;m--,n++)
{
judge=1;
now[m][n]=3-now[m][n];
}
}
//翻转右下
i_search=i+1;
j_search=j+1;
while((j_search<9)&&(i_search<9)&&(now[i_search][j_search]==3-color))
{i_search++;j_search++;}
if((j_search<9)&&(i_search<9)&&(now[i_search][j_search]==color))
{
for(m=i+1,n=j+1;m<i_search,n<j_search;m++,n++)
{
judge=1;
now[m][n]=3-now[m][n];
}
}
//翻转左下
i_search=i+1;
j_search=j-1;
while((j_search>0)&&(i_search<9)&&(now[i_search][j_search]==3-color))
{i_search++;j_search--;}
if((j_search>0)&&(i_search<9)&&(now[i_search][j_search]==color))
{
for(m=i+1,n=j-1;m<i_search,n>j_search;m++,n--)
{
judge=1;
now[m][n]=3-now[m][n];
}
}
return judge;
}