projects
/
xscreensaver
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
From http://www.jwz.org/xscreensaver/xscreensaver-5.26.tar.gz
[xscreensaver]
/
hacks
/
pacman_ai.c
diff --git
a/hacks/pacman_ai.c
b/hacks/pacman_ai.c
index 0da72384017f70369ef3ffd85e50fa9424f7713e..b85bd96e816fafa32e32e09f90fd022e15b196a4 100644
(file)
--- a/
hacks/pacman_ai.c
+++ b/
hacks/pacman_ai.c
@@
-67,9
+67,9
@@
ghost_get_posdirs (pacmangamestruct * pp, int *posdirs, ghoststruct * g)
/* check if possible direction */
can_go_in = (g->aistate == goingout || g->aistate == goingin);
if ((posdirs[i] =
/* check if possible direction */
can_go_in = (g->aistate == goingout || g->aistate == goingin);
if ((posdirs[i] =
- check_pos (pp, g->row + dirvecs[i].dy,
- g->col + dirvecs[i].dx,
- can_go_in)) == True) {
+
pacman_
check_pos (pp, g->row + dirvecs[i].dy,
+
g->col + dirvecs[i].dx,
+
can_go_in)) == True) {
nrdirs++;
}
}
nrdirs++;
}
}
@@
-177,7
+177,7
@@
ghost_hiding (pacmangamestruct * pp, ghoststruct * g)
}
#if 1
}
#if 1
-void
+
static
void
clear_trace(ghoststruct *g)
{
int i = 0;
clear_trace(ghoststruct *g)
{
int i = 0;
@@
-245,7
+245,7
@@
clear_dir ( ghoststruct *g ){
static int
found_jail ( int col, int row ){
int cx, cy;
static int
found_jail ( int col, int row ){
int cx, cy;
- get_jail_opening ( &cx, &cy );
+
pacman_
get_jail_opening ( &cx, &cy );
cy += 1;
if (row == cy && col == cx )
return 1;
cy += 1;
if (row == cy && col == cx )
return 1;
@@
-261,7
+261,7
@@
move_ghost ( pacmangamestruct * pp,
int idx = (int)ps;
int tr = row + dirvecs[idx].dx;
int tc = col + dirvecs[idx].dy;
int idx = (int)ps;
int tr = row + dirvecs[idx].dx;
int tc = col + dirvecs[idx].dy;
- if ( check_pos ( pp, tr, tc, True )){
+ if (
pacman_
check_pos ( pp, tr, tc, True )){
*new_row = tr;
*new_col = tc;
return True;
*new_row = tr;
*new_col = tc;
return True;
@@
-310,7
+310,7
@@
recur_back_track ( pacmangamestruct * pp, ghoststruct *g, int row, int col ){
return False;
}
return False;
}
-void
+
static
void
find_home ( pacmangamestruct *pp, ghoststruct *g ){
int i;
int r,c;
find_home ( pacmangamestruct *pp, ghoststruct *g ){
int i;
int r,c;
@@
-332,7
+332,7
@@
find_home ( pacmangamestruct *pp, ghoststruct *g ){
c = tmp_ghost->col;
if ( ! recur_back_track ( pp, tmp_ghost, r, c ) ){
fprintf(stderr, "Could not find way home.#@$?\n");
c = tmp_ghost->col;
if ( ! recur_back_track ( pp, tmp_ghost, r, c ) ){
fprintf(stderr, "Could not find way home.#@$?\n");
- get_jail_opening ( &cx, &cy);
+
pacman_
get_jail_opening ( &cx, &cy);
fprintf(stderr, "Jail was at (%d%d)\n", cx,cy);
}
for ( i = 0; i < GHOST_TRACE; i++ ){
fprintf(stderr, "Jail was at (%d%d)\n", cx,cy);
}
for ( i = 0; i < GHOST_TRACE; i++ ){
@@
-388,7
+388,7
@@
pac_dot_vec (pacmangamestruct * pp, pacmanstruct * p, long *vx, long *vy)
for (y = by; y < ey; y++)
for (x = bx; x < ex; x++)
for (y = by; y < ey; y++)
for (x = bx; x < ex; x++)
- if (check_dot (pp, x, y) == 1) {
+ if (
pacman_
check_dot (pp, x, y) == 1) {
dx = (long) x - (long) (p->col);
dy = (long) y - (long) (p->row);
dist = dx * dx + dy * dy;
dx = (long) x - (long) (p->col);
dy = (long) y - (long) (p->row);
dist = dx * dx + dy * dy;
@@
-451,8
+451,8
@@
pac_get_posdirs (pacmangamestruct * pp, pacmanstruct * p, int *posdirs)
posdirs[i] = 0;
}
else if ((posdirs[i] =
posdirs[i] = 0;
}
else if ((posdirs[i] =
- check_pos (pp, p->row + dirvecs[i].dy,
- p->col + dirvecs[i].dx, 0)) == 1)
+
pacman_
check_pos (pp, p->row + dirvecs[i].dy,
+
p->col + dirvecs[i].dx, 0)) == 1)
nrdirs++;
}
p->state_change = 0;
nrdirs++;
}
p->state_change = 0;
@@
-462,7
+462,7
@@
pac_get_posdirs (pacmangamestruct * pp, pacmanstruct * p, int *posdirs)
/* Clears the trace of vectors. */
void
/* Clears the trace of vectors. */
void
-pac_clear_trace (pacmanstruct * p)
+pac
man
_clear_trace (pacmanstruct * p)
{
int i;
{
int i;
@@
-517,14
+517,14
@@
pac_eating (pacmangamestruct * pp, pacmanstruct * p)
4 * 4 && p->aistate == ps_eating) {
p->aistate = ps_hiding;
p->state_change = 1;
4 * 4 && p->aistate == ps_eating) {
p->aistate = ps_hiding;
p->state_change = 1;
- pac_clear_trace (p);
+ pac
man
_clear_trace (p);
}
if (prox > 6 * 6 && p->aistate == ps_hiding) {
p->aistate = ps_eating;
if (p->justate == 0)
p->state_change = 1;
}
if (prox > 6 * 6 && p->aistate == ps_hiding) {
p->aistate = ps_eating;
if (p->justate == 0)
p->state_change = 1;
- pac_clear_trace (p);
+ pac
man
_clear_trace (p);
}
if (prox < 3 * 3)
}
if (prox < 3 * 3)
@@
-567,7
+567,7
@@
pac_eating (pacmangamestruct * pp, pacmanstruct * p)
if (p->roundscore >= 12) {
p->roundscore = 0;
p->aistate = ps_random;
if (p->roundscore >= 12) {
p->roundscore = 0;
p->aistate = ps_random;
- pac_clear_trace (p);
+ pac
man
_clear_trace (p);
}
}
else
}
}
else
@@
-580,8
+580,8
@@
pac_eating (pacmangamestruct * pp, pacmanstruct * p)
if (posdirs[i] == 0)
continue;
score = dirvecs[i].dx * vx + dirvecs[i].dy * vy;
if (posdirs[i] == 0)
continue;
score = dirvecs[i].dx * vx + dirvecs[i].dy * vy;
- if (check_dot (pp, p->col + dirvecs[i].dx,
- p->row + dirvecs[i].dy) == 1) {
+ if (
pacman_
check_dot (pp, p->col + dirvecs[i].dx,
+
p->row + dirvecs[i].dy) == 1) {
if (dotfound == 0) {
highest = score;
dir = i;
if (dotfound == 0) {
highest = score;
dir = i;
@@
-609,10
+609,8
@@
static void
pac_chasing (pacmangamestruct * pp, pacmanstruct * p)
{
int posdirs[DIRVECS], nrdirs, i, highest = -(1 << 16),
pac_chasing (pacmangamestruct * pp, pacmanstruct * p)
{
int posdirs[DIRVECS], nrdirs, i, highest = -(1 << 16),
- score, dir = 0, prox, worst = 0;
- int vx, vy;
-
- prox = pac_ghost_prox_and_vector (pp, p, &vx, &vy);
+ score, dir = 0, worst = 0;
+ int vx = 0, vy = 0;
nrdirs = pac_get_posdirs (pp, p, posdirs);
nrdirs = pac_get_posdirs (pp, p, posdirs);
@@
-629,7
+627,6
@@
pac_chasing (pacmangamestruct * pp, pacmanstruct * p)
}
nrdirs--;
posdirs[worst] = 0;
}
nrdirs--;
posdirs[worst] = 0;
- highest = -(1 << 16);
/* get last possible direction if all else fails */
/* get last possible direction if all else fails */
@@
-650,7
+647,7
@@
pac_chasing (pacmangamestruct * pp, pacmanstruct * p)
if (p->roundscore >= 12) {
p->roundscore = 0;
p->aistate = ps_random;
if (p->roundscore >= 12) {
p->roundscore = 0;
p->aistate = ps_random;
- pac_clear_trace (p);
+ pac
man
_clear_trace (p);
}
}
else
}
}
else
@@
-677,7
+674,7
@@
pac_random (pacmangamestruct * pp, pacmanstruct * p)
if (NRAND (20) == 0) {
p->aistate = ps_eating;
p->state_change = 1;
if (NRAND (20) == 0) {
p->aistate = ps_eating;
p->state_change = 1;
- pac_clear_trace (p);
+ pac
man
_clear_trace (p);
}
nrdirs = pac_get_posdirs (pp, p, posdirs);
}
nrdirs = pac_get_posdirs (pp, p, posdirs);
@@
-686,12
+683,12
@@
pac_random (pacmangamestruct * pp, pacmanstruct * p)
if (posdirs[i] == 0)
continue;
lastdir = i;
if (posdirs[i] == 0)
continue;
lastdir = i;
- if (check_dot (pp, p->col + dirvecs[i].dx,
- p->row + dirvecs[i].dy) == 1) {
+ if (
pacman_
check_dot (pp, p->col + dirvecs[i].dx,
+
p->row + dirvecs[i].dy) == 1) {
dir = i;
p->aistate = ps_eating;
p->state_change = 1;
dir = i;
p->aistate = ps_eating;
p->state_change = 1;
- pac_clear_trace (p);
+ pac
man
_clear_trace (p);
break;
}
else if (NRAND (nrdirs) == 0)
break;
}
else if (NRAND (nrdirs) == 0)
@@
-772,7
+769,7
@@
pac_trackmouse (ModeInfo * mi, pacmangamestruct * pp, pacmanstruct * p)
/* Calls correct state function, and changes between states. */
void
/* Calls correct state function, and changes between states. */
void
-ghost_update (pacmangamestruct * pp, ghoststruct * g)
+
pacman_
ghost_update (pacmangamestruct * pp, ghoststruct * g)
{
if (!(g->nextrow == NOWHERE && g->nextcol == NOWHERE)) {
{
if (!(g->nextrow == NOWHERE && g->nextcol == NOWHERE)) {
@@
-836,7
+833,7
@@
ghost_update (pacmangamestruct * pp, ghoststruct * g)
/* Calls correct pacman state function. */
void
/* Calls correct pacman state function. */
void
-pac_update (ModeInfo * mi, pacmangamestruct * pp, pacmanstruct * p)
+pac
man
_update (ModeInfo * mi, pacmangamestruct * pp, pacmanstruct * p)
{
if (!(p->nextrow == NOWHERE && p->nextcol == NOWHERE)) {
p->row = p->nextrow;
{
if (!(p->nextrow == NOWHERE && p->nextcol == NOWHERE)) {
p->row = p->nextrow;
@@
-846,15
+843,15
@@
pac_update (ModeInfo * mi, pacmangamestruct * pp, pacmanstruct * p)
if (pp->level[p->row * LEVWIDTH + p->col] == '.' ||
pp->level[p->row * LEVWIDTH + p->col] == 'o') {
pp->level[p->row * LEVWIDTH + p->col] = ' ';
if (pp->level[p->row * LEVWIDTH + p->col] == '.' ||
pp->level[p->row * LEVWIDTH + p->col] == 'o') {
pp->level[p->row * LEVWIDTH + p->col] = ' ';
- if (!trackmouse)
+ if (!
pacman_
trackmouse)
p->justate = 1;
pp->dotsleft--;
}
p->justate = 1;
pp->dotsleft--;
}
- else if (!trackmouse) {
+ else if (!
pacman_
trackmouse) {
p->justate = 0;
}
p->justate = 0;
}
- if (!(trackmouse && pac_trackmouse (mi, pp, p))) {
+ if (!(
pacman_
trackmouse && pac_trackmouse (mi, pp, p))) {
/* update pacman */
switch (p->aistate) {
case ps_eating:
/* update pacman */
switch (p->aistate) {
case ps_eating: