History

"harder ai"

mischief committed 11 years ago

Commit 0bcfeff1 parent 357e4951 file · +21 −5Browse files

Unified · Split

hack9.c+21−5
@@ -108,6 +108,7 @@ move(Point src, int dir) · 107 unmodified lines
108 108
109 switch(dir){109 switch(dir){
110 default:110 default:
111 fprint(2, "unknown move %d\n", dir);
111 case DUMMY:112 case DUMMY:
112 return ZP;113 return ZP;
113 break;114 break;
@@ -202,7 +203,15 @@ movemons(void) · 88 unmodified lines
202 double ang = atan2(p2.y, p2.x);203 double ang = atan2(p2.y, p2.x);
203 movdir = (int)(4 * ang / (2*PI) + 4.5) % 4;204 movdir = (int)(4 * ang / (2*PI) + 4.5) % 4;
204 /* no pos to update. */205 /* no pos to update. */
205 move(p, movdir+1);206 if(eqpt(move(p, movdir+1), ZP)){
207 /* try again? */
208 movdir = (movdir+1) % 4;
209 if(eqpt(move(p, movdir+1), ZP)){
210 /* try again? */
211 movdir = (movdir+2) % 4;
212 move(p, movdir+1);
213 }
214 }
206 }215 }
207 }216 }
208 }217 }
@@ -279,7 +288,7 @@ threadmain(int argc, char *argv[]) · 70 unmodified lines
279 flushimage(display, 1);288 flushimage(display, 1);
280 break;289 break;
281 case AKEYBOARD:290 case AKEYBOARD:
282 movdir = 0;291 movdir = DUMMY;
283 switch(c){292 switch(c){
284 case Kdel:293 case Kdel:
285 threadexitsall(nil);294 threadexitsall(nil);
@@ -309,15 +318,22 @@ threadmain(int argc, char *argv[]) · 23 unmodified lines
309 case '.':318 case '.':
310 movdir = DUMMY;319 movdir = DUMMY;
311 break;320 break;
321 default:
322 /* don't waste a move */
323 continue;
312 }324 }
313 325
314 p=move(pos, movdir);326 if(movdir != DUMMY){
315 if(!eqpt(p, ZP)){327 p=move(pos, movdir);
328 if(eqpt(p, ZP)){
329 break;
330 }
331
316 pos = subpt(pos, p);332 pos = subpt(pos, p);
317 }333 }
318 334
319 static int turns=0;335 static int turns=0;
320 if(++turns % 5 ==0){336 if(++turns % 3 ==0){
321 movemons();337 movemons();
322 }338 }
323 339