Ejemplo n.º 1
0
        public static List <TileData> PlaceTilesOnCart(List <Tile> tiles, int cartWidth)
        {
            int tilesTotalSquare = tiles.Aggregate(0, (square, tile) => square + tile.Square);

            const int maxCartRows = 20;

            int cartMinimumRows = tilesTotalSquare % cartWidth > 0
                ? (int)Math.Ceiling((double)tilesTotalSquare / cartWidth)
                : tilesTotalSquare / cartWidth;


            bool            areTilesArrangedOnGrid;
            int             cartRows = cartMinimumRows;
            List <TileData> arrangedTiles;

            do
            {
                Grid cartGrid = new Grid(cartWidth, cartRows);

                List <TileData> gridTiles = tiles.ConvertAll(tile => new TileData
                {
                    Tile            = tile,
                    AvailablePoints = cartGrid.GetAvailablePoints(tile),
                });

                areTilesArrangedOnGrid = ArrangeTilesToFitGrid(cartGrid, gridTiles);
                arrangedTiles          = gridTiles;
            } while (!areTilesArrangedOnGrid && cartRows++ < maxCartRows);


            return(arrangedTiles);
        }
Ejemplo n.º 2
0
        private GridTilingService(Grid grid, DifficultyEnum difficulty)
        {
            _grid       = grid.Clone();
            _difficulty = difficulty;

            _tiles = AvailableTileTypes.ConvertAll(tile => new TileData
            {
                Tile            = tile,
                AvailablePoints = grid.GetAvailablePoints(tile)
            });


            int hardMinimumFreePoints = GetHardMinimumFreePoints();
            int normalMinimumFreePointsByPercentage =
                (int)Math.Round((double)(100 * NormalDifficultyPointsPercentage) / _grid.FreePointsCount);

            _freePointsByDifficulty = new Difficulties
            {
                { DifficultyEnum.Hard, hardMinimumFreePoints },
                { DifficultyEnum.Normal, Math.Max(hardMinimumFreePoints + 2, normalMinimumFreePointsByPercentage) }
            };

            Log($"Difficulties: hard - {_freePointsByDifficulty[DifficultyEnum.Hard]}, normal - {_freePointsByDifficulty[DifficultyEnum.Normal]}");
        }