コード例 #1
0
        static void Main(string[] args)
        {
            var watch = new System.Diagnostics.Stopwatch();

            Console.WriteLine("Hello World!");
            Stack <HexagonalCoordinate> hexagonalCoordinates = new Stack <HexagonalCoordinate>(Board.getCoordinatesInBoard(Board.SIZE));
            TileCounts tileCounts = new TileCounts(3, 4, 3, 4, 4, 1);
            Board      board      = new Board();

            watch.Start();
            //List<Board> results = BiomeHelper.getBiomeConfigurationsRecursive(hexagonalCoordinates, tileCounts, board);
            List <Board> results = BiomeHelper.getBiomeConfigurationsRecursive(0, Board.tilesInBoard(Board.SIZE), tileCounts, board);

            watch.Stop();
            Console.WriteLine($"Found {results.Count} configurations in {watch.Elapsed.TotalSeconds}s.");
        }
コード例 #2
0
        public static List <Board> getBiomeConfigurationsRecursive(Stack <HexagonalCoordinate> coordinates, TileCounts tileCounts, Board currentState)
        {
            if (coordinates.Count == 0)
            {
                return(new List <Board> {
                    currentState
                });
            }

            List <Board>        toReturn       = new List <Board>();
            HexagonalCoordinate nextCoordinate = coordinates.Pop();

            if (tileCounts.clay > 0)
            {
                Board?nextState = getNextValidState(Tile.CLAY, nextCoordinate, currentState);
                if (nextState != null)
                {
                    toReturn.AddRange(getBiomeConfigurationsRecursive(new Stack <HexagonalCoordinate>(coordinates), tileCounts.removeClay(), nextState));
                }
            }
            if (tileCounts.wood > 0)
            {
                Board?nextState = getNextValidState(Tile.WOOD, nextCoordinate, currentState);
                if (nextState != null)
                {
                    toReturn.AddRange(getBiomeConfigurationsRecursive(new Stack <HexagonalCoordinate>(coordinates), tileCounts.removeWood(), nextState));
                }
            }
            if (tileCounts.wheat > 0)
            {
                Board?nextState = getNextValidState(Tile.WHEAT, nextCoordinate, currentState);
                if (nextState != null)
                {
                    toReturn.AddRange(getBiomeConfigurationsRecursive(new Stack <HexagonalCoordinate>(coordinates), tileCounts.removeWheat(), nextState));
                }
            }
            if (tileCounts.sheep > 0)
            {
                Board?nextState = getNextValidState(Tile.SHEEP, nextCoordinate, currentState);
                if (nextState != null)
                {
                    toReturn.AddRange(getBiomeConfigurationsRecursive(new Stack <HexagonalCoordinate>(coordinates), tileCounts.removeSheep(), nextState));
                }
            }
            if (tileCounts.stone > 0)
            {
                Board?nextState = getNextValidState(Tile.STONE, nextCoordinate, currentState);
                if (nextState != null)
                {
                    toReturn.AddRange(getBiomeConfigurationsRecursive(new Stack <HexagonalCoordinate>(coordinates), tileCounts.removeStone(), nextState));
                }
            }
            if (tileCounts.desert > 0)
            {
                Board?nextState = getNextValidState(Tile.DESERT, nextCoordinate, currentState);
                if (nextState != null)
                {
                    toReturn.AddRange(getBiomeConfigurationsRecursive(new Stack <HexagonalCoordinate>(coordinates), tileCounts.removeDesert(), nextState));
                }
            }

            return(toReturn);
        }
コード例 #3
0
        public static List <Board> getBiomeConfigurationsRecursive(int currentIndex, int maxIndex, TileCounts tileCounts, Board currentState)
        {
            if (currentIndex == maxIndex)
            {
                return(new List <Board> {
                    currentState
                });
            }

            List <Board>        toReturn       = new List <Board>();
            HexagonalCoordinate nextCoordinate = Board.indexToCoordinate(currentIndex);

            if (tileCounts.clay > 0)
            {
                Board?nextState = getNextValidState(Tile.CLAY, nextCoordinate, currentState);
                if (nextState != null)
                {
                    toReturn.AddRange(getBiomeConfigurationsRecursive(currentIndex + 1, maxIndex, tileCounts.removeClay(), nextState));
                }
            }
            if (tileCounts.wood > 0)
            {
                Board?nextState = getNextValidState(Tile.WOOD, nextCoordinate, currentState);
                if (nextState != null)
                {
                    toReturn.AddRange(getBiomeConfigurationsRecursive(currentIndex + 1, maxIndex, tileCounts.removeWood(), nextState));
                }
            }
            if (tileCounts.wheat > 0)
            {
                Board?nextState = getNextValidState(Tile.WHEAT, nextCoordinate, currentState);
                if (nextState != null)
                {
                    toReturn.AddRange(getBiomeConfigurationsRecursive(currentIndex + 1, maxIndex, tileCounts.removeWheat(), nextState));
                }
            }
            if (tileCounts.sheep > 0)
            {
                Board?nextState = getNextValidState(Tile.SHEEP, nextCoordinate, currentState);
                if (nextState != null)
                {
                    toReturn.AddRange(getBiomeConfigurationsRecursive(currentIndex + 1, maxIndex, tileCounts.removeSheep(), nextState));
                }
            }
            if (tileCounts.stone > 0)
            {
                Board?nextState = getNextValidState(Tile.STONE, nextCoordinate, currentState);
                if (nextState != null)
                {
                    toReturn.AddRange(getBiomeConfigurationsRecursive(currentIndex + 1, maxIndex, tileCounts.removeStone(), nextState));
                }
            }
            if (tileCounts.desert > 0)
            {
                Board?nextState = getNextValidState(Tile.DESERT, nextCoordinate, currentState);
                if (nextState != null)
                {
                    toReturn.AddRange(getBiomeConfigurationsRecursive(currentIndex + 1, maxIndex, tileCounts.removeDesert(), nextState));
                }
            }

            return(toReturn);
        }