Пример #1
0
        private IEnumerable <int> FindWalkMoves(int x, int y, int j, int p)
        {
            if (!_pointMaster.IsPointGround(x, y) || j > 0)
            {
                yield break;
            }

            /*if (_pointMaster.IsPointGround(x - 1, y))
             * {
             *  yield return NavigationUtils.EncodeState(x - 1, y, 0, 0);
             *  if (_pointMaster.IsPointGround(x - 2, y))
             *      yield return NavigationUtils.EncodeState(x - 2, y, 0, 0);
             * }
             *
             * if (_pointMaster.IsPointGround(x + 1, y))
             * {
             *  yield return NavigationUtils.EncodeState(x + 1, y, 0, 0);
             *  if (_pointMaster.IsPointGround(x + 2, y))
             *      yield return NavigationUtils.EncodeState(x + 2, y, 0, 0);
             * }*/
            yield return(NavigationUtils.EncodeState(x - 2, y, 0, 0));

            yield return(NavigationUtils.EncodeState(x - 1, y, 0, 0));

            yield return(NavigationUtils.EncodeState(x + 1, y, 0, 0));

            yield return(NavigationUtils.EncodeState(x + 2, y, 0, 0));
        }
Пример #2
0
        private IEnumerable <int> FindUsualFlyDownMoves(int x, int y, int j, int p)
        {
            if (!(j > 0 && p == 0) || (_pointMaster.IsPointGround(x, y) && !_pointMaster.IsPointDrop(x, y)))
            {
                yield break;
            }

            /*if (!_pointMaster.IsPointBlocking(x, y - 1))
             * {
             *  yield return NavigationUtils.EncodeState(x, y - 2, 0, 0);
             *  if (_pointMaster.IsPointGround(x, y - 1))
             *      yield return NavigationUtils.EncodeState(x, y - 1, 0, 0);
             * }
             *
             * if (!_pointMaster.IsSharp(x - 1, y - 1))
             * {
             *  if (!_pointMaster.IsPointBlocking(x - 1, y - 1))
             *  {
             *      yield return NavigationUtils.EncodeState(x - 1, y - 2, 0, 0);
             *      if (!_pointMaster.IsSharp(x - 1, y))
             *      {
             *          if (!_pointMaster.IsSharp(x - 2, y - 1))
             *              yield return NavigationUtils.EncodeState(x - 2, y - 2, 0, 0);
             *          else if (_pointMaster.IsPointGround(x - 1, y - 1))
             *              yield return NavigationUtils.EncodeState(x - 1, y - 1, 0, 0);
             *      }
             *  }
             *
             * }
             *
             * if (!_pointMaster.IsSharp(x + 1, y - 1))
             * {
             *  if (!_pointMaster.IsPointBlocking(x + 1, y - 1))
             *  {
             *      yield return NavigationUtils.EncodeState(x + 1, y - 2, 0, 0);
             *      if (!_pointMaster.IsSharp(x + 1, y))
             *      {
             *          if (!_pointMaster.IsSharp(x + 2, y - 1))
             *              yield return NavigationUtils.EncodeState(x - 2, y - 2, 0, 0);
             *          else if (_pointMaster.IsPointGround(x + 1, y - 1))
             *              yield return NavigationUtils.EncodeState(x + 1, y - 1, 0, 0);
             *      }
             *  }
             * }*/

            yield return(NavigationUtils.EncodeState(x - 2, y - 2, 0, 0));

            yield return(NavigationUtils.EncodeState(x - 1, y - 2, 0, 0));

            yield return(NavigationUtils.EncodeState(x, y - 2, 0, 0));

            yield return(NavigationUtils.EncodeState(x + 1, y - 2, 0, 0));

            yield return(NavigationUtils.EncodeState(x + 2, y - 2, 0, 0));
        }
Пример #3
0
        private IEnumerable <int> FindUsualFlyUpMoves(int x, int y, int j, int p)
        {
            if (p != 0 || (j == 0 && !_pointMaster.IsPointGround(x, y)))
            {
                yield break;
            }

            if (j == 0)
            {
                j = 33;
            }

            /*if (!_pointMaster.IsPointBlocking(x, y + 1))
             * {
             *  yield return NavigationUtils.EncodeState(x, y + 2, j - 1, 0);
             *   yield return NavigationUtils.EncodeState(x - 1, y + 2, j - 1, 0);
             *  yield return NavigationUtils.EncodeState(x + 1, y + 2, j - 1, 0);
             * }
             *
             * if (!_pointMaster.IsPointBlocking(x - 1, y + 1))
             *  yield return NavigationUtils.EncodeState(x - 2, y + 2, j - 1, 0);
             *
             * if (!_pointMaster.IsPointBlocking(x + 1, y + 1))
             *  yield return NavigationUtils.EncodeState(x + 2, y + 2, j - 1, 0);*/

            /*if (!_pointMaster.IsSharp(x, y + 1))
             * {
             *  if (!_pointMaster.IsSharp(x - 1, y + 2) && !_pointMaster.IsPointBlocking(x - 1, y + 1))
             *      yield return NavigationUtils.EncodeState(x - 2, y + 2, j - 1, 0);
             *
             *  if (!_pointMaster.IsSharp(x + 1, y + 2) && !_pointMaster.IsPointBlocking(x + 1, y + 1))
             *      yield return NavigationUtils.EncodeState(x + 2, y + 2, j - 1, 0);
             * }*/

            yield return(NavigationUtils.EncodeState(x - 2, y + 2, j - 1, 0));

            yield return(NavigationUtils.EncodeState(x - 1, y + 2, j - 1, 0));

            yield return(NavigationUtils.EncodeState(x, y + 2, j - 1, 0));

            yield return(NavigationUtils.EncodeState(x + 1, y + 2, j - 1, 0));

            yield return(NavigationUtils.EncodeState(x + 2, y + 2, j - 1, 0));
        }
Пример #4
0
        public List <int> FindPath(int s, int fx, int fy, int dist = 0)
        {
            if (_lastPath != null && fx == _lastFx && fy == _lastFy && _lastPath.Count > 0)
            {
                var(sx, sy, jj, pp)     = NavigationUtils.DecodeState(s);
                var(sx1, sy1, jj1, pp1) = NavigationUtils.DecodeState(_lastPath[0]);
                if (sx == sx1 && sy == sy1)
                {
                    _lastPath.RemoveAt(0);
                    return(_lastPath);
                }
            }

            var order = new LinkedList <int>();

            order.AddLast(s);

            var parent = new Dictionary <int, int>();

            parent.Add(s, s);
            int f = -1;

            while (order.Count > 0)
            {
                var currentCode = order.First.Value;
                order.RemoveFirst();
                var(x, y, j, p) = NavigationUtils.DecodeState(currentCode);
                if (Math.Abs(x - fx) <= dist && Math.Abs(y - fy) <= dist)
                {
                    f = currentCode;
                    break;
                }

                var currentPoint = NavigationUtils.EncodePoint(x, y);
                for (int move = 0; move < PointMaster.Moves; ++move)
                {
                    if (!_pointMaster.IsValidMove(currentPoint, move))
                    {
                        continue;
                    }
                    var newCode = ApplyMove(x, y, j, p, move);
                    if (newCode < 0 || parent.ContainsKey(newCode))
                    {
                        continue;
                    }
                    var(nx, ny, nj, np) = NavigationUtils.DecodeState(newCode);
                    parent[newCode]     = currentCode;
                    order.AddLast(newCode);
                }

                if (j == 1 && p == 1)
                {
                    var newCode = NavigationUtils.EncodeState(x, y, 0, 0);
                    if (newCode < 0 || parent.ContainsKey(newCode))
                    {
                        continue;
                    }
                    parent[newCode] = currentCode;
                    order.AddLast(newCode);
                }
            }

            if (f == -1)
            {
                return(null);
            }

            var path = new List <int>();
            var cur  = f;

            while (cur != s)
            {
                cur = parent[cur];
                if (cur == s)
                {
                    break;
                }
                path.Add(cur);
            }
            path.Reverse();


            order.Clear();
            parent.Clear();

            _lastFx   = fx;
            _lastFy   = fy;
            _lastPath = path;

            return(path);
        }
Пример #5
0
        private int ApplyMove(int x, int y, int j, int p, int move)
        {
            if (move <= 5 && j != 0)
            {
                return(-1);
            }
            if (move >= 6 && move <= 7 && p != 0)
            {
                return(-1);
            }
            if (move >= 8 && move <= 10 && !(j > 0 && p == 0))
            {
                return(-1);
            }
            if (move >= 14 && !(j > 1 && p == 1))
            {
                return(-1);
            }

            switch (move)
            {
            case 0: return(NavigationUtils.EncodeState(x - 1, y, 0, 0));

            case 1: return(NavigationUtils.EncodeState(x + 1, y, 0, 0));

            case 2: return(NavigationUtils.EncodeState(x - 1, y + 1, 32, 0));

            case 3: return(NavigationUtils.EncodeState(x + 1, y + 1, 32, 0));

            case 4: return(NavigationUtils.EncodeState(x, y + 1, 32, 0));

            case 5: return(NavigationUtils.EncodeState(x - 1, y - 1, 0, 0));

            case 6: return(NavigationUtils.EncodeState(x + 1, y - 1, 0, 0));

            case 7: return(NavigationUtils.EncodeState(x, y - 1, 0, 0));

            case 8: return(NavigationUtils.EncodeState(x - 1, y + 1, j - 1, 0));

            case 9: return(NavigationUtils.EncodeState(x + 1, y + 1, j - 1, 0));

            case 10: return(NavigationUtils.EncodeState(x, y + 1, j - 1, 0));

            case 11: return(NavigationUtils.EncodeState(x - 1, y + 2, 31, 1));

            case 12: return(NavigationUtils.EncodeState(x + 1, y + 2, 31, 1));

            case 13: return(NavigationUtils.EncodeState(x, y + 2, 31, 1));

            case 14: return(NavigationUtils.EncodeState(x - 1, y + 2, j - 1, 1));

            case 15: return(NavigationUtils.EncodeState(x + 1, y + 2, j - 1, 1));

            case 16: return(NavigationUtils.EncodeState(x, y + 2, j - 1, 1));

            case 17: return(NavigationUtils.EncodeState(x, y, 0, 0));

            default:
                //impossible
                return(-1);
            }
        }