void process() { long i, j, k; line l, l2; point la, lb, c; ans = 0; p[n] = p[0]; for (i = 0; i < n; i++) for (j = i + 1; j < n; j++) { l = midline(p[i], p[j]); for (k = i; k != j; k = (k + 1) % n) { if (cross(p[k], p[k + 1], l)) { la = crosspoint(straightline(p[k], p[k + 1]), l); break; } } if (k == j) printf("ERROR\n"); for (k = j; k != i; k = (k + 1) % n) { if (cross(p[k], p[k + 1], l)) { lb = crosspoint(straightline(p[k], p[k + 1]), l); break; } } if (k == i) printf("ERROR\n"); check(la, 'e'); check(lb, 'e'); for (k = 0; k < n; k++) if (k != i && k != j) { l2 = midline(p[i], p[k]); if (cross(la, lb, l2)) { c = crosspoint(l2, l); check(c, 'i'); } } } printf("%.3lf\n", sqrt(ans)); }
const char *handlecombat(int tx, int ty, char target) { static char action[16]; int idx; int monstercount = 0; int lowestscore = 9999999; int lowestx; int lowesty; int score; float dist; unsigned char direction; item_t *daggeritem; // this doesn't work but hell if I know why not if (target == 'Z' || target == 'M' || target == 'V' || target == '@' || target == 'c' || target == 'l' || target == 'n') { lastkilltimer = 999; monsterx = 0; monstery = 0; } else { lastkilltimer = 0; monsterx = tx; monstery = ty; } for (idx = 80; idx < 80 * 22; idx++) { if (ismonster(framebuffer[idx]) && ((idx % 80) != myx || (idx / 80) != myy) && !(strcasestr(framebuffer, "see here") && tx >= 58 && ty <= 3)) { monstercount++; } } // see if we should fling daggers if (straightline(tx, ty, &dist, &direction) && (dist > 1.5 || target == NOTOUCH_MONSTER) && dist < 5.0 && countitems(ITEM_DAGGER, -1)) { daggeritem = getitem(ITEM_DAGGER, -1); fprintf(logfile, "flinging daggers @ %c (%f distance)\n", direction, dist); sprintf(action, "t%c%c ", daggeritem->letter, direction); daggeritem->count--; return action; } if (1 || monstercount <= 2) { // don't worry about advanced tactics when not facing large // numbers of opponents lastdirection = pathto(tx, ty, target, 0); fprintf(logfile, "naively attacking %i.%i by moving %c\n", tx, ty, lastdirection); sprintf(action, "%c", lastdirection); } else { if (abs(tx - myx) <= 1 && abs(ty - myy) <= 1) { lastdirection = pathto(tx, ty, target, 0); fprintf(logfile, "monster is next to us. Moving %c\n", lastdirection); sprintf(action, "%c", lastdirection); return action; } if (assessvulnerability(myx, myy) >= VULNERABILITY_CUTOFF) { fprintf(logfile, "Current location (%i.%i) is a little hot. Moving to somewhere more secure.\n", myx, myy); for (idx = 80; idx < 80 * 22; idx++) { if (!(idx % 80) || (idx % 80) == 79) { continue; } score = scorecombatlocation(idx % 80, idx / 80); if (score < lowestscore) { lowestscore = score; lowestx = idx % 80; lowesty = idx / 80; } } if (lowestscore < 9999999) { fprintf(logfile, "%i.%i seems to be a comfy spot to fight (score = %i)\n", lowestx, lowesty, lowestscore); lastdirection = pathto(lowestx, lowesty, framebuffer[lowesty * 80 + lowestx], 0); sprintf(action, "%c", lastdirection); } } else { lastdirection = pathto(tx, ty, target, 0); fprintf(logfile, "monster is NOT next to us. Moving %c\n", lastdirection); sprintf(action, "%c", lastdirection); } } return action; }