Example #1
0
        private RiverPathResults TryFollowSomePath(
            List <RiverPath> paths, IEnumerable <IHexCell> oceanCells, HashSet <IHexCell> cellsAdjacentToRiver
            )
        {
            if (paths.Any(path => path.IsAlreadyCompleted()))
            {
                return(RiverPathResults.Success);
            }

            while (paths.Count > 0)
            {
                RiverPath randomPath = paths.First();

                var pathResults = randomPath.TryBuildOutPath(cellsAdjacentToRiver, oceanCells);

                if (pathResults.Completed)
                {
                    return(pathResults);
                }

                paths.Remove(randomPath);
            }

            return(RiverPathResults.Fail);
        }
Example #2
0
        //We need to draw a river from previousCell to nextCell by adding rivers
        //to the edges of currentCell. PreviousCell is in directionToNext.Next2(),
        //and should have some river pointing at currentCell
        private RiverPathResults CreateRiverAlongCell_GentleCWTurn(
            IHexCell previousCell, IHexCell currentCell, IHexCell nextCell,
            HexDirection directionToPrevious, HexDirection directionToNext,
            IEnumerable <IHexCell> oceanCells, HashSet <IHexCell> cellsAdjacentToRiver
            )
        {
            var leftLeftPath = new RiverPath(
                currentCell, directionToPrevious.Next(), directionToNext.Previous(),
                RiverFlow.Clockwise, RiverCanon, Grid
                );

            var leftRightPath = new RiverPath(
                currentCell, directionToPrevious, directionToNext.Next(),
                RiverFlow.Counterclockwise, RiverCanon, Grid
                );

            var rightRightPath = new RiverPath(
                currentCell, directionToNext.Next(),
                RiverFlow.Counterclockwise, RiverCanon, Grid
                );

            var rightleftPath = new RiverPath(
                currentCell, directionToPrevious, directionToNext.Previous(),
                RiverFlow.Clockwise, RiverCanon, Grid
                );

            var pathsToTry = new List <RiverPath>();

            //If directionToNext.Previous() is considered up,
            //this case triggers when previousCell has a river
            //along its upper-left edge.
            if (RiverCanon.HasRiverAlongEdge(previousCell, directionToPrevious.Next2()))
            {
                pathsToTry.Add(leftLeftPath);
                pathsToTry.Add(leftRightPath);
            }

            //If directionToNext.Previous() is considered up,
            //this case triggers when previousCell has a river
            //along its upper-right edge.
            if (RiverCanon.HasRiverAlongEdge(previousCell, directionToPrevious.Previous2()))
            {
                pathsToTry.Add(rightRightPath);
                pathsToTry.Add(rightleftPath);
            }

            return(TryFollowSomePath(pathsToTry, oceanCells, cellsAdjacentToRiver));
        }
Example #3
0
        //We need to draw a river from previousCell to nextCell by adding rivers
        //to the edges of currentCell. PreviousCell and nextCell are across from
        //each-other. Previous river should have some river pointing at currentCell
        private RiverPathResults CreateRiverAlongCell_StraightAcross(
            IHexCell previousCell, IHexCell currentCell, IHexCell nextCell,
            HexDirection directionToPrevious, HexDirection directionToNext,
            IEnumerable <IHexCell> oceanCells, HashSet <IHexCell> cellsAdjacentToRiver
            )
        {
            var leftToLeftPath = new RiverPath(
                currentCell, directionToNext.Previous2(), directionToNext.Previous(),
                RiverFlow.Clockwise, RiverCanon, Grid
                );

            var leftToRightPath = new RiverPath(
                currentCell, directionToPrevious, directionToNext.Next(),
                RiverFlow.Counterclockwise, RiverCanon, Grid
                );

            var rightToRightPath = new RiverPath(
                currentCell, directionToNext.Next2(), directionToNext.Next(),
                RiverFlow.Counterclockwise, RiverCanon, Grid
                );

            var rightToLeftPath = new RiverPath(
                currentCell, directionToPrevious, directionToNext.Previous(),
                RiverFlow.Clockwise, RiverCanon, Grid
                );

            var pathsToTry = new List <RiverPath>();

            //If nextCell is above us, this case happens when previousCell has a
            //river along its left edge
            if (RiverCanon.HasRiverAlongEdge(previousCell, directionToNext.Previous()))
            {
                pathsToTry.Add(leftToLeftPath);
                pathsToTry.Add(leftToRightPath);

                //If nextCell is above us, this case happens when previousCell has a
                //river along its right edge
            }
            else if (RiverCanon.HasRiverAlongEdge(previousCell, directionToNext.Next()))
            {
                pathsToTry.Add(rightToRightPath);
                pathsToTry.Add(rightToLeftPath);
            }

            return(TryFollowSomePath(pathsToTry, oceanCells, cellsAdjacentToRiver));
        }
Example #4
0
        //We need to draw a river from previousCell to nextCell by adding rivers
        //to the edges of currentCell. PreviousCell is in directionToNext.Next(),
        //and should have some river pointing at currentCell
        private RiverPathResults CreateRiverAlongCell_SharpCWTurn(
            IHexCell previousCell, IHexCell currentCell, IHexCell nextCell,
            HexDirection directionToPrevious, HexDirection directionToNext,
            IEnumerable <IHexCell> oceanCells, HashSet <IHexCell> cellsAdjacentToRiver
            )
        {
            var leftToLeftPath = new RiverPath(
                currentCell, directionToPrevious.Next(), directionToNext.Previous(),
                RiverFlow.Clockwise, RiverCanon, Grid
                );

            var leftToRightPath = new RiverPath(
                currentCell, directionToPrevious, RiverFlow.Counterclockwise,
                RiverCanon, Grid
                );

            var pathsToTry = new List <RiverPath>();

            //Assuming directionToPrevious.Opposite() is up,
            //this case triggers when previousCell has a
            //river along its upper left edge
            if (RiverCanon.HasRiverAlongEdge(previousCell, directionToPrevious.Next2()))
            {
                pathsToTry.Add(leftToLeftPath);
                pathsToTry.Add(leftToRightPath);
            }

            //Assuming directionToPrevious.Opposite() is up,
            //this case triggers when previousCell has a
            //river along its upper right edge
            if (RiverCanon.HasRiverAlongEdge(previousCell, directionToPrevious.Previous2()))
            {
                return(RiverPathResults.Success);
            }

            return(TryFollowSomePath(pathsToTry, oceanCells, cellsAdjacentToRiver));
        }