public static void RandomlyChooseAndSetStartAndExit(MapGrid grid, ref Vector3 startPosition, ref Vector3 exitPosition, bool randomPlacement, Direction startPositionEdge = Direction.Left, Direction exitPositionEdge = Direction.Right)
 {
     if (randomPlacement)
     {
         startPosition = RandomlyChoosPositionOnTheEdgeOfTheGrid(grid, startPosition);
         exitPosition  = RandomlyChoosPositionOnTheEdgeOfTheGrid(grid, startPosition);
     }
     else
     {
         startPosition = RandomlyChoosPositionOnTheEdgeOfTheGrid(grid, startPosition, startPositionEdge);
         exitPosition  = RandomlyChoosPositionOnTheEdgeOfTheGrid(grid, startPosition, exitPositionEdge);
     }
     grid.SetCell(startPosition.x, startPosition.z, CellObjectType.Start, true);
     grid.SetCell(exitPosition.x, exitPosition.z, CellObjectType.Exit, true);
 }
 private void VisualizeUsingPrimitives(MapGrid grid, MapData data)
 {
     PlaceStartAndExitPoints(data);
     for (int i = 0; i < data.obstacleArray.Length; i++)
     {
         if (data.obstacleArray[i])
         {
             var positionOnGrid = grid.CalculateCoordinatesFromIndex(i);
             if (positionOnGrid == data.startPosition || positionOnGrid == data.exitPosition)
             {
                 continue;
             }
             grid.SetCell(positionOnGrid.x, positionOnGrid.z, CellObjectType.Obstacle);
             if (PlaceKnightObstacle(data, positionOnGrid))
             {
                 continue;
             }
             if (dictionaryOfObstacles.ContainsKey(positionOnGrid) == false)
             {
                 CreateIndicator(positionOnGrid, Color.white, PrimitiveType.Cube);
             }
         }
     }
 }
        private void VisualizeUsingPrefabs(MapGrid grid, MapData data)
        {
            for (int i = 0; i < data.path.Count; i++)
            {
                var position = data.path[i];
                if (position != data.exitPosition)
                {
                    grid.SetCell(position.x, position.z, CellObjectType.Road);
                }
            }
            for (int col = 0; col < grid.Width; col++)
            {
                for (int row = 0; row < grid.Length; row++)
                {
                    var cell     = grid.GetCell(col, row);
                    var position = new Vector3(cell.X, 0, cell.Z);

                    var index = grid.CalculateIndexFromCoordinates(position.x, position.z);

                    if (data.obstacleArray[index] && cell.IsTaken == false)
                    {
                        cell.ObjectType = CellObjectType.Obstacle;
                    }

                    Direction previousDirection = Direction.None;
                    Direction nextDirection     = Direction.None;

                    switch (cell.ObjectType)
                    {
                    case CellObjectType.Empty:
                        int randomEmpty = Random.Range(0, tileEmpty.Length);
                        CreateIndicator(position, tileEmpty[randomEmpty]);
                        break;

                    case CellObjectType.Road:
                        int randomRoad = Random.Range(0, roadTiles.Length);

                        if (data.path.Count > 0)
                        {
                            previousDirection = GetDirectionOfPreviousCell(position, data);
                            nextDirection     = GetDirectionOfNextCell(position, data);
                        }
                        if (previousDirection == Direction.Up && nextDirection == Direction.Right || previousDirection == Direction.Right && nextDirection == Direction.Up)
                        {
                            CreateIndicator(position, roadTileCorner, Quaternion.Euler(0, 90, 0));
                        }
                        else if (previousDirection == Direction.Right && nextDirection == Direction.Down || previousDirection == Direction.Down && nextDirection == Direction.Right)
                        {
                            CreateIndicator(position, roadTileCorner, Quaternion.Euler(0, 180, 0));
                        }
                        else if (previousDirection == Direction.Down && nextDirection == Direction.Left || previousDirection == Direction.Left && nextDirection == Direction.Down)
                        {
                            CreateIndicator(position, roadTileCorner, Quaternion.Euler(0, -90, 0));
                        }
                        else if (previousDirection == Direction.Left && nextDirection == Direction.Up || previousDirection == Direction.Up && nextDirection == Direction.Left)
                        {
                            CreateIndicator(position, roadTileCorner);
                        }
                        else if (previousDirection == Direction.Right && nextDirection == Direction.Left || previousDirection == Direction.Left && nextDirection == Direction.Right)
                        {
                            CreateIndicator(position, roadTiles[randomRoad], Quaternion.Euler(0, 90, 0));
                        }
                        else
                        {
                            CreateIndicator(position, roadTiles[randomRoad]);
                        }
                        break;

                    case CellObjectType.Obstacle:
                        int randomIndex = Random.Range(0, environmentTiles.Length);
                        CreateIndicator(position, environmentTiles[randomIndex]);
                        break;

                    case CellObjectType.Start:
                        if (data.path.Count > 0)
                        {
                            nextDirection = GetDirectionFromVectors(data.path[0], position);
                        }
                        if (nextDirection == Direction.Right || nextDirection == Direction.Left)
                        {
                            CreateIndicator(position, startTile, Quaternion.Euler(0, 90, 0));
                        }
                        else
                        {
                            CreateIndicator(position, startTile);
                        }
                        break;

                    case CellObjectType.Exit:
                        if (data.path.Count > 0)
                        {
                            previousDirection = GetDirectionOfPreviousCell(position, data);
                        }
                        switch (previousDirection)
                        {
                        case Direction.Right:
                            CreateIndicator(position, exitTile, Quaternion.Euler(0, 90, 0));
                            break;

                        case Direction.Left:
                            CreateIndicator(position, exitTile, Quaternion.Euler(0, -90, 0));
                            break;

                        case Direction.Down:
                            CreateIndicator(position, exitTile, Quaternion.Euler(0, 180, 0));
                            break;

                        default:
                            CreateIndicator(position, exitTile);
                            break;
                        }
                        break;
                    }
                }
            }
        }