Single Player AI Test 3

origin
stpohle 23 years ago
parent 03ecc242d6
commit 722578ebe5

@ -1,4 +1,4 @@
/* $Id: bomberclone.h,v 1.27 2003/05/28 22:31:47 stpohle Exp $ */
/* $Id: bomberclone.h,v 1.28 2003/05/28 23:03:21 stpohle Exp $ */
/* bomberclone.h */
#ifndef _BOMBERCLONE_H_
@ -251,6 +251,7 @@ extern int ai_findbestbombdir (_point pos, int dir, int range);
extern int ai_bombpoints (_point pos, int range);
extern int ai_runawayfrom (_point p, int nearbomb, signed char norecursive);
extern int ai_checkfield (int x, int y);
extern int ai_easyrunaway (_point p);
// mapmenu.c

@ -1,4 +1,4 @@
/* $Id: single.c,v 1.21 2003/05/28 22:31:47 stpohle Exp $ */
/* $Id: single.c,v 1.22 2003/05/28 23:03:21 stpohle Exp $ */
/* single player */
#include "basic.h"
@ -70,6 +70,70 @@ ai_checkfield (int x, int y)
}
/* give the run away direction */
int
ai_easyrunaway (_point p)
{
int i, done = 0, dir = 0;
_point pos[4], m[4];
for (i = 0; i < 4; i++) {
pos[i] = p;
switch (i) {
case (left):
m[i].x = -1;
m[i].y = 0;
break;
case (right):
m[i].x = 1;
m[i].y = 0;
break;
case (up):
m[i].x = 0;
m[i].y = -1;
break;
default:
m[i].x = 0;
m[i].y = 1;
break;
}
pos[i].x += m[i].x;
pos[i].y += m[i].y;
}
/* test the possible ways */
while (!done) {
done = 1;
for (i = 0; i < 4; i++) {
/* check if we are still in the game field */
if (pos[i].x <= 0 || pos[i].y <= 0 || pos[i].x >= bman.fieldsize.x-1 || pos[i].y >= bman.fieldsize.y-1)
pos[i].x = pos[i].y = -1;
if (pos[i].x != -1 && pos[i].y != -1) {
/* check if this place is free to go to */
if (ai_checkfield (pos[i].x, pos[i].y)) {
done = 0;
/* check the field left and right beside */
if (i == left || i == right) {
if (ai_checkfield (pos[i].x, pos[i].y - 1) || ai_checkfield (pos[i].x, pos[i].y + 1))
dir |= (1 << i);
}
else {
if (ai_checkfield (pos[i].x - 1, pos[i].y) || ai_checkfield (pos[i].x + 1, pos[i].y))
dir |= (1 << i);
}
pos[i].x += m[i].x;
pos[i].y += m[i].y;
}
}
}
}
return dir;
};
/* give the run away direction */
int
ai_runawayfrom (_point p, int nearbomb, signed char norecursive)
@ -135,8 +199,6 @@ ai_runawayfrom (_point p, int nearbomb, signed char norecursive)
}
}
}
printf ("["); d_bitprint (dir, 4);
if (norecursive == 0) {// to prevent from invinite loops
for (i = 0; i < 4; i ++)
@ -156,8 +218,6 @@ ai_runawayfrom (_point p, int nearbomb, signed char norecursive)
dir &= (0xFF - (1 << i));
}
}
d_bitprint (dir, 4); printf ("] ");
return dir;
};
@ -205,8 +265,8 @@ ai_bombpoints (_point pos, int range)
points++;
}
}
if ((ai_runawayfrom (p, 16, 0) == 0) || ai_findnearbombs (p) != 0)
if (ai_easyrunaway (pos) == 0 || ai_findnearbombs (pos) != 0)
points = 0;
return points;
@ -258,9 +318,6 @@ ai_findbestbombdir (_point pos, int dir, int range)
if (points[bestd] <= points[4] && points[4] != 0)
bestd = 4;
d_printf ("ai_findbestbombdir (%d %d %d %d %d)\n", points[0], points[1], points[2], points[3],
points[4]);
return bestd;
}
@ -383,8 +440,6 @@ ai_choosedir (int dir, int nearbomb, int oldpos) {
else
i = rdir[s_random (rnr)];
printf ("AIDir %d,%d->%d ", rnr,bnr, i);
return i;
};
@ -468,7 +523,6 @@ single_loop ()
pl->m = 1;
else {
nearbomb = ai_findnearbombs (plpos);
printf ("SP: %d,%d NB:", plpos.x, plpos.y); d_bitprint (nearbomb, 5);
if (nearbomb == 0) { // no bombs found
bestbdir = ai_findbestbombdir (plpos, pl->d, pl->range);
if (bestbdir >= 4)
@ -484,15 +538,11 @@ single_loop ()
}
else {
// bombs in the near found
printf (" FB: %d,%d ", plpos.x, plpos.y);
if ((i = ai_runawayfrom (plpos, nearbomb, 0)) != 0) {
pl->d = ai_choosedir (i, nearbomb, pl->d); // we have to make a choice.. do it
pl->m = 1;
}
printf ("D:%d, M:%d, Flee", pl->d, pl->m);
d_bitprint (i, 4);
}
printf ("\n");
}
player_ilness_loop (p);
move_player (p);

Loading…
Cancel
Save