public async Task GetAllImages() { try { StorageFolder pictureFolder2 = await Folder.GetFolderAsync(PuzzleSize.ToString()); for (int i = 1; i <= TotalPuzzleSize; i++) { StorageFile img = await pictureFolder2.GetFileAsync($"{i.ToString()}{ImageTypes.Png}"); BitmapImage image = new BitmapImage(); using (IRandomAccessStream fileStream = await img.OpenAsync(FileAccessMode.Read)) { image.SetSource(fileStream); } PuzzleImages.Add(image); } if (PuzzleImages.Count != TotalPuzzleSize) { throw new Exception("PUzzle can not be generated."); } } catch { throw; } }
/// <summary> /// Ctor /// </summary> /// <param name="puzzleSize">The size of the puzzle solution to generate</param> public PuzzleSolutionGenerator(PuzzleSize puzzleSize) { PuzzleGrid = new Puzzle(puzzleSize); PuzzleBoxes = PuzzleGrid.ByBox() .Select(box => box.ToList()).ToList(); }
public async Task GetAllImages() { List <BitmapImage> images = new List <BitmapImage>(); try { StorageFolder pictureFolder2 = await Folder.GetFolderAsync(PuzzleSize.ToString()); for (int i = 1; i < (PuzzleSize * PuzzleSize); i++) { Debug.WriteLine("Image from folder: " + i.ToString()); StorageFile img = await pictureFolder2.GetFileAsync(i.ToString() + ".png"); BitmapImage image = new BitmapImage(); using (IRandomAccessStream fileStream = await img.OpenAsync(FileAccessMode.Read)) { image.SetSource(fileStream); } images.Add(image); } } catch (Exception ex) { Debug.Write(ex.ToString()); throw; } PuzzlePieceImages = images; }
/// <summary> /// Gets the integer value for the number of rows, columns or boxes defined by PuzzleSize. /// </summary> /// <param name="puzzleSize">The PuzzleSize getting the in value for.</param> /// <returns>The PuzzleSize's integer value</returns> public static int ToInt32(this PuzzleSize puzzleSize) { if (puzzleSize == PuzzleSize.Undefined) { throw new ArgumentOutOfRangeException(nameof(puzzleSize), "Must be defined"); } return((int)puzzleSize); }
/// <summary> /// Is the puzzle and odd number of rows, columns or boxes? /// </summary> /// <param name="puzzleSize">The PuzzleSize being checked.</param> /// <returns>true if odd, false if not</returns> public static bool IsOdd(this PuzzleSize puzzleSize) { if (puzzleSize == PuzzleSize.Undefined) { throw new ArgumentOutOfRangeException(nameof(puzzleSize), "PuzzleSize.Undefined is neither even or odd"); } return(puzzleSize == PuzzleSize.NineByNine); }
/// <summary> /// Get's the center coordinate of a puzzle, if PuzzleSize.IsOdd() is true! /// </summary> /// <param name="puzzleSize">The PuzzleSize of the puzzle.</param> /// <returns>The center coordinate of the puzzle, if it has one.</returns> public static PuzzleCoordinate GetCenterCoordinate(this PuzzleSize puzzleSize) { if (puzzleSize != PuzzleSize.NineByNine) { throw new ArgumentOutOfRangeException(nameof(puzzleSize), "Must be PuzzleSize.NineByNine"); } var center = new PuzzleCoordinate(4, 4); return(center); }
/// <summary> /// How many rows/columns in a box? /// </summary> /// <param name="puzzleSize">The size opf the overall puzzle</param> /// <returns>The square root of the PuzzleSize</returns> public static int BoxSize(this PuzzleSize puzzleSize) { if (puzzleSize == PuzzleSize.Undefined) { throw new ArgumentOutOfRangeException(nameof(puzzleSize), "Must be defined"); } var boxSize = (int)Math.Sqrt(puzzleSize.ToInt32()); return(boxSize); }
public PuzzleSet(PuzzleSize size) { if (!new[] { PuzzleSize.FourByFour, PuzzleSize.NineByNine, PuzzleSize.SixteenBySixteen }.Contains(size)) { throw new ArgumentOutOfRangeException(nameof(size), $"Must be a defined {nameof(PuzzleSize)} value"); } MaxValue = size.ToInt32(); Bits = new BitArray(MaxValue); }
/// <summary> /// The initial step to kick off recursive Dlx solver algorithm. /// </summary> /// <param name="puzzle">The puzzle to solve.</param> /// <param name="maxSolutionToFind">The upper limit of the number of solutions to find, if any</param> public IList <Puzzle> Solve(Puzzle puzzle, int?maxSolutionToFind = null) { // setup _puzzleSize = puzzle.Size; MaxSolutionsToFind = maxSolutionToFind; // create/reset CreateDlxGrid(); // load data LoadPuzzleGrid(puzzle); // solve the puzzle RecursiveSolve(); return(SolutionList); }
public PuzzleSet(PuzzleSize size, [NotNull] IEnumerable <byte> values) { if (values == null) { throw new ArgumentNullException(nameof(values)); } if (!new[] { PuzzleSize.FourByFour, PuzzleSize.NineByNine, PuzzleSize.SixteenBySixteen }.Contains(size)) { throw new ArgumentOutOfRangeException(nameof(size), $"Must be a defined {nameof(PuzzleSize)} value"); } MaxValue = size.ToInt32(); Bits = new BitArray(MaxValue); AddRange(values); }
private void AssertIfNotFullSet(IEnumerable <PuzzleCoordinateAndValue> sudokuSet, PuzzleSize puzzleSize) { var maxVal = puzzleSize.ToInt32(); var sudokuArray = sudokuSet.ToArray(); var setValues = sudokuArray.Select(s => s.Value) .Where(v => v.HasValue) .Select(v => v.Value) .OrderBy((v => v)) .Distinct() .ToList(); Assert.Equal(maxVal, setValues.Count); Assert.Equal(1, setValues.First()); Assert.Equal(maxVal, setValues.Last()); }
public static IEnumerable <byte> ValidCellValues(this PuzzleSize puzzleSize) { return(Enumerable.Range(1, puzzleSize.ToInt32()).Select(Convert.ToByte)); }
/// <summary> /// Public ctor. /// </summary> /// <param name="puzzleSize">This may not be needed, could be inferred when puzzle is loaded.</param> public Puzzle(PuzzleSize puzzleSize) { Size = puzzleSize; }