-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAI1.0.cpp
285 lines (277 loc) · 6.01 KB
/
AI1.0.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
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
//#include"Table.h"
#include<queue>
#include<stack>
#include"GetStatus.h"
//########################
//Path Data
vector<Edge> Link[MAXROOM];
int Path[MAXROOM];
int Short[MAXROOM];
int BombMap[MAXLEN][MAXLEN];
//########################
//------------------------
//########################
//Run to Dest Point
void GetSourceMap(int Source[][MAXLEN],int Dest[][MAXLEN])
{
for(int i=0;i<MAXLEN;i++)
for(int j=0;j<MAXLEN;j++)
Dest[i][j]=Source[i][j];
}
void Change(int X,int Y,int T)
{
if(BombMap[Y][X]<0)
return;
if(BombMap[Y][X]>=T)
return;
BombMap[Y][X]=T;
for(int i=0;i<4;i++)
{
Change(X+Dir[i][0],Y+Dir[i][1],T);
Change(X+Dir[i][0]*2,Y+2*Dir[i][1],T);
}
}
void SetBoomTime()
{
memset(BombMap,0,sizeof(BombMap));
for(int i=1;i<=BombNum;i++)
{
int X=BombX[i];
int Y=BombY[i];
BombMap[Y][X]=BombTime[i];
}
for(int i=1;i<=BombNum;i++)
{
int X=BombX[i];
int Y=BombY[i];
Change(Y,X,BombMap[Y][X]);
}
for(int i=1;i<=BombNum;i++)
{
int X=BombX[i];
int Y=BombY[i];
BombTime[i]=BombMap[Y][X];
}
}
int CoordToNum(int X,int Y)
{
return Y*MAXLEN+X;
}
void BulidLinkMap()
{
int TempMap[MAXLEN][MAXLEN];
GetSourceMap(SourceMap,TempMap);
for(int i=1;i<=BombNum;i++)
{
int X=BombX[i];
int Y=BombY[i];
TempMap[Y][X]=BombTime[i];
}
for(int y=1;y<=MAPLEN;y++)
for(int x=1;x<=MAPLEN;x++)
{
int At=CoordToNum(x,y);
int X,Y;
for(int i=0;i<4;i++)
{
X=x+Dir[i][1];
Y=y+Dir[i][0];
}
switch(TempMap[Y][X])
{
case WOOD:
Link[At].push_back(Edge(CoordToNum(X,Y),9));
case BLANK:
Link[At].push_back(Edge(CoordToNum(X,Y),1));
case STONE:
Link[At].push_back(Edge(CoordToNum(X,Y),INF));
case HOME:
Link[At].push_back(Edge(CoordToNum(X,Y),INF));
case BOMB:
Link[At].push_back(Edge(CoordToNum(X,Y),BombMap[Y][X]));
}
}
}
void Dijistra(int Source)
{
int Visit[MAXROOM];
memset(Visit,0,sizeof(Visit));
fill(Short,Short+MAXROOM,INF);
Short[Source]=0;
Path[Source]=Source;
while(true)
{
int Pos=-1;
for(int i=0;i<MAXROOM;i++)
if(!Visit[i]&&(Pos==-1||Visit[i]<Visit[Pos]))
Pos=i;
Visit[Pos]=true;
//cout<<Point<<endl;
if(Pos==-1)
break;
for(int i=0;i<Link[Pos].size();i++)
{
int Dest=Link[Pos][i].Dest;
int Cost=Link[Pos][i].Cost;
if(Short[Dest]>Short[Pos]+Cost)
{
Short[Dest]=Short[Pos]+Cost;
Path[Dest]=Pos;
}
}
}
}
int GetDest(int ID)
{
}
//########################
//------------------------
//########################
// Escape Function
Coord PosOp(Coord Pos,int op)
{
op=op-1;
Pos.y+=Dir[op][0];
Pos.x+=Dir[op][1];
return Pos;
}
int SafeMap[MAXLEN][MAXLEN];
int Attion[MAXLEN][MAXLEN];
int PathMap[MAXLEN][MAXLEN];
int StepMap[MAXLEN][MAXLEN];
void BulidSafeMap()
{
GetSourceMap(SourceMap,SafeMap);
for(int i=0;i<BombNum;i++)
{
int X=BombX[i];
int Y=BombY[i];
SafeMap[Y][X]=BOMB;
Attion[Y][X]=ATTENTION;
for(int i=0;i<4;i++)
for(int j=1;j<=2;j++)
{
int TX=X+Dir[i][1]*j;
int TY=Y+Dir[i][0]*j;
if(SafeMap[TY][TX]!=BLANK)
break;
Attion[TY][TX]=ATTENTION;
}
}
}
Coord GetPath(Coord Source)
{
queue<Coord> Next;
memset(StepMap,-1,sizeof(StepMap));
memset(StepMap,0,sizeof(PathMap));
Next.push(Source);
int X=Source.x;
int Y=Source.y;
StepMap[Y][X]=0;
PathMap[Y][X]=0;
if(Attion[Y][X]!=ATTENTION)
return Source;
while(Next.empty())
{
Coord Now;
Now=Next.front();
Next.pop();
X=Now.x;
Y=Now.y;
for(int i=0;i<4;i++)
{
int TX=X+Dir[i][1];
int TY=Y+Dir[i][0];
if(SafeMap[TY][TX]!=BLANK)
continue;
if(PathMap[TY][TX]!=-1)
continue;
StepMap[TY][TX]=PathMap[Y][X]+1;
PathMap[TY][TX]=i+1;
Coord Temp;
Temp.x=TX;
Temp.y=TY;
Next.push(Temp);
if(Attion[TY][TX]!=ATTENTION)
return Temp;
}
}
Coord Ans;
Ans.x=-1;
Ans.y=-1;
return Ans;
}
int GetStep(Coord Pos)
{
if(Pos.x<0||Pos.y<0)
return INF;
return StepMap[Pos.y][Pos.x];
}
Coord OptoPos(Coord Pos,int Op)
{
if(Op>=1&&Op<=4)
{
Pos.x+=Dir[Op-1][1];
Pos.y+=Dir[Op-1][0];
}
return Pos;
}
int GetInvOp(int Op)
{
switch(Op)
{
case UP:
return DOWN;
case DOWN:
return UP;
case LEFT:
return RIGHT;
case RIGHT:
return LEFT;
}
return Op;
}
int GetOp(Coord Pos)
{
if(Pos.x<0||Pos.y<0)
return PUT;
int Ans=NOP;
while(PathMap[Pos.y][Pos.x]!=NOP)
{
Ans=PathMap[Pos.y][Pos.x];
Pos=OptoPos(Pos,GetInvOp(Ans));
}
return Ans;
}
void Judge(int ID)
{
Coord Pos=MyPlayer[ID].pos;
int Op=Behave[ID];
int StepA,StepS;
BulidSafeMap();
Coord Temp;
Temp=GetPath(Pos);
StepA=GetStep(Temp);
Pos=OptoPos(Pos,Op);
Temp=GetPath(Pos);
StepS=GetStep(Temp);
if(StepS<StepA)
Behave[ID]=GetOp(Temp);
}
//########################
//------------------------
//########################
void AI(const Game *game,Operator op[PLAYER_NUM])
{
GetGame(game);
if(Round<=TABLE)
AutoRun(Round);
else
{
}
Push(op);
}
//########################
bool TrueOp(Coord Pos,int Map)
{
}