public void restorePuzzleState(PuzzleGenerator puzzle) { //takes a PuzzleGenerator object and sets all of the building and note values to be the ones contained in this PuzzleState for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { puzzle.tilesArray[i, j].shownNumber = buildings[i, j]; puzzle.tilesArray[i, j].addNumberToTile(buildings[i, j]); } } for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { puzzle.tilesArray[i, j].clearColoredNotes(); for (int k = 0; k < notes1[i, j].Length; k++) { puzzle.tilesArray[i, j].toggleNote1(notes1[i, j][k]); } for (int k = 0; k < notes2[i, j].Length; k++) { puzzle.tilesArray[i, j].toggleNote2(notes2[i, j][k]); } } } }
public PuzzleState(PuzzleGenerator puzzle) { //takes a snapshot of the puzzle and saves it in this PuzzleState object size = puzzle.puzzle.size; buildings = new int[size, size]; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { buildings[i, j] = puzzle.tilesArray[i, j].shownNumber; } } notes1 = new int[size, size][]; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { notes1[i, j] = toList(puzzle.tilesArray[i, j].noteGroup1); } } notes2 = new int[size, size][]; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { notes2[i, j] = toList(puzzle.tilesArray[i, j].noteGroup2); } } }
public void Constructor_WithValidArgs_Works() { var generator = new PuzzleGenerator <Puzzle>( () => new Puzzle(9), new List <IConstraint> { new RowUniquenessConstraint() }); }
public static IEnumerator Generate(Action onFinish, Action <float> onProgress) { Texture2D texture = AssetsManager.PuzzleImages[Settings.PuzzleFile + SelectImageIndex]; yield return(PuzzleGenerator.Generate(texture, onFinish, onProgress)); yield return(RandomPuzzle()); }
public void Generate_WithShortTimeout_ThrowsTimeoutException() { var generator = new PuzzleGenerator <PuzzleWithPossibleValues>( size => new PuzzleWithPossibleValues(size), StandardPuzzles.CreateSolver()); Assert.Throws <TimeoutException>( () => generator.Generate(16, 150, TimeSpan.FromMilliseconds(1))); }
public void Generate_WithShortTimeout_ThrowsTimeoutException() { var generator = new PuzzleGenerator <Puzzle>( () => new Puzzle(9), puzzle => new PuzzleSolver(puzzle)); Assert.Throws <TimeoutException>( () => generator.Generate(17, TimeSpan.FromMilliseconds(1))); }
public int SudokuSpiceConstraints() { var generator = new PuzzleGenerator <Puzzle>( size => new Puzzle(size), ConstraintBased.StandardPuzzles.CreateSolver()); Puzzle puzzle = generator.Generate(9, 30, TimeSpan.FromSeconds(10)); return(puzzle.NumEmptySquares); }
public void Generate_CreatesPuzzleWithUniqueSolution(int size, int numToSet) { var generator = new PuzzleGenerator <Puzzle>( () => new Puzzle(size), puzzle => new PuzzleSolver(puzzle)); Puzzle puzzle = generator.Generate(numToSet, TimeSpan.FromSeconds(60)); Assert.Equal(size * size - numToSet, puzzle.NumEmptySquares); var solver = new PuzzleSolver(puzzle); SolveStats stats = solver.GetStatsForAllSolutions(); Assert.Equal(1, stats.NumSolutionsFound); }
public void Generate_WithShortTimeout_ThrowsTimeoutException() { var generator = new PuzzleGenerator <Puzzle>( () => new Puzzle(9), new List <IConstraint> { new RowUniquenessConstraint(), new ColumnUniquenessConstraint(), new BoxUniquenessConstraint() }); Assert.Throws <TimeoutException>( () => generator.Generate(17, TimeSpan.FromMilliseconds(1))); }
public void Generate_CreatesPuzzleWithUniqueSolution(int size, int numToSet) { var generator = new PuzzleGenerator <PuzzleWithPossibleValues>( size => new PuzzleWithPossibleValues(size), StandardPuzzles.CreateSolver()); PuzzleWithPossibleValues puzzle = generator.Generate(size, numToSet, TimeSpan.FromSeconds(60)); Assert.Equal(size * size - numToSet, puzzle.NumEmptySquares); var solver = StandardPuzzles.CreateSolver(); SolveStats stats = solver.ComputeStatsForAllSolutions(puzzle); Assert.Equal(1, stats.NumSolutionsFound); }
public void Generate_WithShortTimeout_ThrowsTimeoutException() { var generator = new PuzzleGenerator <Puzzle>( size => new Puzzle(size), new PuzzleSolver <Puzzle>( new IConstraint[] { new RowUniquenessConstraint(), new ColumnUniquenessConstraint(), new BoxUniquenessConstraint() })); Assert.Throws <TimeoutException>( () => generator.Generate(16, 150, TimeSpan.FromMilliseconds(1))); }
public void LoadAndGeneratePuzzle(string puzzleFileName) { currentBreaks = 0; commandManager.commandFreeze = false; cameraRot.camRotAllowed = true; completeTextDisplay.gameObject.SetActive(false); // 퍼즐 정보 불러오기 puzzle = SaveLoadManager.LoadPuzzle(puzzleFileName); currentOpenPuzzleNameDisplay.text = "퍼즐 이름 : " + puzzleFileName; if (puzzle == null) { Debug.Log("Error : 퍼즐 불러오기 실패!"); Application.Quit(); } // Cube들로 이루어진 퍼즐 생성 PuzzleGenerator puzzleGenerator = GetComponent <PuzzleGenerator>(); puzzleGenerator.GeneratePuzzle(puzzle); // 퍼즐의 큐브들 중 정답 큐브 mark for (int z = 0; z < puzzle.zLen; ++z) { for (int y = 0; y < puzzle.yLen; ++y) { for (int x = 0; x < puzzle.xLen; ++x) { puzzle.cubes[z, y, x].isAnswerCube = false; if (puzzle.answerArray[z, y, x] == 1) { puzzle.cubes[z, y, x].isAnswerCube = true; } } } } for (int i = 0; i < slicers.Length; ++i) { slicers[i].InitSlicer(puzzle); } // Edge Cube 사이즈를 새로운 퍼즐에 맞게 조절 edgeCube.transform.localScale = new Vector3(puzzle.xLen + 0.05f, puzzle.yLen + 0.05f, puzzle.zLen + 0.05f); }
public static IServiceCollection AddApplicationServices(this IServiceCollection serviceCollection) { serviceCollection.AddTransient <PuzzleGenerator <SudokuPuzzle>, SudokuGenerator>(); serviceCollection.AddTransient <PuzzlePrinter <SudokuPuzzle>, SudokuPrinter>(); serviceCollection.AddTransient <IRestServiceConnector, RestServiceConnector>(serviceProvider => new RestServiceConnector(Client)); serviceCollection.AddTransient <IPuzzleStorageService, PuzzleStorageService>(); serviceCollection.AddTransient <IPuzzleService <SudokuPuzzle>, SudokuPuzzleService>(serviceProvider => { PuzzleGenerator <SudokuPuzzle> puzzleGenerator = serviceProvider.GetService <PuzzleGenerator <SudokuPuzzle> >(); PuzzlePrinter <SudokuPuzzle> puzzlePrinter = serviceProvider.GetService <PuzzlePrinter <SudokuPuzzle> >(); return(new SudokuPuzzleService(puzzleGenerator, puzzlePrinter)); }); return(serviceCollection); }
public void PuzzleGenerator_Test1() { var puzzleSolver = new DlxPuzzleSolver(); var generatorOptions = new TestPuzzleGeneratorOptions(); var clueGenerator = new SymmetricClueCoordinateGenerator(); var puzzleSolution = (new PuzzleSolutionGenerator(PuzzleSize.NineByNine)).CreatePuzzleSolution(); var sut = new PuzzleGenerator(generatorOptions, puzzleSolver, clueGenerator, puzzleSolution); var result = sut.Generate(); Assert.NotNull(result); TestHelper.WriteLine(result.AsText()); }
public MainWindow() { InitializeComponent(); //var puzzle = PuzzleGenerator.CreateEmptyPuzzle(); var puzzle = PuzzleGenerator.CreateSolvable(); foreach (var box in puzzle.AllBoxes) { Boxes.Add(box); } DataContext = this; }
private void BlockCreation() { GameEvents.GameObjectMosaicDictionaty = new Dictionary <int, GameEvents.MosaicTile>(verticalBlockCount * gorizontalBlockCount); GameEvents.MosaicTile tempMosaicBlock; GameObject currentBlock = new GameObject(); string blockG = ""; int countBlocks = 0; Vector3 rotate = new Vector3(); generator = new PuzzleGenerator(verticalBlockCount, gorizontalBlockCount); for (int y = 0; y < verticalBlockCount; y++) { for (int x = 0; x < gorizontalBlockCount; x++) { for (int k = 0; k < pointerMosaicPrefabs.Length; k++) { currentBlock = null; if (generator.GetInstantiateBlockJigsawPuzzle(x, y, pointerMosaicPrefabs[k], ref rotate)) { currentBlock = pointerMosaicPrefabs[k]; blockG = generator.mosaicDivision[x, y]; break; } } if (currentBlock == null) { Debug.Log(blockG); continue; } tempMosaicBlock.obj = Instantiate(currentBlock, new Vector3(Random.Range(0 - Backplate.transform.localScale.x / 2 * 0.70f, Backplate.transform.localScale.x / 2 * 0.70f), Random.Range(0 - Backplate.transform.localScale.y / 2 * 0.70f, Backplate.transform.localScale.y / 2 * 0.70f), 0.06f), Quaternion.Euler(rotate)); //tempMosaicBlock.obj = Instantiate(currentBlock,new Vector3( x, y, 0.06f), Quaternion.Euler(rotate)); tempMosaicBlock.obj.name = countBlocks.ToString(); tempMosaicBlock.obj.transform.root.transform.localScale = new Vector3 { x = scaleX, y = 1.0f, z = scaleZ }; tempMosaicBlock.vector3rotate = rotate; tempMosaicBlock.blockID = x + y * gorizontalBlockCount; GameEvents.GameObjectMosaicDictionaty.Add(countBlocks++, tempMosaicBlock); } } }
public void Generate_CreatesPuzzleWithUniqueSolution(int size, int numToSet) { var generator = new PuzzleGenerator <Puzzle>( size => new Puzzle(size), new PuzzleSolver <Puzzle>( new IConstraint[] { new RowUniquenessConstraint(), new ColumnUniquenessConstraint(), new BoxUniquenessConstraint() })); Puzzle puzzle = generator.Generate(size, numToSet, TimeSpan.FromSeconds(60)); Assert.Equal(size * size - numToSet, puzzle.NumEmptySquares); var solver = RuleBased.StandardPuzzles.CreateSolver(); SolveStats stats = solver.ComputeStatsForAllSolutions(new RuleBased.PuzzleWithPossibleValues(puzzle)); Assert.Equal(1, stats.NumSolutionsFound); }
public void Constructor_WithValidArgs_Works() { var generator = new PuzzleGenerator <Puzzle>( () => new Puzzle(9), puzzle => new PuzzleSolver(puzzle)); }
public SudokuPuzzleService(PuzzleGenerator <SudokuPuzzle> puzzleGenerator, PuzzlePrinter <SudokuPuzzle> sudokuPrinter) { _sudokuGenerator = puzzleGenerator; _sudokuPrinter = sudokuPrinter; }
public void Constructor_WithValidArgs_Works() { var generator = new PuzzleGenerator <Puzzle>( size => new Puzzle(size), new PuzzleSolver <Puzzle>(new IConstraint[] { new RowUniquenessConstraint() })); }
static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Gray; int num = int.Parse(args[0]); int width = int.Parse(args[1]); int height = int.Parse(args[2]); int maxColor = int.Parse(args[3]); int numberOfPipes = -1; bool filterLame = false; if (args.Length > 4) { if (!int.TryParse(args[4], out numberOfPipes)) { filterLame = args[4].ToLower() == "true"; } } DateTime start = DateTime.Now; Console.WriteLine($"Generating {num} {width}x{height} colorlink level(s), with {(maxColor + 1)} possible colors"); int startCursor = Console.CursorTop; string filename = $"{width}x{height}.txt"; Int64 i = 0; while (File.Exists("Generated Colorlink Levels\\" + filename)) { filename = $"{width}x{height}_{i}.txt"; i++; } string path = Directory.GetCurrentDirectory() + $"\\Generated Colorlink Levels"; Directory.CreateDirectory(path); string filepath = path + $"\\{filename}"; Console.WriteLine("I'll output here:"); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(filepath); Console.ForegroundColor = ConsoleColor.White; List <Puzzle> levels = new List <Puzzle>(); Console.Write("Progess: "); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("0"); Console.ForegroundColor = ConsoleColor.White; Console.Write(" of " + num); for (int j = 0; j < num; j++) { levels.Add(PuzzleGenerator.GenerateSolvableLevel(width, height, maxColor, filterLame, numberOfPipes)); Console.CursorTop = 2 + startCursor; Console.CursorLeft = 9; Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(j + 1); Console.ForegroundColor = ConsoleColor.White; Console.Write($" of {num}"); } Console.WriteLine(); List <string> outputList = new List <string>(); foreach (Puzzle g in levels) { string[] arr = PuzzleGenerator.GridToString(g.level.grid); foreach (string s in arr) { outputList.Add(s); } outputList.Add(""); } string[] outputArr = outputList.ToArray(); string output = ""; for (int j = 0; j < outputArr.Length; j++) { output += outputArr[j] + "\n"; } File.AppendAllText(filepath, output); Console.ForegroundColor = ConsoleColor.Green; DateTime stop = DateTime.Now; Console.WriteLine($"All done. Generated in {(stop - start)}"); Console.ForegroundColor = ConsoleColor.Gray; }
public void Constructor_WithValidArgs_Works() { var generator = new PuzzleGenerator <PuzzleWithPossibleValues>( size => new PuzzleWithPossibleValues(size), StandardPuzzles.CreateSolver()); }
private static void Main() { var puzzle = PuzzleGenerator.CreateSolvable(); puzzle.PuzzlePrinter(); }