예제 #1
0
        public Ways PosibleWay(int a, int b)
        {
            Ways w = new Ways();                        // inicialization to false

            w.free = 0;
            w.ways = new bool[4];
            for (int i = 0; i < 4; i++)
            {
                w.ways[i] = false;
            }

            if (CheckIn(a, b - 1))
            {
                w.ways[(int)Direction.up] = true; w.free++;
            }
            if (CheckIn(a, b + 1))
            {
                w.ways[(int)Direction.down] = true; w.free++;
            }
            if (CheckIn(a - 1, b))
            {
                w.ways[(int)Direction.left] = true; w.free++;
            }
            if (CheckIn(a + 1, b))
            {
                w.ways[(int)Direction.right] = true; w.free++;
            }                                                                                   // right
            return(w);
        }
예제 #2
0
        protected Direction TwoWays(Ghost g, Ways w, Point pacPoint)
        {
            Direction first  = Direction.down;
            Direction second = Direction.up;
            bool      was    = false;

            for (int i = 0; i <= 3; i++)
            {
                if (w.ways[i])
                {
                    if (!was)
                    {
                        first = (Direction)i; was = true;
                    }
                    else
                    {
                        second = ((Direction)i);
                    }
                }
            }

            if (1 == PacmanNear(Figure.Shift(first, g.position), Figure.Shift(second, g.position), pacPoint))
            {
                return((Direction)first);
            }
            else
            {
                return((Direction)second);
            }
        }
예제 #3
0
        public virtual Direction MakeDecision(Ghost g, Point pacPoint, Map map)
        {
            this.ways = g.mapa.PosibleWay( g.position ); 		// Bool array of posible way
            this.rnd = new Random();

            if( rnd.Next(1,9) == 5) return ((Direction) rnd.Next(0,4));  // Random element

            bool pravda = true;
            switch( this.ways.free )
            {
            case 1:				/* Turn round */
                if(pravda) return OneWay(g);
                break;
            case 2: 			/* go straight */
                if(pravda) return TwoWays(g);
                break;
            case 3: 			/* prefer 2 ways */
                if (pravda) return ThreeWays(g, this.ways);
                break;
            case 4: 			/* totaly random */
                if(pravda) return FourWays(g.direction);
                break;
            default :
                return ((Direction) rnd.Next(0,4));
            }

            return (Direction) rnd.Next(0,3);
        }
예제 #4
0
        protected Direction ThreeWays(Ghost g, Ways w, Point pacPoint)
        {
            Direction secondary;
            Direction primary1 = Direction.up;
            Direction primary2 = Direction.down;
            bool was = false;
            byte decision;

            secondary = Reverse(g.direction);
            w.ways[(int) secondary] = false;

            for(int i = 0; i <=3;i++)
            {
                if(w.ways[i]) {
                    if(!was) { primary1 = ((Direction) i); was =true; }
                    else primary2 = ((Direction) i);
                }
            }

            if(rnd.Next(0,9) == 4) decision = (byte) rnd.Next(1,3);
            else
                if(rnd.Next(0,5) == 2) decision = PacmanNear( Figure.Shift(primary1 , g.position), Figure.Shift( primary2 , g.position ), Figure.Shift(secondary, g.position), pacPoint);
                else decision = PacmanNear( Figure.Shift(primary1,g.position), Figure.Shift( primary2, g.position ), pacPoint);

            if(decision == 1) return primary1;
            if(decision == 2) return primary2;
            return secondary;
        }
예제 #5
0
        protected Direction ThreeWays(Ghost g, Ways w, Point pacPoint)
        {
            Direction secondary;
            Direction primary1 = Direction.up;
            Direction primary2 = Direction.down;
            bool      was      = false;
            byte      decision;

            secondary = Reverse(g.direction);
            w.ways[(int)secondary] = false;

            for (int i = 0; i <= 3; i++)
            {
                if (w.ways[i])
                {
                    if (!was)
                    {
                        primary1 = ((Direction)i); was = true;
                    }
                    else
                    {
                        primary2 = ((Direction)i);
                    }
                }
            }

            if (rnd.Next(0, 9) == 4)
            {
                decision = (byte)rnd.Next(1, 3);
            }
            else
            if (rnd.Next(0, 5) == 2)
            {
                decision = PacmanNear(Figure.Shift(primary1, g.position), Figure.Shift(primary2, g.position), Figure.Shift(secondary, g.position), pacPoint);
            }
            else
            {
                decision = PacmanNear(Figure.Shift(primary1, g.position), Figure.Shift(primary2, g.position), pacPoint);
            }

            if (decision == 1)
            {
                return(primary1);
            }
            if (decision == 2)
            {
                return(primary2);
            }
            return(secondary);
        }
예제 #6
0
        protected Direction TwoWays(Ghost g, Ways w, Point pacPoint)
        {
            Direction first = Direction.down;
            Direction second = Direction.up;
            bool was = false;
            for(int i = 0; i <=3;i++)
                if(w.ways[i]) {
                    if(!was) { first = (Direction) i; was =true; }
                    else second = ((Direction) i);
                }

            if(1 == PacmanNear( Figure.Shift(first, g.position), Figure.Shift(second, g.position), pacPoint)) return (Direction) first;
            else return (Direction) second;
        }
예제 #7
0
        public virtual Direction MakeDecision(Ghost g, Point pacPoint, Map map)
        {
            this.ways = g.mapa.PosibleWay(g.position);                          // Bool array of posible way
            this.rnd  = new Random();

            if (rnd.Next(1, 9) == 5)
            {
                return((Direction)rnd.Next(0, 4));                                   // Random element
            }
            bool pravda = true;

            switch (this.ways.free)
            {
            case 1:                                     /* Turn round */
                if (pravda)
                {
                    return(OneWay(g));
                }
                break;

            case 2:                                     /* go straight */
                if (pravda)
                {
                    return(TwoWays(g));
                }
                break;

            case 3:                                     /* prefer 2 ways */
                if (pravda)
                {
                    return(ThreeWays(g, this.ways));
                }
                break;

            case 4:                                     /* totaly random */
                if (pravda)
                {
                    return(FourWays(g.direction));
                }
                break;

            default:
                return((Direction)rnd.Next(0, 4));
            }

            return((Direction)rnd.Next(0, 3));
        }
예제 #8
0
        protected virtual Direction ThreeWays(Ghost g, Ways w)
        {
            Direction secondary;
            Direction primary1 = Direction.up;
            Direction primary2 = Direction.down;
            bool      was      = false;

            secondary = Reverse(g.direction);

            for (int i = 0; i <= 3; i++)
            {
                if (w.ways[i])
                {
                    if (!was)
                    {
                        primary1 = (Direction)i; was = true;
                    }
                    else
                    {
                        primary2 = ((Direction)i);
                    }
                }
            }

            switch (rnd.Next(0, 7))
            {
            case 0:
            case 2:
            case 4:
                return(primary1);

                break;

            case 1:
            case 3:
            case 5:
                return(primary2);

                break;

            default:
                return(secondary);

                break;
            }
        }
예제 #9
0
        protected virtual Direction ThreeWays(Ghost g, Ways w )
        {
            Direction secondary;
            Direction primary1 = Direction.up;
            Direction primary2 = Direction.down;
            bool was = false;

            secondary = Reverse(g.direction);

            for(int i = 0; i <=3;i++)
                if(w.ways[i]) {
                    if(!was) { primary1 = (Direction) i; was =true; }
                    else primary2 = ((Direction) i);
                }

            switch(rnd.Next(0,7))
            {
            case 0:
            case 2:
            case 4:
                return primary1;
                break;
            case 1:
            case 3:
            case 5:
                return primary2;
                break;
            default :
                return secondary;
                break;
            }
        }
예제 #10
0
        public Ways PosibleWay(int a, int b)
        {
            Ways w = new Ways(); 		// inicialization to false
            w.free = 0;
            w.ways = new bool[4];
            for(int i = 0; i<4; i++) w.ways[i] = false;

            if(CheckIn(a, b-1)) { w.ways[(int) Direction.up  ] = true; w.free++; }
            if(CheckIn(a, b+1)) { w.ways[(int) Direction.down] = true; w.free++; }
            if(CheckIn(a-1, b))	{ w.ways[(int) Direction.left] = true; w.free++; }
            if(CheckIn(a+1, b)) { w.ways[(int) Direction.right] = true; w.free++; }	// right
            return w;
        }