1 | |
---|
2 | #include "PacmanBrown.h" |
---|
3 | |
---|
4 | #include "core/CoreIncludes.h" |
---|
5 | #include "BulletDynamics/Dynamics/btRigidBody.h" |
---|
6 | |
---|
7 | |
---|
8 | namespace orxonox{ |
---|
9 | |
---|
10 | RegisterClass(PacmanBrown); |
---|
11 | |
---|
12 | PacmanBrown::PacmanBrown(Context* context) : PacmanGhost(context){ |
---|
13 | |
---|
14 | RegisterObject(PacmanBrown); |
---|
15 | |
---|
16 | this->target_x=0; |
---|
17 | this->target_z=15; |
---|
18 | this->lastPlayerPassedPoint=Vector3(0,0,0); //Vector3(70,10,-135); |
---|
19 | |
---|
20 | } |
---|
21 | |
---|
22 | /** |
---|
23 | @brief |
---|
24 | Method for creating a ghost through XML. |
---|
25 | */ |
---|
26 | void PacmanBrown::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
27 | { |
---|
28 | SUPER(PacmanBrown, XMLPort, xmlelement, mode); |
---|
29 | } |
---|
30 | |
---|
31 | |
---|
32 | int PacmanBrown::absoluteDistance(Vector3 pos1, Vector3 pos2){ |
---|
33 | |
---|
34 | |
---|
35 | Vector3 diffVector; |
---|
36 | diffVector.x=pos2.x-pos1.x; |
---|
37 | diffVector.y=pos2.y-pos1.y; //should always be 0 |
---|
38 | diffVector.z=pos2.z-pos1.z; |
---|
39 | int result = sqrt((diffVector.x)*(diffVector.x)+(diffVector.z)*(diffVector.z)); |
---|
40 | return result; |
---|
41 | } |
---|
42 | |
---|
43 | |
---|
44 | void PacmanBrown::tick(float dt) |
---|
45 | { |
---|
46 | SUPER(PacmanGhost, tick, dt); |
---|
47 | |
---|
48 | this->actuelposition = this->getPosition(); |
---|
49 | |
---|
50 | |
---|
51 | for(int u=0; u < 67; u++){//always check if player passed a point |
---|
52 | if(jeanfindpos(this->getPlayerPos(), possibleposition[u])){ |
---|
53 | this->lastPlayerPassedPoint=possibleposition[u]; |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | //Stop, if target arrived |
---|
59 | if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){ |
---|
60 | this->ismoving = false; |
---|
61 | } |
---|
62 | |
---|
63 | //Move, if ghost hasn't arrived yet |
---|
64 | if(this->ismoving){ |
---|
65 | if(!(abs(this->actuelposition.z-target_z)<0.5)) { |
---|
66 | velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z)); |
---|
67 | move(dt, actuelposition, velocity); |
---|
68 | } |
---|
69 | if(!(abs(this->actuelposition.x-target_x)<0.5)){ |
---|
70 | velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0); |
---|
71 | move(dt, actuelposition, velocity); |
---|
72 | } |
---|
73 | } |
---|
74 | else if(this->lastPlayerPassedPoint==Vector3(0,0,0)){ |
---|
75 | //as long as the player has not started the game, |
---|
76 | //i.e. lastPlayerPastPoint is (0,0,0), brown pacman |
---|
77 | //cannot possibly move, because it needs the position |
---|
78 | //of the player to move accordingly |
---|
79 | |
---|
80 | this->ismoving=false; |
---|
81 | std::cout<<"weie"<<endl; |
---|
82 | } |
---|
83 | |
---|
84 | //Check on which position the ghost has arrived and set new target |
---|
85 | else{ |
---|
86 | std::cout<<"naye"<<endl; |
---|
87 | while(lockmove){}; |
---|
88 | lockmove = true; |
---|
89 | |
---|
90 | //do brown behavior |
---|
91 | //put everything needed here |
---|
92 | |
---|
93 | Vector3 brownPos=Vector3(this->target_x, 10, this->target_z); |
---|
94 | |
---|
95 | if(absoluteDistance(this->lastPlayerPassedPoint, this->actuelposition)<50){ |
---|
96 | //no idea if 50 is large enough |
---|
97 | |
---|
98 | //if near player, flee |
---|
99 | |
---|
100 | this->isFleeing=true; |
---|
101 | Vector3 nextMove=getShortestPath( brownPos,Vector3(-215, 10, -195)); |
---|
102 | setNewTargetGhost(nextMove); |
---|
103 | |
---|
104 | } |
---|
105 | |
---|
106 | else if((this->isFleeing==true)&&(!findpos(brownPos,Vector3(-215,10,-195)))){ |
---|
107 | //if fleeing, continue to flee |
---|
108 | Vector3 nextMove = getShortestPath(brownPos, Vector3(-215, 10, -195)); |
---|
109 | setNewTargetGhost(nextMove); |
---|
110 | } |
---|
111 | else if ((this->isFleeing==true)&&(findpos(brownPos,Vector3(-215,10,-195)))){ |
---|
112 | //if fleeing and reached flee point, go back near player |
---|
113 | this->isFleeing=false; |
---|
114 | Vector3 nextMove = getShortestPath(brownPos, this->lastPlayerPassedPoint); |
---|
115 | setNewTargetGhost(nextMove); |
---|
116 | } |
---|
117 | else{ |
---|
118 | //if not fleeing and not near player, go near player |
---|
119 | Vector3 nextMove = getShortestPath(brownPos, this->lastPlayerPassedPoint); |
---|
120 | setNewTargetGhost(nextMove); |
---|
121 | } |
---|
122 | if(this->isFleeing){ |
---|
123 | std::cout<<"fleeing"<<endl; |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | |
---|
128 | |
---|
129 | |
---|
130 | /*if((this->fleeing==true)&&(this->actuelposition!=(-215,10,-195))){ |
---|
131 | //if fleeing, then go to corner map if not already there |
---|
132 | fleeMode(); |
---|
133 | } |
---|
134 | else{ // else go next to pacman |
---|
135 | |
---|
136 | if(absoluteDistance(this->pos, player.pos)<10){//no idea if 10 ok |
---|
137 | //if near player, flee away |
---|
138 | fleemode(); |
---|
139 | } |
---|
140 | else{ //go to neighboor of player nearest to brown pacman |
---|
141 | |
---|
142 | //first find nearest neighboor point of player to brown pacman |
---|
143 | //we can maybe call getShortestPath recursively to do so |
---|
144 | |
---|
145 | player.pos.nearestneighboor=findPlayerNeighboorNearestToPacman(player.neighboors); |
---|
146 | //btw the array player.neighboor can be defined with a big list as we |
---|
147 | //already did several times for similar things |
---|
148 | |
---|
149 | Vector3 nextMove = getShortestPath(this->actuelposition, player.pos.nearestneighboor); |
---|
150 | setNewTargetBrown(nextMove); |
---|
151 | } |
---|
152 | |
---|
153 | }*/ |
---|
154 | lockmove=false; //NEVER FORGET THIS ONE !!! |
---|
155 | |
---|
156 | } |
---|
157 | |
---|
158 | |
---|
159 | |
---|
160 | bool PacmanBrown::isAdjacentToPlayerLastPastPoint(Vector3 pacmanBrownPos, Vector3 arrayForNeighborPositions[]){ |
---|
161 | //return true if brownPacman is on an adjacent position to the last |
---|
162 | //point visited by the player. return false otherwise. |
---|
163 | |
---|
164 | for(int i =0; i < 4; i++){ |
---|
165 | if(arrayForNeighborPositions[i]!=Vector3(0,0,0)){ |
---|
166 | if(findpos(pacmanBrownPos, arrayForNeighborPositions[i])){ |
---|
167 | return true; |
---|
168 | } |
---|
169 | } |
---|
170 | } |
---|
171 | return false; |
---|
172 | } |
---|
173 | |
---|
174 | |
---|
175 | |
---|
176 | void PacmanBrown::findNeighboorPositions(Vector3 actuelposition, Vector3 adjacentPositions[], Vector3 positionArray[]){ |
---|
177 | //this function should put in adjacentPosition[] the neighboors of lastPlayerPastPoint |
---|
178 | |
---|
179 | if(findpos(actuelposition,possibleposition[0])){ |
---|
180 | |
---|
181 | |
---|
182 | adjacentPositions[0]=positionArray[1]; //graphVertex(possibleposition[1]); //need to do it everywhere !!! |
---|
183 | adjacentPositions[1]=positionArray[17]; //graphVertex(possibleposition[17]); |
---|
184 | adjacentPositions[2]=positionArray[19]; //graphVertex(possibleposition[19]); //maybe a vector would be more suitable ? |
---|
185 | } |
---|
186 | else if(findpos(actuelposition,possibleposition[1])){ |
---|
187 | adjacentPositions[0]=positionArray[0]; //graphVertex(possibleposition[0]); |
---|
188 | adjacentPositions[1]=positionArray[2]; //graphVertex(possibleposition[2]); |
---|
189 | } |
---|
190 | else if(findpos(actuelposition,possibleposition[2])){ |
---|
191 | adjacentPositions[0]=positionArray[1]; //graphVertex(possibleposition[1]); |
---|
192 | adjacentPositions[1]=positionArray[3]; //graphVertex(possibleposition[3]); |
---|
193 | } |
---|
194 | else if(findpos(actuelposition,possibleposition[3])){ |
---|
195 | adjacentPositions[0]=positionArray[2]; //graphVertex(possibleposition[2]); |
---|
196 | adjacentPositions[1]=positionArray[4]; //graphVertex(possibleposition[4]); |
---|
197 | adjacentPositions[2]=positionArray[5]; //graphVertex(possibleposition[5]); |
---|
198 | } |
---|
199 | else if(findpos(actuelposition,possibleposition[4])){ |
---|
200 | adjacentPositions[0]=positionArray[3]; //graphVertex(possibleposition[3]); |
---|
201 | adjacentPositions[1]=positionArray[6]; //graphVertex(possibleposition[6]); |
---|
202 | } |
---|
203 | else if(findpos(actuelposition,possibleposition[5])){ |
---|
204 | adjacentPositions[0]=positionArray[3]; //graphVertex(possibleposition[3]); |
---|
205 | adjacentPositions[1]=positionArray[7]; //graphVertex(possibleposition[7]); |
---|
206 | } |
---|
207 | else if(findpos(actuelposition,possibleposition[6])){ |
---|
208 | adjacentPositions[0]=positionArray[4]; //graphVertex(possibleposition[4]); |
---|
209 | adjacentPositions[1]=positionArray[9]; //graphVertex(possibleposition[9]); |
---|
210 | adjacentPositions[2]=positionArray[26]; //graphVertex(possibleposition[26]); |
---|
211 | } |
---|
212 | else if(findpos(actuelposition,possibleposition[7])){ |
---|
213 | adjacentPositions[0]=positionArray[5]; //graphVertex(possibleposition[5]); |
---|
214 | adjacentPositions[1]=positionArray[8]; //graphVertex(possibleposition[8]); |
---|
215 | } |
---|
216 | else if(findpos(actuelposition,possibleposition[8])){ |
---|
217 | adjacentPositions[0]=positionArray[7]; //graphVertex(possibleposition[7]); |
---|
218 | adjacentPositions[1]=positionArray[9]; //graphVertex(possibleposition[9]); |
---|
219 | } |
---|
220 | else if(findpos(actuelposition,possibleposition[9])){ |
---|
221 | adjacentPositions[0]=positionArray[6]; //graphVertex(possibleposition[6]); |
---|
222 | adjacentPositions[1]=positionArray[8]; //graphVertex(possibleposition[8]); |
---|
223 | adjacentPositions[2]=positionArray[10]; //graphVertex(possibleposition[10]); |
---|
224 | adjacentPositions[3]=positionArray[38]; //graphVertex(possibleposition[38]); |
---|
225 | } |
---|
226 | else if(findpos(actuelposition,possibleposition[10])){ |
---|
227 | adjacentPositions[0]=positionArray[9]; //graphVertex(possibleposition[9]); |
---|
228 | adjacentPositions[1]=positionArray[11]; //graphVertex(possibleposition[11]); |
---|
229 | adjacentPositions[2]=positionArray[45]; //graphVertex(possibleposition[45]); |
---|
230 | } |
---|
231 | else if(findpos(actuelposition,possibleposition[11])){ |
---|
232 | adjacentPositions[0]=positionArray[10]; //graphVertex(possibleposition[10]); |
---|
233 | adjacentPositions[1]=positionArray[12]; //graphVertex(possibleposition[12]); |
---|
234 | adjacentPositions[2]=positionArray[13]; //graphVertex(possibleposition[13]); |
---|
235 | } |
---|
236 | else if(findpos(actuelposition,possibleposition[12])){ |
---|
237 | adjacentPositions[0]=positionArray[11]; //graphVertex(possibleposition[11]); |
---|
238 | adjacentPositions[1]=positionArray[14]; //graphVertex(possibleposition[14]); |
---|
239 | } |
---|
240 | else if(findpos(actuelposition,possibleposition[13])){ |
---|
241 | adjacentPositions[0]=positionArray[11]; //graphVertex(possibleposition[11]); |
---|
242 | adjacentPositions[1]=positionArray[14]; //graphVertex(possibleposition[14]); |
---|
243 | adjacentPositions[2]=positionArray[16]; //graphVertex(possibleposition[16]); |
---|
244 | adjacentPositions[3]=positionArray[61]; //graphVertex(possibleposition[61]); |
---|
245 | } |
---|
246 | else if(findpos(actuelposition,possibleposition[14])){ |
---|
247 | adjacentPositions[0]=positionArray[12]; //graphVertex(possibleposition[12]); |
---|
248 | adjacentPositions[1]=positionArray[13]; //graphVertex(possibleposition[13]); |
---|
249 | adjacentPositions[2]=positionArray[15]; //graphVertex(possibleposition[15]); |
---|
250 | } |
---|
251 | else if(findpos(actuelposition,possibleposition[15])){ |
---|
252 | adjacentPositions[0]=positionArray[14]; //graphVertex(possibleposition[14]); |
---|
253 | adjacentPositions[1]=positionArray[16]; //graphVertex(possibleposition[16]); |
---|
254 | } |
---|
255 | else if(findpos(actuelposition,possibleposition[16])){ |
---|
256 | adjacentPositions[0]=positionArray[13]; //graphVertex(possibleposition[13]); |
---|
257 | adjacentPositions[1]=positionArray[15]; //graphVertex(possibleposition[15]); |
---|
258 | adjacentPositions[2]=positionArray[62]; //graphVertex(possibleposition[62]); |
---|
259 | } |
---|
260 | else if(findpos(actuelposition,possibleposition[17])){ |
---|
261 | adjacentPositions[0]=positionArray[0]; //graphVertex(possibleposition[0]); |
---|
262 | adjacentPositions[1]=positionArray[25]; //graphVertex(possibleposition[25]); |
---|
263 | } |
---|
264 | else if(findpos(actuelposition,possibleposition[18])){ |
---|
265 | adjacentPositions[0]=positionArray[19]; //graphVertex(possibleposition[19]); |
---|
266 | adjacentPositions[1]=positionArray[24]; //graphVertex(possibleposition[24]); |
---|
267 | } |
---|
268 | else if(findpos(actuelposition,possibleposition[19])){ |
---|
269 | adjacentPositions[0]=positionArray[0]; //graphVertex(possibleposition[0]); |
---|
270 | adjacentPositions[1]=positionArray[18]; //graphVertex(possibleposition[18]); |
---|
271 | adjacentPositions[2]=positionArray[20]; //graphVertex(possibleposition[20]); |
---|
272 | } |
---|
273 | else if(findpos(actuelposition,possibleposition[20])){ |
---|
274 | adjacentPositions[0]=positionArray[19]; //graphVertex(possibleposition[19]); |
---|
275 | adjacentPositions[1]=positionArray[21]; //graphVertex(possibleposition[21]); |
---|
276 | } |
---|
277 | else if(findpos(actuelposition,possibleposition[21])){ |
---|
278 | adjacentPositions[0]=positionArray[20]; //graphVertex(possibleposition[20]); |
---|
279 | adjacentPositions[1]=positionArray[22]; //graphVertex(possibleposition[22]); |
---|
280 | } |
---|
281 | else if(findpos(actuelposition,possibleposition[22])){ |
---|
282 | adjacentPositions[0]=positionArray[21]; //graphVertex(possibleposition[21]); |
---|
283 | adjacentPositions[1]=positionArray[23]; //graphVertex(possibleposition[23]); |
---|
284 | adjacentPositions[2]=positionArray[31]; //graphVertex(possibleposition[31]); |
---|
285 | } |
---|
286 | else if(findpos(actuelposition,possibleposition[23])){ |
---|
287 | adjacentPositions[0]=positionArray[22]; //graphVertex(possibleposition[22]); |
---|
288 | adjacentPositions[1]=positionArray[30]; //graphVertex(possibleposition[30]); |
---|
289 | } |
---|
290 | else if(findpos(actuelposition,possibleposition[24])){ |
---|
291 | adjacentPositions[0]=positionArray[18]; //graphVertex(possibleposition[18]); |
---|
292 | adjacentPositions[1]=positionArray[29]; //graphVertex(possibleposition[29]); |
---|
293 | } |
---|
294 | else if(findpos(actuelposition,possibleposition[25])){ |
---|
295 | adjacentPositions[0]=positionArray[17]; //graphVertex(possibleposition[17]); |
---|
296 | adjacentPositions[1]=positionArray[26]; //graphVertex(possibleposition[26]); |
---|
297 | } |
---|
298 | else if(findpos(actuelposition,possibleposition[26])){ |
---|
299 | adjacentPositions[0]=positionArray[6]; //graphVertex(possibleposition[6]); |
---|
300 | adjacentPositions[1]=positionArray[25]; //graphVertex(possibleposition[25]); |
---|
301 | adjacentPositions[2]=positionArray[27]; //graphVertex(possibleposition[27]); |
---|
302 | } |
---|
303 | else if(findpos(actuelposition,possibleposition[27])){ |
---|
304 | adjacentPositions[0]=positionArray[26]; //graphVertex(possibleposition[26]); |
---|
305 | adjacentPositions[1]=positionArray[28]; //graphVertex(possibleposition[28]); |
---|
306 | adjacentPositions[2]=positionArray[37]; //graphVertex(possibleposition[37]); |
---|
307 | } |
---|
308 | else if(findpos(actuelposition,possibleposition[28])){ |
---|
309 | adjacentPositions[0]=positionArray[27]; //graphVertex(possibleposition[27]); |
---|
310 | adjacentPositions[1]=positionArray[29]; //graphVertex(possibleposition[29]); |
---|
311 | adjacentPositions[2]=positionArray[36]; //graphVertex(possibleposition[36]); |
---|
312 | } |
---|
313 | else if(findpos(actuelposition,possibleposition[29])){ |
---|
314 | adjacentPositions[0]=positionArray[24]; //graphVertex(possibleposition[24]); |
---|
315 | adjacentPositions[1]=positionArray[28]; //graphVertex(possibleposition[28]); |
---|
316 | adjacentPositions[2]=positionArray[30]; //graphVertex(possibleposition[30]); |
---|
317 | } |
---|
318 | else if(findpos(actuelposition,possibleposition[30])){ |
---|
319 | adjacentPositions[0]=positionArray[23]; //graphVertex(possibleposition[23]); |
---|
320 | adjacentPositions[1]=positionArray[29]; //graphVertex(possibleposition[29]); |
---|
321 | adjacentPositions[2]=positionArray[34]; //graphVertex(possibleposition[34]); |
---|
322 | } |
---|
323 | else if(findpos(actuelposition,possibleposition[31])){ |
---|
324 | adjacentPositions[0]=positionArray[22]; //graphVertex(possibleposition[22]); |
---|
325 | adjacentPositions[1]=positionArray[32]; //graphVertex(possibleposition[32]); |
---|
326 | } |
---|
327 | else if(findpos(actuelposition,possibleposition[32])){ |
---|
328 | adjacentPositions[0]=positionArray[31]; //graphVertex(possibleposition[31]); |
---|
329 | adjacentPositions[1]=positionArray[33]; //graphVertex(possibleposition[33]); |
---|
330 | } |
---|
331 | else if(findpos(actuelposition,possibleposition[33])){ |
---|
332 | adjacentPositions[0]=positionArray[32]; //graphVertex(possibleposition[32]); |
---|
333 | adjacentPositions[1]=positionArray[34]; //graphVertex(possibleposition[34]); |
---|
334 | } |
---|
335 | else if(findpos(actuelposition,possibleposition[34])){ |
---|
336 | adjacentPositions[0]=positionArray[30]; //graphVertex(possibleposition[30]); |
---|
337 | adjacentPositions[1]=positionArray[33]; //graphVertex(possibleposition[33]); |
---|
338 | adjacentPositions[2]=positionArray[35]; //graphVertex(possibleposition[35]); |
---|
339 | adjacentPositions[3]=positionArray[42]; //graphVertex(possibleposition[42]); |
---|
340 | |
---|
341 | } |
---|
342 | else if(findpos(actuelposition,possibleposition[35])){ |
---|
343 | adjacentPositions[0]=positionArray[34]; //graphVertex(possibleposition[34]); |
---|
344 | adjacentPositions[1]=positionArray[36]; //graphVertex(possibleposition[36]); |
---|
345 | adjacentPositions[2]=positionArray[41]; //graphVertex(possibleposition[41]); |
---|
346 | } |
---|
347 | else if(findpos(actuelposition,possibleposition[36])){ |
---|
348 | adjacentPositions[0]=positionArray[28]; //graphVertex(possibleposition[28]); |
---|
349 | adjacentPositions[1]=positionArray[35]; //graphVertex(possibleposition[35]); |
---|
350 | } |
---|
351 | else if(findpos(actuelposition,possibleposition[37])){ |
---|
352 | adjacentPositions[0]=positionArray[27]; //graphVertex(possibleposition[27]); |
---|
353 | adjacentPositions[1]=positionArray[38]; //graphVertex(possibleposition[38]); |
---|
354 | } |
---|
355 | else if(findpos(actuelposition,possibleposition[38])){ |
---|
356 | adjacentPositions[0]=positionArray[9]; //graphVertex(possibleposition[9]); |
---|
357 | adjacentPositions[1]=positionArray[37]; //graphVertex(possibleposition[37]); |
---|
358 | adjacentPositions[2]=positionArray[39]; //graphVertex(possibleposition[39]); |
---|
359 | } |
---|
360 | else if(findpos(actuelposition,possibleposition[39])){ |
---|
361 | adjacentPositions[0]=positionArray[38]; //graphVertex(possibleposition[38]); |
---|
362 | adjacentPositions[1]=positionArray[40]; //graphVertex(possibleposition[40]); |
---|
363 | adjacentPositions[2]=positionArray[45]; //graphVertex(possibleposition[45]); |
---|
364 | } |
---|
365 | else if(findpos(actuelposition,possibleposition[40])){ |
---|
366 | adjacentPositions[0]=positionArray[39]; //graphVertex(possibleposition[39]); |
---|
367 | adjacentPositions[1]=positionArray[41]; //graphVertex(possibleposition[41]); |
---|
368 | } |
---|
369 | else if(findpos(actuelposition,possibleposition[41])){ |
---|
370 | adjacentPositions[0]=positionArray[35]; //graphVertex(possibleposition[35]); |
---|
371 | adjacentPositions[1]=positionArray[43]; //graphVertex(possibleposition[43]); |
---|
372 | } |
---|
373 | else if(findpos(actuelposition,possibleposition[42])){ |
---|
374 | adjacentPositions[0]=positionArray[34]; //graphVertex(possibleposition[34]); |
---|
375 | adjacentPositions[1]=positionArray[43]; //graphVertex(possibleposition[43]); |
---|
376 | adjacentPositions[2]=positionArray[54]; //graphVertex(possibleposition[54]); |
---|
377 | } |
---|
378 | else if(findpos(actuelposition,possibleposition[43])){ |
---|
379 | adjacentPositions[0]=positionArray[41]; //graphVertex(possibleposition[41]); |
---|
380 | adjacentPositions[1]=positionArray[46]; //graphVertex(possibleposition[46]); |
---|
381 | } |
---|
382 | else if(findpos(actuelposition,possibleposition[44])){ |
---|
383 | adjacentPositions[0]=positionArray[40]; //graphVertex(possibleposition[40]); |
---|
384 | adjacentPositions[1]=positionArray[66]; //graphVertex(possibleposition[66]); |
---|
385 | } |
---|
386 | else if(findpos(actuelposition,possibleposition[45])){ |
---|
387 | adjacentPositions[0]=positionArray[10]; //graphVertex(possibleposition[10]); |
---|
388 | adjacentPositions[1]=positionArray[39]; //graphVertex(possibleposition[39]); |
---|
389 | adjacentPositions[2]=positionArray[49]; //graphVertex(possibleposition[49]); |
---|
390 | } |
---|
391 | else if(findpos(actuelposition,possibleposition[46])){ |
---|
392 | adjacentPositions[0]=positionArray[43]; //graphVertex(possibleposition[43]); |
---|
393 | adjacentPositions[1]=positionArray[47]; //graphVertex(possibleposition[47]); |
---|
394 | } |
---|
395 | else if(findpos(actuelposition,possibleposition[47])){ |
---|
396 | adjacentPositions[0]=positionArray[46]; //graphVertex(possibleposition[46]); |
---|
397 | adjacentPositions[1]=positionArray[52]; //graphVertex(possibleposition[52]); |
---|
398 | adjacentPositions[2]=positionArray[66]; //graphVertex(possibleposition[66]); |
---|
399 | } |
---|
400 | else if(findpos(actuelposition,possibleposition[48])){ |
---|
401 | adjacentPositions[0]=positionArray[49]; //graphVertex(possibleposition[49]); |
---|
402 | adjacentPositions[1]=positionArray[51]; //graphVertex(possibleposition[51]); |
---|
403 | adjacentPositions[2]=positionArray[66]; //graphVertex(possibleposition[66]); |
---|
404 | } |
---|
405 | else if(findpos(actuelposition,possibleposition[49])){ |
---|
406 | adjacentPositions[0]=positionArray[45]; //graphVertex(possibleposition[45]); |
---|
407 | adjacentPositions[1]=positionArray[48]; //graphVertex(possibleposition[48]); |
---|
408 | } |
---|
409 | else if(findpos(actuelposition,possibleposition[50])){ |
---|
410 | adjacentPositions[0]=positionArray[51]; //graphVertex(possibleposition[51]); |
---|
411 | adjacentPositions[1]=positionArray[61]; //graphVertex(possibleposition[61]); |
---|
412 | } |
---|
413 | else if(findpos(actuelposition,possibleposition[51])){ |
---|
414 | adjacentPositions[0]=positionArray[48]; //graphVertex(possibleposition[48]); |
---|
415 | adjacentPositions[1]=positionArray[50]; //graphVertex(possibleposition[50]); |
---|
416 | } |
---|
417 | else if(findpos(actuelposition,possibleposition[52])){ |
---|
418 | adjacentPositions[0]=positionArray[47]; //graphVertex(possibleposition[47]); |
---|
419 | adjacentPositions[1]=positionArray[53]; //graphVertex(possibleposition[53]); |
---|
420 | } |
---|
421 | else if(findpos(actuelposition,possibleposition[53])){ |
---|
422 | adjacentPositions[0]=positionArray[52]; //graphVertex(possibleposition[52]); |
---|
423 | adjacentPositions[1]=positionArray[58]; //graphVertex(possibleposition[58]); |
---|
424 | } |
---|
425 | else if(findpos(actuelposition,possibleposition[54])){ |
---|
426 | adjacentPositions[0]=positionArray[42]; //graphVertex(possibleposition[42]); |
---|
427 | adjacentPositions[1]=positionArray[55]; //graphVertex(possibleposition[55]); |
---|
428 | adjacentPositions[2]=positionArray[57]; //graphVertex(possibleposition[57]); |
---|
429 | } |
---|
430 | else if(findpos(actuelposition,possibleposition[55])){ |
---|
431 | adjacentPositions[0]=positionArray[54]; //graphVertex(possibleposition[54]); |
---|
432 | adjacentPositions[1]=positionArray[56]; //graphVertex(possibleposition[56]); |
---|
433 | } |
---|
434 | else if(findpos(actuelposition,possibleposition[56])){ |
---|
435 | adjacentPositions[0]=positionArray[55]; //graphVertex(possibleposition[55]); |
---|
436 | adjacentPositions[1]=positionArray[57]; //graphVertex(possibleposition[57]); |
---|
437 | adjacentPositions[2]=positionArray[65]; //graphVertex(possibleposition[65]); |
---|
438 | } |
---|
439 | else if(findpos(actuelposition,possibleposition[57])){ |
---|
440 | adjacentPositions[0]=positionArray[54]; //graphVertex(possibleposition[54]); |
---|
441 | adjacentPositions[1]=positionArray[56]; //graphVertex(possibleposition[56]); |
---|
442 | adjacentPositions[2]=positionArray[58]; //graphVertex(possibleposition[58]); |
---|
443 | adjacentPositions[3]=positionArray[64]; //graphVertex(possibleposition[64]); |
---|
444 | |
---|
445 | } |
---|
446 | else if(findpos(actuelposition,possibleposition[58])){ |
---|
447 | adjacentPositions[0]=positionArray[53]; //graphVertex(possibleposition[53]); |
---|
448 | adjacentPositions[1]=positionArray[57]; //graphVertex(possibleposition[57]); |
---|
449 | adjacentPositions[2]=positionArray[59]; //graphVertex(possibleposition[59]); |
---|
450 | } |
---|
451 | else if(findpos(actuelposition,possibleposition[59])){ |
---|
452 | adjacentPositions[0]=positionArray[58]; //graphVertex(possibleposition[58]); |
---|
453 | adjacentPositions[1]=positionArray[59]; //graphVertex(possibleposition[59]); |
---|
454 | adjacentPositions[2]=positionArray[63]; //graphVertex(possibleposition[63]); |
---|
455 | } |
---|
456 | else if(findpos(actuelposition,possibleposition[60])){ |
---|
457 | adjacentPositions[0]=positionArray[59]; //graphVertex(possibleposition[59]); |
---|
458 | adjacentPositions[1]=positionArray[61]; //graphVertex(possibleposition[61]); |
---|
459 | adjacentPositions[2]=positionArray[62]; //graphVertex(possibleposition[62]); |
---|
460 | } |
---|
461 | else if(findpos(actuelposition,possibleposition[61])){ |
---|
462 | adjacentPositions[0]=positionArray[13]; //graphVertex(possibleposition[13]); |
---|
463 | adjacentPositions[1]=positionArray[50]; //graphVertex(possibleposition[50]); |
---|
464 | adjacentPositions[2]=positionArray[60]; //graphVertex(possibleposition[60]); |
---|
465 | } |
---|
466 | else if(findpos(actuelposition,possibleposition[62])){ |
---|
467 | adjacentPositions[0]=positionArray[16]; //graphVertex(possibleposition[16]); |
---|
468 | adjacentPositions[1]=positionArray[60]; //graphVertex(possibleposition[60]); |
---|
469 | } |
---|
470 | else if(findpos(actuelposition,possibleposition[63])){ |
---|
471 | adjacentPositions[0]=positionArray[59]; //graphVertex(possibleposition[59]); |
---|
472 | adjacentPositions[1]=positionArray[64]; //graphVertex(possibleposition[64]); |
---|
473 | } |
---|
474 | else if(findpos(actuelposition,possibleposition[64])){ |
---|
475 | adjacentPositions[0]=positionArray[57]; //graphVertex(possibleposition[57]); |
---|
476 | adjacentPositions[1]=positionArray[63]; //graphVertex(possibleposition[63]); |
---|
477 | adjacentPositions[2]=positionArray[65]; //graphVertex(possibleposition[65]); |
---|
478 | } |
---|
479 | else if(findpos(actuelposition,possibleposition[65])){ |
---|
480 | adjacentPositions[0]=positionArray[56]; //graphVertex(possibleposition[56]); |
---|
481 | adjacentPositions[1]=positionArray[64]; //graphVertex(possibleposition[64]); |
---|
482 | } |
---|
483 | else if(findpos(actuelposition,possibleposition[66])){ |
---|
484 | adjacentPositions[0]=positionArray[47]; //graphVertex(possibleposition[47]); |
---|
485 | adjacentPositions[1]=positionArray[48]; //graphVertex(possibleposition[48]); |
---|
486 | } |
---|
487 | } |
---|
488 | |
---|
489 | |
---|
490 | |
---|
491 | } |
---|
492 | |
---|
493 | |
---|
494 | |
---|
495 | |
---|
496 | |
---|
497 | |
---|
498 | |
---|
499 | |
---|
500 | |
---|
501 | /*int graphDistance(Vector3 start, Vector3 goal){ |
---|
502 | |
---|
503 | Vector3 differenceVector= Vector3(abs(goal.x-start.x), 0,abs(goal.z-start.z)); |
---|
504 | |
---|
505 | return differenceVector.x+differenceVector.z; |
---|
506 | }*/ |
---|
507 | |
---|
508 | /*void setNewTargetBrown(Vector3 goalToGo){ |
---|
509 | |
---|
510 | this->target_x = goalToGo.x; |
---|
511 | this->target_z = goalToGo.z; |
---|
512 | this->ismoving = true; |
---|
513 | }*/ |
---|
514 | |
---|
515 | |
---|
516 | |
---|
517 | /*int PacmanBrown::absoluteDistance(Vector3 pos1, Vector3 pos2){ |
---|
518 | |
---|
519 | |
---|
520 | Vector3 diffVector; |
---|
521 | diffVector.x=pos2-pos1; |
---|
522 | diffVector.y=pos2-pos1; //should always be 0 |
---|
523 | diffVector.z=pos2-pos1; |
---|
524 | int result = sqrt((diffVector.x)*(diffVector.x)+(diffVector.z)*(diffVector.z)); |
---|
525 | return result; |
---|
526 | }*/ |
---|
527 | |
---|
528 | |
---|
529 | /*void fleeMode(){ //flees to corner of the map |
---|
530 | |
---|
531 | Vector3 cornerPos = Vector3(-215,10,-195); //let's take this. We can still change |
---|
532 | Vector3 nextMove = getShortestPath(this->actuelposition, cornerPos); |
---|
533 | setNewTargetGhost(nextMove); |
---|
534 | |
---|
535 | //while(this->actuelposition!=cornerPos){ |
---|
536 | |
---|
537 | continue moving and each time find next point to go until |
---|
538 | we reach the corner |
---|
539 | } |
---|
540 | }*/ |
---|
541 | |
---|
542 | |
---|
543 | /*Vector3 goAdjacentOfPlayer(Vector neighboorsOfPlayer[]){ |
---|
544 | //find ,nearest to brown, player neighboor |
---|
545 | |
---|
546 | int besTotDist=-1; |
---|
547 | Vector3 curPos=this->pos; |
---|
548 | Vector3 predPos; |
---|
549 | Vector3 chosenNeighbor; |
---|
550 | |
---|
551 | for(int i=0; i < 4; i++){ |
---|
552 | int totDist=0; |
---|
553 | |
---|
554 | if(neighboorsOfPlayer[i]!=0){ |
---|
555 | while(curPos!=neighboorsOfPlayer[i]){ |
---|
556 | |
---|
557 | predPos=curPos; |
---|
558 | curPos = getShortestPath(curPos, neighboorsOfPlayer[i]); |
---|
559 | totDist+=graphDistance(curPos,predPos); |
---|
560 | |
---|
561 | } |
---|
562 | } |
---|
563 | |
---|
564 | if(besTotDist==-1){ |
---|
565 | besTotDist=totDist; |
---|
566 | chosenNeighbor=neighboorsOfPlayer[i]; |
---|
567 | } |
---|
568 | else if(besTotDist>totDist){ |
---|
569 | besTotDist=totDist; |
---|
570 | chosenNeighbor=neighboorsOfPlayer[i]; |
---|
571 | } |
---|
572 | } |
---|
573 | return chosenNeighbor; |
---|
574 | |
---|
575 | }*/ |
---|
576 | |
---|
577 | |
---|
578 | /*Vector3 findPlayerNeighboorNearestToPacman(Vector3 neighboorArray[]){ |
---|
579 | //uh, i think it does the same think as the function above |
---|
580 | |
---|
581 | Vector3 nextMove; |
---|
582 | int distCost=-1; |
---|
583 | for(int i=0; i < 4; i++){ |
---|
584 | int totDist=0; |
---|
585 | Vector3 newCandidate=this->actuelposition; |
---|
586 | Vector3 predPos; |
---|
587 | |
---|
588 | if(neighboorArray[i]!=NULL){ |
---|
589 | while(nextMove!=neighboorArray[i]){ |
---|
590 | predPos=newCandidate; |
---|
591 | newCandidate=getShortestPath(newCandidate, neighboorArray[i]); |
---|
592 | totDist+=graphDistance(predPos, newCandidate); |
---|
593 | } |
---|
594 | |
---|
595 | if(distCost==-1){ |
---|
596 | distCost=totDist; |
---|
597 | nextMove=gneighboorArray[i]; |
---|
598 | } |
---|
599 | else if(totDist<distCost){ |
---|
600 | distCost=totDist; |
---|
601 | nextMove=neighboorArray[i]; |
---|
602 | } |
---|
603 | } |
---|
604 | } |
---|
605 | return nextMove; |
---|
606 | |
---|
607 | }*/ |
---|
608 | |
---|
609 | |
---|
610 | |
---|
611 | |
---|
612 | |
---|
613 | |
---|