static long FindGold(int size, IEnumerable <string> input) { var tiles = new TileCollection(input); var grid = new Tile[size, size]; // Find a corner piece and orient it in the top left corner var cornerTile = tiles.CornerPieces.First(); grid[0, 0] = cornerTile; if (tiles.SideMatches(cornerTile.TopId).Count > 1) { cornerTile.FlipVertical(); } if (tiles.SideMatches(cornerTile.LeftId).Count > 1) { cornerTile.FlipHorizontal(); } // Fill in the left column for (int y = 1; y < size; y++) { grid[y, 0] = tiles.FindAndOrientTileBelow(grid[y - 1, 0]); } // Fill in the rest of the grid for (int y = 0; y < size; y++) { for (int x = 1; x < size; x++) { grid[y, x] = tiles.FindAndOrientTileRight(grid[y, x - 1]); } } // Piece together the final image var image = new FinalImage(size * 8); for (int y = 0; y < size; y++) { for (int line = 1; line <= 8; line++) { var sb = new StringBuilder(); for (int x = 0; x < size; x++) { sb.Append(grid[y, x].GetLineInner(line)); } image.AddLine(sb.ToString()); } } // Solution is total # count minus the number of characters taken up by monsters const int monsterSize = 15; var hashMarkCount = image.CountCharacter('#'); var monsterCount = image.CountMonsters(); return(hashMarkCount - (monsterCount * monsterSize)); }
public static FinalImage ToFinalImage(this FinalImageEntity newEntity, FinalImage oldEntity = null) { FinalImage entity = oldEntity; if (entity == null) { entity = new FinalImage(); } entity.Format = newEntity.Format; entity.Resolution = newEntity.Resolution; entity.FinalImageBlob = newEntity.FinalImageBlob; entity.InitialVideoId = newEntity.InitialVideoId; return(entity); }
public static FinalImageEntity ToFinalImageEntity(this FinalImage model) { if (model == null) { return(null); } FinalImageEntity entity = new FinalImageEntity(); entity.Id = model.Id; entity.Format = model.Format; entity.Resolution = model.Resolution; entity.FinalImageBlob = model.FinalImageBlob; entity.InitialVideoId = model.InitialVideoId; if (model.InitialVideo != null) { entity.InitialVideo = model.InitialVideo.ToInitialVideoEntity(); } return(entity); }
public override void UnloadContent() { FinalImage.Dispose(); FinalImage = null; base.UnloadContent(); }