Beispiel #1
0
        private static bool ArrangeTilesToFitGrid(Grid grid, List <TileData> gridTiles)
        {
            foreach (TileData tile in gridTiles)
            {
                foreach (GridPoint point in tile.AvailablePoints)
                {
                    if (grid.CanTileBePlaced(tile.Tile, point))
                    {
                        grid.PlaceTile(tile.Tile, point);
                        tile.SetPlacedPoint(point);
                        break;
                    }
                }

                if (!tile.IsPlaced)
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #2
0
        private List <Tile> GetTileSetForTileTypes()
        {
            List <TileData> availableTiles = new List <TileData>();

            foreach (var tile in _tiles)
            {
                availableTiles.Add(tile);
            }

            List <Tile> placedTiles = new List <Tile>();

            while (availableTiles.Count > 0)
            {
                int      randomTileIndex = Rnd.Next(availableTiles.Count);
                TileData randomTile      = availableTiles[randomTileIndex];
                Log($"random {randomTileIndex}/{availableTiles.Count}: {randomTile.Tile}");

                bool isTilePlaced = false;

                foreach (GridPoint point in randomTile.AvailablePoints)
                {
                    if (_grid.CanTileBePlaced(randomTile.Tile, point))
                    {
                        isTilePlaced = true;
                        _grid.PlaceTile(randomTile.Tile, point);
                        placedTiles.Add(randomTile.Tile);
                        break;
                    }
                }

                if (!isTilePlaced)
                {
                    Log($"Excluding tile index {randomTileIndex}: " + randomTile.Tile);
                    availableTiles.RemoveAt(randomTileIndex);
                }
            }

            return(placedTiles);
        }