Ejemplo n.º 1
0
        public PointList WriteSolvedPuzzleCoordinatesToConsole(string searchString, IGridManager gridManager)
        {
            string[] searchWords = searchString.Split(',');

            PointList points = new PointList();

            _wordFinder.SetSearchOrientations(_searchOrientationManager.GetSearchOrientations(gridManager));

            foreach (var searchWord in searchWords)
            {
                var coordinatesOfSearchTarget = _wordFinder.GetCoordinatesOfSearchTarget(searchWord, $"Did not find {searchWord} in puzzle.");
                if (coordinatesOfSearchTarget != null && coordinatesOfSearchTarget.Count > 0)
                {
                    _consoleWrapper.WriteLine($"{searchWord}: " + $"{coordinatesOfSearchTarget.ToString()}");

                    //create list of all coordinates of grid that are part of the puzzle solution
                    foreach (var coordinate in coordinatesOfSearchTarget)
                    {
                        if (!points.Contains(coordinate))
                        {
                            points.Add(coordinate);
                        }
                    }
                }
            }

            return(points.Count > 0 ? points : null);
        }
Ejemplo n.º 2
0
        public void WriteGridToConsole(string[,] grid, ConsoleColor foregroundColor, ConsoleColor backgroundColor, PointList coordinatesToHighlight = null)
        {
            if (grid == null)
            {
                throw new ArgumentException("grid is null.");
            }

            var columnsCount = grid.GetLength(1);
            var rowsCount    = grid.GetLength(0);

            SetConsoleColors(foregroundColor, backgroundColor);

            for (int rowNumber = 0; rowNumber < rowsCount; rowNumber++)
            {
                for (int columnNumber = 0; columnNumber < columnsCount; columnNumber++)
                {
                    string letter = grid[rowNumber, columnNumber];

                    if (coordinatesToHighlight != null && coordinatesToHighlight.Contains(new Point(columnNumber, rowNumber)))
                    {
                        SetConsoleColors(backgroundColor, foregroundColor);
                    }

                    _consoleWrapper.Write(letter);

                    SetConsoleColors(foregroundColor, backgroundColor);

                    _consoleWrapper.Write(" ");
                }
                _consoleWrapper.WriteLine();
            }
        }
Ejemplo n.º 3
0
    public static IEnumerable <RectPoint> GenerateMazeWalls <TCell>(RectGrid <TCell> grid)
    {
        var walls = grid.CloneStructure <bool>();        //true indicates passable

        foreach (var point in walls)
        {
            walls[point] = point.GetColor3() == 0;

            //Debug.Log(point);
        }

        var wallList = new PointList <RectPoint>();

        var newMaizePoint = grid.Where(p => p.GetColor3() == 0).RandomItem();
        var inMaze        = new PointList <RectPoint> {
            newMaizePoint
        };

        var edges = grid.GetNeighbors(newMaizePoint);

        wallList.AddRange(edges);

        while (wallList.Any())
        {
            var randomWall = wallList.RandomItem();
            var faces      = GetEdgeFaces(randomWall).Where(grid.Contains);

            //At least one of the two faces must be in the maze
            if (faces.Any(point => !inMaze.Contains(point)))
            {
                newMaizePoint = faces.First(point => !inMaze.Contains(point));
                inMaze.Add(newMaizePoint);
                walls[randomWall] = true;

                yield return(randomWall);

                // Add all edges that are not passages
                edges = grid.GetNeighbors(newMaizePoint).Where(edge => !(walls[edge]));
                wallList.AddRange(edges);
            }
            else
            {
                wallList.Remove(randomWall);
            }
        }
    }
Ejemplo n.º 4
0
        public virtual void AddPolyPoint(float x, float y)
        {
            Point p = new Point(x, y);

            if (!poly.Contains(p))
            {
                poly.Add(p);
            }
        }
Ejemplo n.º 5
0
    /**
     *      Generates a maze using a randomized version of Prim's algorithm.
     *
     *      @returns a IEnumerable of passages
     */
    //For some reason, the generic version gives a TypeLoadException in Unity (but not when run from visual studio).

    /*
     * public static IEnumerable<TEdge> GenerateMazeWalls<TGrid, TPoint, TEdge>(TGrid grid)
     *      where TEdge : IGridPoint<TEdge>, IEdge<TPoint>
     *      where TPoint : IGridPoint<TPoint>, ISupportsEdges<TEdge>
     *      where TGrid : ISupportsEdgeGrid<TEdge>, IGridSpace<TPoint>
     * {
     *      IGrid<bool, TEdge> walls = grid.MakeEdgeGrid<bool>(); //true indicates passable
     *      var wallList = new List<TEdge>();
     *
     *      TPoint newMaizePoint = grid.RandomItem<TPoint>();
     *      var inMaze = new List<TPoint>();
     *      inMaze.Add(newMaizePoint);
     *
     *      var edges = newMaizePoint.GetEdges();
     *      wallList.AddRange(edges);
     *
     *      while (wallList.Any())
     *      {
     *              var randomWall = wallList.RandomItem();
     *              IEnumerable<TPoint> faces = (randomWall as IEdge<TPoint>).GetEdgeFaces().Where(x => grid.Contains(x));
     *
     *              //At least one of the two faces must be in the maze
     *              if (faces.Any(point => !inMaze.Contains(point)))
     *              {
     *                      newMaizePoint = faces.First(point => !inMaze.Contains(point));
     *                      inMaze.Add(newMaizePoint);
     *                      walls[randomWall] = true;
     *
     *                      yield return randomWall;
     *
     *                      // Add all edges that are not passages
     *                      edges = newMaizePoint.GetEdges().Where(edge => !(walls[edge]));
     *                      wallList.AddRange(edges);
     *              }
     *              else
     *              {
     *                      wallList.Remove(randomWall);
     *              }
     *      }
     *      yield return (TEdge)(object) g.First();
     *      yield break;
     * }
     */

    /**
     *      Generates a maze using a randomized version of Prim's algorithm.
     *
     *      @returns a IEnumerable of passages
     */
    public static IEnumerable <PointyRhombPoint> GenerateMazeWalls <TCell>(FlatTriGrid <TCell> grid)
    {
        var walls    = grid.MakeEdgeGrid <bool>();     //true indicates passable
        var wallList = new PointList <PointyRhombPoint>();

        var newMaizePoint = grid.RandomItem();
        var inMaze        = new PointList <FlatTriPoint> {
            newMaizePoint
        };

        var edges = newMaizePoint.GetEdges();

        wallList.AddRange(edges);

        while (wallList.Any())
        {
            var randomWall = wallList.RandomItem();
            var faces      = (randomWall as IEdge <FlatTriPoint>).GetEdgeFaces().Where(x => grid.Contains(x));

            //At least one of the two faces must be in the maze
            if (faces.Any(point => !inMaze.Contains(point)))
            {
                newMaizePoint = faces.First(point => !inMaze.Contains(point));
                inMaze.Add(newMaizePoint);
                walls[randomWall] = true;

                yield return(randomWall);

                // Add all edges that are not passages
                edges = newMaizePoint.GetEdges().Where(edge => !(walls[edge]));
                wallList.AddRange(edges);
            }
            else
            {
                wallList.Remove(randomWall);
            }
        }
    }
Ejemplo n.º 6
0
 private void UpdatePoints(IList <Point> oldList)
 {
     foreach (Point point in PointList)
     {
         if (oldList.Contains(point))
         {
             continue;
         }
         AddPoint(point);
     }
     if (oldList == null)
     {
         return;
     }
     foreach (Point point in oldList)
     {
         if (PointList.Contains(point))
         {
             continue;
         }
         RemovePoint(point);
     }
 }
Ejemplo n.º 7
0
 private PointList<int, int> CalcEnemyShipCountPerSector()
 {
     PointList<int, int> result = new PointList<int, int>();
     foreach (IVisible unit in mComputerView)
         if (unit is ISpaceship && unit.Allegiance == Allegiance.Player)
         {
             Point sector = mUnitSectorManager.GetSector(unit.Position);
             if (result.Contains(sector.X, sector.Y))
                 result.Set(sector.X, sector.Y, result.Get(sector.X, sector.Y)+1);
             else
                 result.Add(sector.X, sector.Y, 1);
         }
     return result;
 }