-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchess.cpp
More file actions
237 lines (229 loc) · 6.6 KB
/
Copy pathchess.cpp
File metadata and controls
237 lines (229 loc) · 6.6 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#include "chess.h"
#include "utils.h"
#include <iostream>
#include "chessboard.h"
using namespace std;
// 我命名为扩散算法,依次枚举可到位置,蜂王把半径设为1,蜘蛛3,蚂蚁0(代表无限)
// radius表示步数。stuck表示是否考虑卡位的情况,原版的几个棋子应该设置为true
std::set<Point> diffusion(Point ori, const set<Point> &range,const set<Point> &all_chesses, int radius,bool stuck)
{
int round = 0;
set<Point> previous, current, next, x, ret;
previous.insert(ori);
current = previous;
while (true)
{
for (auto it = current.begin(); it != current.end();++it)//逐个枚举
{
x = (enum_nearby(*it)*range)-previous;
for (auto it2 = x.begin(); it2 != x.end(); ++it2)
{
if (!stuck||!((enum_nearby(*it)*enum_nearby(*it2))-all_chesses).empty())
{
next.insert(*it2);
}
}
}
next = next - current;//禁止蜘蛛通过3步移动到只需2步可以移动到的位置,是否启用此行代码取决于未确定的规则。
round++;
if(radius==0)
{
ret = ret + next;
}
if (radius != 0 && round == radius)
{
return next;
}
if(radius==0&&(next-previous).empty())
{
return ret;
}
previous = current;
current = next;
next.clear();
}
}
graph Chess::to_graph(){
string cha(1, id.id);
string line13 = cha + " " + cha;
string line2 = " " +pattern+ " ";
graph x = {id.player, line13,line2, line13}; // 1个emoji=2个字符位
return x;
}
set<Point> Chess::get_dest(cid id, const Chessboard &chessboard) const
{
set<Point> r;
return r;
}
set<Point> Beequeen::get_dest(cid id, const Chessboard& chessboard ) const
{
set<Point> range, allchesses;
Point ori = chessboard.ID2Pnt(id);
if (chessboard.check_upper(ori))
{
cout << "你不能控制被压住的棋子..." << endl;
return range;
}
if (!chessboard.isConnected(ori))
{
std::cout << "not connected" << endl;
return range;
}
range = chessboard.enum_mov_dest(ori);
allchesses = chessboard.get_chess(0);
allchesses.erase(ori);
return diffusion(ori, range, allchesses, 1, true);
}
set<Point> Spider::get_dest(cid id, const Chessboard &chessboard) const
{
set<Point> range,allchesses;
Point ori = chessboard.ID2Pnt(id);
if (chessboard.check_upper(ori))
{
cout << "你不能控制被压住的棋子..." << endl;
return range;
}
if (!chessboard.isConnected(ori))
{
std::cout << "not connected" << endl;
return range;
}
range = chessboard.enum_mov_dest(ori);
allchesses = chessboard.get_chess(0);
allchesses.erase(ori);
return diffusion(ori, range, allchesses, 3, true);
}
set<Point> Ant::get_dest(cid id, const Chessboard &chessboard) const
{
set<Point> range,allchesses;
Point ori = chessboard.ID2Pnt(id);
if (chessboard.check_upper(ori))
{
cout << "你不能控制被压住的棋子..." << endl;
return range;
}
if (!chessboard.isConnected(ori))
{
std::cout << "not connected" << endl;
return range;
}
range = chessboard.enum_mov_dest(ori);
allchesses = chessboard.get_chess(0);
allchesses.erase(ori);
return diffusion(ori, range, allchesses, 0, true);
}
set<Point> Grasshopper::get_dest(cid id, const Chessboard &chessboard) const
{
set<Point> ret, allchesses;
Point temp;
Point ori = chessboard.ID2Pnt(id);
if (chessboard.check_upper(ori))
{
cout << "你不能控制被压住的棋子..." << endl;
return ret;
}
if (!chessboard.isConnected(ori))
{
std::cout << "not connected" << endl;
return ret;
}
allchesses = chessboard.get_chess(0);
for(const Point &direction : DIRECTIONS)
{
temp = ori;
while (allchesses.count(temp)!=0)
{
temp = temp + direction;
}
ret.insert(temp);
}
return ret - enum_nearby(ori);
}
set<Point> Beetle::get_dest(cid id, const Chessboard &chessboard) const
{
set<Point> ret, allchesses,range;
Point ori = chessboard.ID2Pnt(id);
if (chessboard.check_upper(ori))
{
cout << "你不能控制被压住的棋子..." << endl;
return ret;
}
Point p;
if (!chessboard.isConnected(ori))
{
std::cout << "not connected" << endl;
return ret;
}
ori.layer = 0;
allchesses = chessboard.get_chess(0);
allchesses.erase(ori);
range = enum_nearby_all(allchesses);
range = range * enum_nearby(ori);
for (auto it = range.begin(); it != range.end(); ++it)
{
p = *it;
while (chessboard.getBoard().count(p)>0)
{
p.layer++;
}
ret.insert(p);
}
return ret;
}
//根据百度百科,当在地面时模仿周围棋子的走法,但在上层时使用甲虫的走法
set<Point> Mosquito::get_dest(cid id, const Chessboard &chessboard) const
{
set<Point> ret, allchesses, range;
Point ori = chessboard.ID2Pnt(id);
allchesses = chessboard.get_chess(0);
if(ori.layer == 0)
{
range = allchesses*enum_nearby(ori);
for(auto i : range)
{
if (typeid(*chessboard.getBoard().at(i)) != typeid(Mosquito))
ret = ret + chessboard.getBoard().at(i)->get_dest(id, chessboard);
}
}
else
{
for (; ori.layer >= 0;ori.layer--)
{
range = range + enum_nearby(ori)*allchesses;
range.insert(ori);
}
for(auto i:range)
{
if (typeid(*chessboard.getBoard().at(i)) == typeid(Beetle))
{
ret = chessboard.getBoard().at(i)->get_dest(id, chessboard);
break;
}
}
}
return ret;
}
set<Point> Ladybug::get_dest(cid id, const Chessboard &chessboard) const
{
set<Point> ret, allchesses,range;
Point ori = chessboard.ID2Pnt(id);
if (chessboard.check_upper(ori))
{
cout << "你不能控制被压住的棋子..." << endl;
return ret;
}
if (!chessboard.isConnected(ori))
{
std::cout << "not connected" << endl;
return ret;
}
allchesses = chessboard.get_chess(0);
allchesses.erase(ori);
range = diffusion(ori, allchesses, ret, 2, false);
for(auto i:range)
{
ret = ret + (enum_nearby(i) - allchesses);
}
ret.erase(ori);
return ret;
}