Beispiel #1
0
        public Direction Move(NeighbourMap map, Board board)
        {
            Direction[] directions = new Direction[4];
            int         peak       = 0;

            if (map.Down != null && map.Down.Full)
            {
                directions [peak] = Direction.Down;
                peak += 1;
            }
            if (map.Up != null && map.Up.Full)
            {
                directions [peak] = Direction.Up;
                peak += 1;
            }
            if (map.Left != null && map.Left.Full)
            {
                directions [peak] = Direction.Left;
                peak += 1;
            }
            if (map.Right != null && map.Right.Full)
            {
                directions [peak] = Direction.Right;
                peak += 1;
            }

            return(directions [random.Next(0, peak)]);
        }
Beispiel #2
0
        protected void sniff(NeighbourMap map, Board board)
        {
            moveRate = moveRateStep;

            int[,] record = new int[board.Width, board.Height];
            for (int i = 0; i < record.GetLength(0); i++)
            {
                for (int j = 0; j < record.GetLength(1); j++)
                {
                    record [i, j] = -1;
                }
            }
            record [map.Current.X, map.Current.Y] = 0;

            Queue <Field> queue = new Queue <Field> ();

            queue.Enqueue(map.Current);
            Field target = board.Player.BaseField;

            while (queue.Count > 0)
            {
                Field field = queue.Dequeue();
                if (field == target)
                {
                    break;
                }
                foreach (Field neighbour in board.GetNeighbours(field))
                {
                    if (neighbour.Full && record [neighbour.X, neighbour.Y] == -1)
                    {
                        record [neighbour.X, neighbour.Y] = record [field.X, field.Y] + 1;
                        queue.Enqueue(neighbour);
                    }
                }
            }

            path = new Stack <Field> ();
            path.Push(target);

            for (int i = record[target.X, target.Y] - 1; i > 0; i--)
            {
                foreach (Field neighbour in board.GetNeighbours(target))
                {
                    if (record [neighbour.X, neighbour.Y] == i)
                    {
                        path.Push(neighbour);
                        target = neighbour;
                        break;
                    }
                }
            }
        }
Beispiel #3
0
 protected void turnAnywhere(NeighbourMap map)
 {
     if (map.Left != null && map.Left.Full) {
         direction = Direction.Left;
     } else if (map.Up != null && map.Up.Full) {
         direction = Direction.Up;
     } else if (map.Right != null && map.Right.Full) {
         direction = Direction.Right;
     } else if (map.Down != null && map.Down.Full) {
         direction = Direction.Down;
     } else {
         direction = Direction.None;
     }
 }
Beispiel #4
0
 protected Field rightHand(NeighbourMap map)
 {
     switch (direction) {
     case Direction.Down:
         return map.Left;
     case Direction.Left:
         return map.Up;
     case Direction.Right:
         return map.Down;
     case Direction.Up:
         return map.Right;
     }
     return map.Current;
 }
Beispiel #5
0
 public Direction Move(NeighbourMap map, Board board)
 {
     if (moveRate > 0 && path.Count > 0 && random.NextDouble () < moveRate) {
         moveRate *= moveRateStep;
     } else {
         if (wait == 0) {
             sniff (map, board);
             wait = 30;
         } else {
             wait -= 1;
         }
         return Direction.None;
     }
     return getDirection (map.Current, path.Pop ());
 }
Beispiel #6
0
        public Direction Move(NeighbourMap map, Board board)
        {
            if (direction == Direction.None) {
                turnAnywhere (map);
            } else {
                if (rightHand (map) != null && !rightHand (map).Full) {
                    while (front(map) == null || !front (map).Full) {
                        turnLeft ();
                    }
                } else {
                    turnRight ();
                }
            }

            return direction;
        }
Beispiel #7
0
        protected Field rightHand(NeighbourMap map)
        {
            switch (direction)
            {
            case Direction.Down:
                return(map.Left);

            case Direction.Left:
                return(map.Up);

            case Direction.Right:
                return(map.Down);

            case Direction.Up:
                return(map.Right);
            }
            return(map.Current);
        }
Beispiel #8
0
        protected void sniff(NeighbourMap map, Board board)
        {
            moveRate = moveRateStep;

            int[,] record = new int[board.Width, board.Height];
            for (int i = 0; i < record.GetLength(0); i++) {
                for (int j = 0; j < record.GetLength(1); j++) {
                    record [i, j] = -1;
                }
            }
            record [map.Current.X, map.Current.Y] = 0;

            Queue<Field> queue = new Queue<Field> ();
            queue.Enqueue (map.Current);
            Field target = board.Player.BaseField;

            while (queue.Count > 0) {
                Field field = queue.Dequeue ();
                if (field == target) {
                    break;
                }
                foreach (Field neighbour in board.GetNeighbours(field)) {
                    if (neighbour.Full && record [neighbour.X, neighbour.Y] == -1) {
                        record [neighbour.X, neighbour.Y] = record [field.X, field.Y] + 1;
                        queue.Enqueue (neighbour);
                    }
                }
            }

            path = new Stack<Field> ();
            path.Push (target);

            for (int i = record[target.X, target.Y] - 1; i > 0; i--) {
                foreach (Field neighbour in board.GetNeighbours(target)) {
                    if (record [neighbour.X, neighbour.Y] == i) {
                        path.Push (neighbour);
                        target = neighbour;
                        break;
                    }
                }
            }
        }
Beispiel #9
0
 public Direction Move(NeighbourMap map, Board board)
 {
     if (moveRate > 0 && path.Count > 0 && random.NextDouble() < moveRate)
     {
         moveRate *= moveRateStep;
     }
     else
     {
         if (wait == 0)
         {
             sniff(map, board);
             wait = 30;
         }
         else
         {
             wait -= 1;
         }
         return(Direction.None);
     }
     return(getDirection(map.Current, path.Pop()));
 }
Beispiel #10
0
        public Direction Move(NeighbourMap map, Board board)
        {
            if (direction == Direction.None)
            {
                turnAnywhere(map);
            }
            else
            {
                if (rightHand(map) != null && !rightHand(map).Full)
                {
                    while (front(map) == null || !front(map).Full)
                    {
                        turnLeft();
                    }
                }
                else
                {
                    turnRight();
                }
            }

            return(direction);
        }
Beispiel #11
0
 protected void turnAnywhere(NeighbourMap map)
 {
     if (map.Left != null && map.Left.Full)
     {
         direction = Direction.Left;
     }
     else if (map.Up != null && map.Up.Full)
     {
         direction = Direction.Up;
     }
     else if (map.Right != null && map.Right.Full)
     {
         direction = Direction.Right;
     }
     else if (map.Down != null && map.Down.Full)
     {
         direction = Direction.Down;
     }
     else
     {
         direction = Direction.None;
     }
 }
Beispiel #12
0
        public Direction Move(NeighbourMap map, Board board)
        {
            Direction[] directions = new Direction[4];
            int peak = 0;

            if (map.Down != null && map.Down.Full) {
                directions [peak] = Direction.Down;
                peak += 1;
            }
            if (map.Up != null && map.Up.Full) {
                directions [peak] = Direction.Up;
                peak += 1;
            }
            if (map.Left != null && map.Left.Full) {
                directions [peak] = Direction.Left;
                peak += 1;
            }
            if (map.Right != null && map.Right.Full) {
                directions [peak] = Direction.Right;
                peak += 1;
            }

            return directions [random.Next (0, peak)];
        }
Beispiel #13
0
 public void StartMove(NeighbourMap map, Board board)
 {
     StartMove(strategy.Move(map, board));
 }