Beispiel #1
0
        /// <summary>
        /// Проверка следующей точки
        /// </summary>
        private void CellCheck()
        {
            switch (Roam)
            {
            case true:

                if (nextCell.Blocked)
                {
                    CanMove     = false;
                    readyToMove = false;
                    return;
                }
                readyToMove = true;

                break;

            case false:

                if (MarkedPointReached & currentCell.Marked)
                {
                    return;
                }

                if (RandomMove)
                {
                    if (nextCell.Blocked)
                    {
                        CanMove     = false;
                        readyToMove = false;
                        return;
                    }
                    readyToMove = true;
                }
                else
                {
                    if (nextCell.Blocked || !markedCells.Contains(targetCell) || !WaveAlgorithm.CanReach(fieldMatrix, currentCell, targetCell))
                    {
                        CanMove     = false;
                        readyToMove = false;
                        return;
                    }
                    readyToMove = true;
                }
                break;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Запускает волну для поиска пути
        /// </summary>
        private void Wave()
        {
            if (deadEnd)
            {
                return;
            }
            switch (Roam)
            {
            case true:

                wayPoints = WaveAlgorithm.ShortWay(fieldMatrix, currentCell, UnitState.Roam);

                break;

            case false:

                if (markedCells.Count == 0)
                {
                    RandomMove = true;
                    wayPoints  = WaveAlgorithm.ShortWay(fieldMatrix, currentCell, UnitState.FirstFree);
                    break;
                }

                if (RandomMove)
                {
                    wayPoints = WaveAlgorithm.ShortWay(fieldMatrix, currentCell, UnitState.FirstFree);
                    break;
                }

                wayPoints = WaveAlgorithm.ShortWay(fieldMatrix, currentCell, UnitState.Follow, markedCells);

                break;
            }

            if (wayPoints == null)
            {
                deadEnd = WaveAlgorithm.NoWay(fieldMatrix, currentCell);
                if (deadEnd)
                {
                    return;
                }
                RandomMove = true;
                return;
            }
            else
            {
                switch (Roam)
                {
                case true:

                    targetCell = wayPoints[wayPoints.Length - 1];
                    cellToMove = false;
                    counter    = 0;
                    CanMove    = true;
                    GetNextCellToMove();
                    break;

                case false:

                    targetCell = wayPoints[wayPoints.Length - 1];
                    MarkedCell = targetCell;
                    cellToMove = false;
                    counter    = 0;
                    CanMove    = true;
                    GetNextCellToMove();
                    break;
                }
            }
        }