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