From b3aa774ad8ae88fe15a6160750b8d5d5462f4aec Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Mon, 4 Nov 2024 07:44:03 +0100 Subject: [PATCH] WIP for ghost moves --- constant.h | 1 + pacman.c | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/constant.h b/constant.h index 5a790ad..a28f686 100644 --- a/constant.h +++ b/constant.h @@ -7,6 +7,7 @@ #ifndef __CONSTANT_C__ +#define MAXNBGHOSTS 4 extern int maxnbturns; extern int turnspan; extern int savelen; diff --git a/pacman.c b/pacman.c index 8bc68c6..536445f 100644 --- a/pacman.c +++ b/pacman.c @@ -74,6 +74,7 @@ void getnewposition (board_t *board, int dir, int x, int y, int *px, int *py) /* main function */ int main (int argc, char *argv[]) { + int i; /* get basename */ char *pt = progname = argv[0]; @@ -190,8 +191,23 @@ int main (int argc, char *argv[]) if (findchar (board, 'c', &x, &y)) { VERBOSE (WARNING, printf ("can't find Pacman\n")); } + int dir = -1; int nx = x; int ny = y; + int ndir = dir; + + /* ghost positions */ + int gx[MAXNBGHOSTS] = {0}; + int gy[MAXNBGHOSTS] = {0}; + for (i = 0; i < MAXNBGHOSTS; i++) { + if ((findchar (board, 'P' + i, gx + i, gy + i)) && + (findchar (board, 'p' + i, gx + i, gy + i)) && + (findchar (board, '$' + i, gx + i, gy + i))) { + VERBOSE ((i == 0) ? WARNING : INFO, printf ("can't find Ghost n°%d\n", i)); + } + } + int gdir[MAXNBGHOSTS] = {-1, -1, -1, -1}; + int gdelay[MAXNBGHOSTS] = {5, 10, 15, 20}; /* event loop */ int stop = 0; @@ -201,8 +217,6 @@ int main (int argc, char *argv[]) timeval_t turn = {0, 0}; int delta = 0; int nbturns = 0; - int dir = -1; - int ndir = -1; int spin = 0; while (!stop) { @@ -283,6 +297,25 @@ int main (int argc, char *argv[]) refresh (); spin = 0; + /* move ghosts */ + for (i = 0; i < MAXNBGHOSTS; i++) { + char *cell = getcell (board, gx[i], gy[i]); + if (*cell == 'x' + i) { + } else if ((*cell == 'P' + i) || (*cell == 'p' + i)) { + int gnx, gny; + getnewposition (board, gdir[i], gx[i], gy[i], &gnx, &gny); + cell = getcell (board, gnx, gny); + } else if ((*cell != '*') && (*cell != '.') && (*cell != ' ')) { + // + //int *ncell = getcell (board, gnx, gny); + if ((*cell == 'C') || (*cell == 'c')) { + + } + } else if (*cell == '$' + i) { + gdelay[i]--; + } + } + } else if ((delta > turnspan / 2) && (spin == 0)) { /* pacman mouth close */ -- 2.30.2