Exemplo n.º 1
0
        public ScorpionRed scorpionMove(short[][][] maze, Human man)
        {//Horizontal then vertical
            // This method was written using a different logic than the current one
            ScorpionRed tam = new ScorpionRed(this.getX(), this.getY());

            if (tam.samePlace(man))
            {
                return(tam);
            }
            else
            {
                Mummy.setAttempt(0);
                Mummy.setCount(0);
                while ((Mummy.getAttempt() < 5) && (Mummy.getCount() < 1))
                {
                    while (this.getX() != man.getX())
                    {
                        tam = tam.mummyMoveVertical(maze, man);
                        if (!(Mummy.getCount() < 1))
                        {
                            return(tam);
                        }
                        if (Mummy.getAttempt() > 4)
                        {
                            break;
                        }
                    }
                    if (tam.samePlace(man))
                    {
                        return(tam);
                    }
                    tam = tam.mummyMoveHorizontal(maze, man);
                    if ((tam.samePlace(man)) || (!(Mummy.getCount() < 1)))
                    {
                        return(tam);
                    }
                }
                return(tam);
            }
        }
Exemplo n.º 2
0
        public MummyRed mummyRedMove(short[][][] maze, Human man)
        {// Vertical then horizontal
            MummyRed tam = new MummyRed(this.getX(), this.getY());

            if (tam.samePlace(man))
            {
                return(tam);
            }
            else
            {
                Mummy.setAttempt(0);
                Mummy.setCount(0);
                while ((Mummy.getAttempt() < 5) && (Mummy.getCount() < 1))
                {
                    while (tam.getX() != man.getX())
                    {
                        tam = (MummyRed)tam.mummyMoveVertical(maze, man);
                        if (!(Mummy.getCount() < 1))
                        {
                            return(tam);
                        }
                        if (Mummy.getAttempt() > 4)
                        {
                            break;
                        }
                    }
                    if (tam.samePlace(man))
                    {
                        return(tam);
                    }
                    tam = (MummyRed)tam.mummyMoveHorizontal(maze, man);
                    if ((tam.samePlace(man)) || (!(Mummy.getCount() < 1)))
                    {
                        return(tam);
                    }
                }
                return(tam);
            }
        }
Exemplo n.º 3
0
        public State testOfMummy(State state)
        {
            State temp = state;

            // Creating temporary saving arrays
            short[][][] mazee = (short[][][])temp.getMaze().Clone();
            for (int i = 0; i < mazee.Length; i++)
            {
                for (int j = 0; j < mazee[0].Length; j++)
                {
                    System.Array.Copy(temp.getMaze()[i][j], 0, mazee[i][j], 0, mazee[0][0].Length);
                }
            }
            MummyWhite[]    updateWhite = (MummyWhite[])temp.getMummyWhite().Clone();
            MummyRed[]      updateRed   = (MummyRed[])temp.getMummyRed().Clone();
            ScorpionWhite[] updateSk    = (ScorpionWhite[])temp.getSk().Clone();
            ScorpionRed[]   updateSkRed = (ScorpionRed[])temp.getSkRed().Clone();

            // Move
            for (int i = 0; i < updateWhite.Length; i++)
            {
                Mummy compare = new Mummy(updateWhite[i].getX(), updateWhite[i].getY());
                updateWhite[i] = updateWhite[i].mummyWhiteMove(temp.getMaze(), temp.getHuman());
                temp.setMummyWhite(updateWhite);
                if (temp.getMummyWhite()[i].samePlace(this))
                {
                    temp.setStep((short)-1);
                    return(temp);
                }
                else
                {
                    if (!compare.samePlace(updateWhite[i]))
                    { //i.e. Mummy did move
                        temp = keyCheck(temp, updateWhite[i]);
                    }
                }
            }
            for (int i = 0; i < updateRed.Length; i++)
            {
                Mummy compare = new Mummy(updateRed[i].getX(), updateRed[i].getY());
                updateRed[i] = updateRed[i].mummyRedMove(temp.getMaze(), temp.getHuman());
                temp.setMummyRed(updateRed);
                if (this.samePlace(temp.getMummyRed()[i]))
                {
                    temp.setStep((short)-1);
                    return(temp);
                }
                else
                {
                    if (!compare.samePlace(updateRed[i]))
                    { //i.e. Mummy did move
                        temp = keyCheck(temp, updateRed[i]);
                    }
                }
            }
            for (int i = 0; i < updateSk.Length; i++)
            {
                Mummy compare = new Mummy(updateSk[i].getX(), updateSk[i].getY());
                updateSk[i] = updateSk[i].scorpionMove(temp.getMaze(), temp.getHuman());
                temp.setSk(updateSk);
                if (this.samePlace(temp.getSk()[i]))
                {
                    temp.setStep((short)-1);
                    return(temp);
                }
                else
                {
                    if (!compare.samePlace(updateSk[i]))
                    { //i.e. Mummy did move
                        temp = keyCheck(temp, updateSk[i]);
                    }
                }
            }
            for (int i = 0; i < updateSkRed.Length; i++)
            {
                Mummy compare = new Mummy(updateSkRed[i].getX(), updateSkRed[i].getY());
                updateSkRed[i] = updateSkRed[i].scorpionMove(temp.getMaze(), temp.getHuman());
                temp.setSkRed(updateSkRed);
                if (this.samePlace(temp.getSkRed()[i]))
                {
                    temp.setStep((short)-1);
                    return(temp);
                }
                else
                {
                    if (!compare.samePlace(updateSkRed[i]))
                    { //i.e. Mummy did move
                        temp = keyCheck(temp, updateSkRed[i]);
                    }
                }
            }
            temp.setMaze(mazee);
            temp.setMummyWhite(updateWhite);
            temp.setMummyRed(updateRed);
            temp.setSk(updateSk);
            temp.setSkRed(updateSkRed);

            //Check for fighting
            temp        = fightCheck(temp);
            updateWhite = temp.getMummyWhite();
            updateRed   = temp.getMummyRed();
            updateSk    = temp.getSk();
            updateSkRed = temp.getSkRed();

            // Move (2nd step for Mummy)
            for (int i = 0; i < updateWhite.Length; i++)
            {
                Mummy compare = new Mummy(updateWhite[i].getX(), updateWhite[i].getY());
                updateWhite[i] = updateWhite[i].mummyWhiteMove(temp.getMaze(), temp.getHuman());
                temp.setMummyWhite(updateWhite);
                if (temp.getMummyWhite()[i].samePlace(this))
                {
                    temp.setStep((short)-1);
                    return(temp);
                }
                else
                {
                    if (!compare.samePlace(updateWhite[i]))
                    { //i.e. Mummy did move
                        temp = keyCheck(temp, updateWhite[i]);
                    }
                }
            }
            for (int i = 0; i < updateRed.Length; i++)
            {
                Mummy compare = new Mummy(updateRed[i].getX(), updateRed[i].getY());
                updateRed[i] = updateRed[i].mummyRedMove(temp.getMaze(), temp.getHuman());
                temp.setMummyRed(updateRed);
                if (this.samePlace(temp.getMummyRed()[i]))
                {
                    temp.setStep((short)-1);
                    return(temp);
                }
                else
                {
                    if (!compare.samePlace(updateRed[i]))
                    { //i.e. Mummy did move
                        temp = keyCheck(temp, updateRed[i]);
                    }
                }
            }

            //Check for fighting again
            temp = fightCheck(temp);

            temp.setMaze(mazee);
            temp.setMummyWhite(updateWhite);
            temp.setMummyRed(updateRed);
            temp.setSk(updateSk);
            temp.setSkRed(updateSkRed);
            return(temp);
        }