Esempio n. 1
0
        public MoveChoice RouteToPoint(Point location, Point goal, char[,] board, int MaxLength)
        {
            MoveChoice bestChoice = new MoveChoice(int.MaxValue, new Point(int.MaxValue, int.MaxValue));

            int result = 0;

            Point newMove = new Point(location.X, location.Y - 1);

            if (CheckPossible(newMove, board, new List <Point>()))
            {
                result = Traverse(newMove, goal, board);
                if (result != -1 && result < bestChoice.distance)
                {
                    bestChoice.distance = result;
                    bestChoice.move     = newMove;
                }
            }
            newMove = new Point(location.X - 1, location.Y);
            if (CheckPossible(newMove, board, new List <Point>()))
            {
                result = Traverse(newMove, goal, board);
                if (result != -1 && result < bestChoice.distance)
                {
                    bestChoice.distance = result;
                    bestChoice.move     = newMove;
                }
            }
            newMove = new Point(location.X + 1, location.Y);
            if (CheckPossible(newMove, board, new List <Point>()))
            {
                result = Traverse(newMove, goal, board);
                if (result != -1 && result < bestChoice.distance)
                {
                    bestChoice.distance = result;
                    bestChoice.move     = newMove;
                }
            }
            newMove = new Point(location.X, location.Y + 1);
            if (CheckPossible(newMove, board, new List <Point>()))
            {
                result = Traverse(newMove, goal, board);
                if (result != -1 && result < bestChoice.distance)
                {
                    bestChoice.distance = result;
                    bestChoice.move     = newMove;
                }
            }

            return(bestChoice);
        }
Esempio n. 2
0
        public Point FindMove(List <Player> players, char[,] board)
        {
            List <Point> attackPoints    = new List <Point>();
            Point        bestAttackPoint = new Point(-1, -1);
            int          bestLength      = maxLength;

            foreach (Player p in players)
            {
                if (p._type != _type)
                {
                    int y = p._location.Y;
                    int x = p._location.X;
                    if (p._hitpoints > 0)
                    {
                        if (board[y - 1, x] == '.')
                        {
                            attackPoints.Add(new Point(x, y - 1));
                        }
                        if (board[y, x - 1] == '.')
                        {
                            attackPoints.Add(new Point(x - 1, y));
                        }
                        if (board[y, x + 1] == '.')
                        {
                            attackPoints.Add(new Point(x + 1, y));
                        }
                        if (board[y + 1, x] == '.')
                        {
                            attackPoints.Add(new Point(x, y + 1));
                        }
                    }
                }
            }
            attackPoints = attackPoints.OrderBy(x => x.Y).ThenBy(x => x.X).ToList <Point>();

            foreach (Point p in attackPoints)
            {
                MoveChoice m = RouteToPoint(_location, p, board, bestLength);
                if (m.distance < bestLength)
                {
                    bestAttackPoint = m.move;
                    bestLength      = m.distance;
                }
            }

            return(bestAttackPoint);
        }