Example #1
0
        protected override void computeTargetTile(PacMan pac, Ghost ghost)
        {
            //We target a different point according to the mode
            switch (this.mode)
            {
            //We target a fixed point in Scatter mode
            case Mode.Scatter:
                this.target = new Position(-1, 26);
                break;

            //We target the center of the square to stay in it
            case Mode.StayIn:
                target = new Position(14, 14);
                break;

            case Mode.GoOut:     //We target outside the square
                target = new Position(0, 13);
                break;

            case Mode.Normal:
                //We target the player
                this.target = new Position(pac.getPosition().getPosX(), pac.getPosition().getPosY());
                break;
            }
        }
Example #2
0
        protected override void computeTargetTile(PacMan pac, Ghost ghost)
        {
            switch (this.mode)
            {
            //We target different points according to the mode
            case Mode.Scatter:
                target = new Position(32, 0);     //We target a fixed point
                break;

            case Mode.StayIn:
                target = new Position(14, 14);     //We target the center of the square to stay in iy
                break;

            case Mode.GoOut:
                target = new Position(0, 14);     //We target outside of the square
                break;

            case Mode.Normal:

                //We target either the scatter point or the pacman
                int distance = manhattanDistance(pac.getPosition(), this.getPosition());
                if (distance < 8)     //If we are at less than 8 tiles away from the pacman
                {
                    //We target the scatter position
                    target = new Position(32, 0);
                }
                else
                {
                    //We have the same target has the red ghost
                    target = new Position(pac.getPosition().getPosX(), pac.getPosition().getPosY());
                }
                break;
            }
        }
Example #3
0
        //Overriding computeTargetTile so that we can have a different target
        protected override void computeTargetTile(PacMan pac, Ghost ghost)
        {
            switch (this.mode)
            {
            case Mode.Scatter:     //If we are in Scatter mode, we target a fixed point in the corner of the map
                target = new Position(32, 28);
                break;

            case Mode.StayIn:     //We stay in the center
                target = new Position(14, 14);
                break;

            case Mode.GoOut:     //We target outside the center
                target = new Position(0, 14);
                break;

            case Mode.Normal:     //We chase the player

                //This ghost target two tiles ahead of the pacman, and create a vector from this
                //new position and the position of the red ghost, this vector timed by 2 gives
                //The target of the blue ghost.
                Position tmp = twoAhead(pac.getState(), pac.getPosition());
                int      xg  = ghost.getPosition().getPosX();
                int      yg  = ghost.getPosition().getPosY();
                int      xp  = pac.getPosition().getPosX();
                int      yp  = pac.getPosition().getPosY();
                target = new Position(2 * xp - xg, 2 * yp - yg);
                break;
            }
        }
Example #4
0
        protected override void computeTargetTile(PacMan pac, Ghost ghost)
        {
            //We target a different point according to the mode
            switch (this.mode)
            {
            case Mode.Scatter:
                target = new Position(-1, 2);     //We target a fixed point in a corner
                break;

            case Mode.StayIn:
                target = new Position(14, 14);     //We target the center of the square to stay in it
                break;

            case Mode.GoOut:     //We target outside of the square
                target = new Position(0, 14);
                break;

            case Mode.Normal:
                //This ghost targets four tiles ahead of the pacman
                Position pos = fourAhead(pac.getState(), pac.getPosition());
                if (pac.getState() == State.Up)
                {
                    //According to an overflow bug in the original version,
                    //When the pacman is heading up, the target was also four tiles to the left.
                    //For a purpose of keeping the same artificial intelligence, we decided to keep this
                    //even though it does not causes any bug today.
                    pos.setPosY(pos.getPosY() - 4);
                }
                target = pos;
                break;
            }
        }
Example #5
0
 //Initialize every items
 public void restart()
 {
     map = new Map();
     map.countBeans();   //We count the number of beans on the map only once so we can check more quickly afterward.
     pacMan                   = new PacMan();
     ghosts                   = new Ghost[4];
     ghosts[0]                = new RedGhost();
     ghosts[1]                = new PinkGhost();
     ghosts[2]                = new YellowGhost();
     ghosts[3]                = new BlueGhost();
     gamePlay                 = GamePlay.Normal;
     hasEaten                 = false;
     score                    = 0;
     countersFixed            = new int[4, 2];
     countersChanging         = new int[4, 2];
     vulnerabitlitiesFixed    = new int[4];
     vulnerabitlitiesChanging = new int[4];
     scatter                  = new Boolean[4];
     turnToGoOut              = new int[4];
     for (int i = 0; i < 4; i++)
     {
         countersFixed[i, 0]         = 20;
         countersFixed[i, 1]         = 50;
         countersChanging[i, 0]      = 0;
         countersChanging[i, 1]      = 0;
         vulnerabitlitiesFixed[i]    = 175;
         vulnerabitlitiesChanging[i] = 0;
         scatter[i]     = false;
         turnToGoOut[i] = 0;
     }
 }
Example #6
0
        public void computeNextMove(PacMan pac, Ghost ghost, Map map)
        {
            //Each loop turn this method is called
            resetIntersect(); //We say that every intersections is possible
            if (this.aggressivity == Aggressivity.aggresive)
            {
                //If the ghost chase the pacman
                computeTargetTile(pac, ghost); //We calculate the target
                //Each ghost will have a different target to make the game easier to play


                checkIntersection(map); //We check if there was an intersection and we forbid the ones with walls
                computeState();         //We deduce a direction
            }
            else
            {
                //If the pacman chase the ghost
                computeAwayTile(pac, map); //We calculate the furthest point from the pacman
                checkIntersection(map);    //We as well check intersections
                reverse();                 //We reverse the direction if we were going toward the pacman
            }
        }
Example #7
0
        private void computeAwayTile(PacMan pac, Map map)
        {
            double   distance = 0;
            double   dist;
            Position pacPos = pac.getPosition();
            Position ret    = new Position(0, 0);

            //For each tiles of the map, we store the furthest
            for (int i = 0; i < map.getVX(); i++)
            {
                for (int j = 0; j < map.getVY(); j++)
                {
                    Position tmp = new Position(i, j);
                    dist = euclidianDistance(pacPos, tmp);
                    if (dist >= distance)
                    {
                        distance = dist;
                        ret.setPosXY(tmp.getPosX(), tmp.getPosY());
                    }
                }
            }

            target = ret; //We target the furthests point
        }
Example #8
0
 //This method will be overwritten by every ghosts because they don't treat target the same way
 protected virtual void  computeTargetTile(PacMan pac, Ghost ghost)
 {
     //To override
 }