/** * Generates puzzle based on current puzzle * (different puzzle, same solution). * * @see SudokuGenerator * @see SudokuGenerator#PARAM_DO_NOT_TRANSFORM * @see SudokuGenerator#generate() */ private void generateFromCurrentPuzzle() { generator = new SudokuGenerator(puzzle, SudokuGenerator.PARAM_DO_NOT_TRANSFORM); setGeneratorOptions(); int[,] generated = generator.generate(); if (generator.getGeneratorState() == SudokuGenerator.GENERATOR_GEN_FINISHED) { trackPuzzleUndo(); puzzle = generated; } else { JanetConsole.println(">>> !!! Error while generating puzzle !!! <<<"); JanetConsole.println(generator.getMessages()); } }
/** * Generates random puzzle with unique solution. * * @see SudokuGenerator * @see SudokuGenerator#PARAM_GEN_RND_BOARD * @see SudokuGenerator#generate() */ private void generateRandomPuzzle() { generator = new SudokuGenerator(SudokuGenerator.PARAM_GEN_RND_BOARD); setGeneratorOptions(); int[,] generated = generator.generate(); if (generator.getGeneratorState() == SudokuGenerator.GENERATOR_GEN_FINISHED) { trackPuzzleUndo(); puzzle = generated; } else { JanetConsole.println(">>> !!! Error while generating random puzzle !!! <<<"); JanetConsole.println(generator.getMessages()); } }
/** * Test scenario implementation. * @param testId Test id. * @param threadId Thread id. * @return True is test successful, otherwise false. */ static bool runTest(int testId, int threadId) { SudokuSolver solverGen, solverInit; SudokuGenerator g; int solUnq; int[,] genPuzzle; int[,] solvedGen, solvedInit, initBoard; bool testResult = true; switch (testId) { case 0: for (int example = 0; example < SudokuPuzzles.NUMBER_OF_PUZZLE_EXAMPLES; example++) { g = new SudokuGenerator(example, SudokuGenerator.PARAM_DO_NOT_TRANSFORM); genPuzzle = g.generate(); solverGen = new SudokuSolver(genPuzzle); ErrorCodes.consolePrintlnIfError(solverGen.solve()); solverInit = new SudokuSolver(example); ErrorCodes.consolePrintlnIfError(solverInit.solve()); solUnq = solverGen.checkIfUniqueSolution(); ErrorCodes.consolePrintlnIfError(solUnq); solvedGen = solverGen.getSolvedBoard(); solvedInit = solverInit.getSolvedBoard(); if ((solUnq == SudokuSolver.SOLUTION_UNIQUE) && (SudokuStore.boardsAreEqual(solvedGen, solvedInit) == true)) { //SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by example number, example: " + example + ", solution unique and correct: YES, time (g, s1, s2): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., " + solverInit.getComputingTime() + " s."); } else { testResult = false; SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by example number, example: " + example + ", solution unique and correct: NO, time (g, s1, s2): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., " + solverInit.getComputingTime() + " s."); Console.WriteLine("Initial board"); SudokuStore.consolePrintBoard(SudokuStore.getPuzzleExample(example)); Console.WriteLine("Generated puzzle"); SudokuStore.consolePrintBoard(genPuzzle); Console.WriteLine("Solved initial board"); SudokuStore.consolePrintBoard(solvedInit); Console.WriteLine("Solved generated puzzle"); SudokuStore.consolePrintBoard(solvedGen); } } break; case 1: for (int example = 0; example < SudokuPuzzles.NUMBER_OF_PUZZLE_EXAMPLES; example++) { initBoard = SudokuStore.getPuzzleExample(example); g = new SudokuGenerator(initBoard, SudokuGenerator.PARAM_DO_NOT_TRANSFORM, SudokuGenerator.PARAM_DO_NOT_SOLVE); genPuzzle = g.generate(); solverGen = new SudokuSolver(genPuzzle); ErrorCodes.consolePrintlnIfError(solverGen.solve()); solverInit = new SudokuSolver(initBoard); ErrorCodes.consolePrintlnIfError(solverInit.solve()); solUnq = solverGen.checkIfUniqueSolution(); ErrorCodes.consolePrintlnIfError(solUnq); solvedGen = solverGen.getSolvedBoard(); solvedInit = solverInit.getSolvedBoard(); if ((solUnq == SudokuSolver.SOLUTION_UNIQUE) && (SudokuStore.boardsAreEqual(solvedGen, solvedInit) == true)) { //SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by example board, example: " + example + ", solution unique and correct: YES, time (g, s1, s2): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., " + solverInit.getComputingTime() + " s."); } else { testResult = false; SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by example board, example: " + example + ", solution unique and correct: NO, time (g, s1, s2): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., " + solverInit.getComputingTime() + " s."); Console.WriteLine("Initial board"); SudokuStore.consolePrintBoard(initBoard); Console.WriteLine("Generated puzzle"); SudokuStore.consolePrintBoard(genPuzzle); Console.WriteLine("Solved initial board"); SudokuStore.consolePrintBoard(solvedInit); Console.WriteLine("Solved generated puzzle"); SudokuStore.consolePrintBoard(solvedGen); } } break; case 2: for (int example = 0; example < SudokuPuzzles.NUMBER_OF_PUZZLE_EXAMPLES; example++) { g = new SudokuGenerator(example); genPuzzle = g.generate(); solverGen = new SudokuSolver(genPuzzle); ErrorCodes.consolePrintlnIfError(solverGen.solve()); solUnq = solverGen.checkIfUniqueSolution(); ErrorCodes.consolePrintlnIfError(solUnq); solvedGen = solverGen.getSolvedBoard(); if ((solUnq == SudokuSolver.SOLUTION_UNIQUE) && (SudokuStore.checkPuzzle(genPuzzle) == true)) { //SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by example number, example: " + example + ", solution unique and correct: YES, time (g, s): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., "); } else { testResult = false; SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by example number, example: " + example + ", solution unique and correct: NO, time (g, s): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., "); Console.WriteLine("Generated puzzle"); SudokuStore.consolePrintBoard(genPuzzle); Console.WriteLine("Solved generated puzzle"); SudokuStore.consolePrintBoard(solvedGen); } } break; case 3: for (int example = 0; example < SudokuPuzzles.NUMBER_OF_PUZZLE_EXAMPLES; example++) { initBoard = SudokuStore.getPuzzleExample(example); g = new SudokuGenerator(initBoard, SudokuGenerator.PARAM_DO_NOT_SOLVE); genPuzzle = g.generate(); solverGen = new SudokuSolver(genPuzzle); ErrorCodes.consolePrintlnIfError(solverGen.solve()); solUnq = solverGen.checkIfUniqueSolution(); ErrorCodes.consolePrintlnIfError(solUnq); solvedGen = solverGen.getSolvedBoard(); if ((solUnq == SudokuSolver.SOLUTION_UNIQUE) && (SudokuStore.checkPuzzle(genPuzzle) == true)) { //SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by example board, example: " + example + ", solution unique and correct: YES, time (g, s): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., "); } else { testResult = false; SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by example board, example: " + example + ", solution unique and correct: NO, time (g, s): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., "); Console.WriteLine("Generated puzzle"); SudokuStore.consolePrintBoard(genPuzzle); Console.WriteLine("Solved initial board"); SudokuStore.consolePrintBoard(solvedGen); } } break; case 5: initBoard = SudokuPuzzles.PUZZLE_EMPTY; g = new SudokuGenerator(initBoard); genPuzzle = g.generate(); solverGen = new SudokuSolver(genPuzzle); ErrorCodes.consolePrintlnIfError(solverGen.solve()); solUnq = solverGen.checkIfUniqueSolution(); ErrorCodes.consolePrintlnIfError(solUnq); solvedGen = solverGen.getSolvedBoard(); if ((solUnq == SudokuSolver.SOLUTION_UNIQUE) && (SudokuStore.checkPuzzle(genPuzzle) == true)) { //SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by empty board, solution unique and correct: YES, time (g, s): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., "); } else { testResult = false; SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by empty board, solution unique and correct: NO, time (g, s): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., "); Console.WriteLine("Generated puzzle"); SudokuStore.consolePrintBoard(genPuzzle); Console.WriteLine("Solved initial board"); SudokuStore.consolePrintBoard(solvedGen); } break; case 6: initBoard = SudokuPuzzles.PUZZLE_EMPTY; g = new SudokuGenerator(initBoard, SudokuGenerator.PARAM_DO_NOT_SOLVE); if (g.getGeneratorState() == SudokuGenerator.GENERATOR_INIT_FAILED) { SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by empty board, solution unique and correct: YES, time (g, s): "); } else { testResult = false; SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by empty board, solution unique and correct: NO, time (g, s): "); SudokuStore.consolePrintln("Generator state: " + g.getGeneratorState()); Console.WriteLine(g.getMessages()); } break; case 7: initBoard = SudokuPuzzles.PUZZLE_ERROR; g = new SudokuGenerator(initBoard, SudokuGenerator.PARAM_DO_NOT_SOLVE); if (g.getGeneratorState() == SudokuGenerator.GENERATOR_INIT_FAILED) { SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by PUZZLE_ERROR + PARAM_DO_NOT_SOLVE, init failed: YES."); } else { testResult = false; SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by PUZZLE_ERROR + PARAM_DO_NOT_SOLVE, init failed: NO."); SudokuStore.consolePrintln("Generator state: " + g.getGeneratorState()); Console.WriteLine(g.getMessages()); } break; case 8: initBoard = SudokuPuzzles.PUZZLE_NON_UNIQUE_SOLUTION; g = new SudokuGenerator(initBoard); genPuzzle = g.generate(); solverGen = new SudokuSolver(genPuzzle); ErrorCodes.consolePrintlnIfError(solverGen.solve()); solUnq = solverGen.checkIfUniqueSolution(); ErrorCodes.consolePrintlnIfError(solUnq); solvedGen = solverGen.getSolvedBoard(); if ((solUnq == SudokuSolver.SOLUTION_UNIQUE) && (SudokuStore.checkPuzzle(genPuzzle) == true)) { //SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by empty board, solution unique and correct: YES, time (g, s): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., "); } else { testResult = false; SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by empty board, solution unique and correct: NO, time (g, s): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., "); Console.WriteLine("Generated puzzle"); SudokuStore.consolePrintBoard(genPuzzle); Console.WriteLine("Solved initial board"); SudokuStore.consolePrintBoard(solvedGen); } break; case 9: initBoard = SudokuPuzzles.PUZZLE_NON_UNIQUE_SOLUTION; g = new SudokuGenerator(initBoard, SudokuGenerator.PARAM_DO_NOT_SOLVE); if (g.getGeneratorState() == SudokuGenerator.GENERATOR_INIT_FAILED) { SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by PUZZLE_NON_UNIQUE_SOLUTION + PARAM_DO_NOT_SOLVE, init failed: YES."); } else { testResult = false; SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by PUZZLE_NON_UNIQUE_SOLUTION + PARAM_DO_NOT_SOLVE, init failed: NO."); SudokuStore.consolePrintln("Generator state: " + g.getGeneratorState()); Console.WriteLine(g.getMessages()); } break; } if (testResult == true) { SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + " >>>>>>>>>>>>>>>>>>>>>> SudokuGenerator, result: OK"); } else { SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + " >>>>>>>>>>>>>>>>>>>>>> SudokuGenerator, result: ERROR"); } return(testResult); }
/** * Test scenario implementation. * @param testId Test id. * @param threadId Thread id. * @return True is test successful, otherwise false. */ static bool runTest(int testId, int threadId) { SudokuSolver solverGen, solverInit; SudokuGenerator g; int solUnq; int[,] genPuzzle; int[,] solvedGen, solvedInit, initBoard; bool testResult = true; switch(testId) { case 0: for (int example = 0; example < SudokuPuzzles.NUMBER_OF_PUZZLE_EXAMPLES; example++) { g = new SudokuGenerator(example, SudokuGenerator.PARAM_DO_NOT_TRANSFORM); genPuzzle = g.generate(); solverGen = new SudokuSolver(genPuzzle); ErrorCodes.consolePrintlnIfError(solverGen.solve()); solverInit = new SudokuSolver(example); ErrorCodes.consolePrintlnIfError(solverInit.solve()); solUnq = solverGen.checkIfUniqueSolution(); ErrorCodes.consolePrintlnIfError(solUnq); solvedGen = solverGen.getSolvedBoard(); solvedInit = solverInit.getSolvedBoard(); if ( (solUnq == SudokuSolver.SOLUTION_UNIQUE) && ( SudokuStore.boardsAreEqual(solvedGen, solvedInit) == true ) ) { //SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by example number, example: " + example + ", solution unique and correct: YES, time (g, s1, s2): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., " + solverInit.getComputingTime() + " s."); } else { testResult = false; SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by example number, example: " + example + ", solution unique and correct: NO, time (g, s1, s2): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., " + solverInit.getComputingTime() + " s."); Console.WriteLine("Initial board"); SudokuStore.consolePrintBoard(SudokuStore.getPuzzleExample(example)); Console.WriteLine("Generated puzzle"); SudokuStore.consolePrintBoard(genPuzzle); Console.WriteLine("Solved initial board"); SudokuStore.consolePrintBoard(solvedInit); Console.WriteLine("Solved generated puzzle"); SudokuStore.consolePrintBoard(solvedGen); } } break; case 1: for (int example = 0; example < SudokuPuzzles.NUMBER_OF_PUZZLE_EXAMPLES; example++) { initBoard = SudokuStore.getPuzzleExample(example); g = new SudokuGenerator(initBoard, SudokuGenerator.PARAM_DO_NOT_TRANSFORM, SudokuGenerator.PARAM_DO_NOT_SOLVE); genPuzzle = g.generate(); solverGen = new SudokuSolver(genPuzzle); ErrorCodes.consolePrintlnIfError(solverGen.solve()); solverInit = new SudokuSolver(initBoard); ErrorCodes.consolePrintlnIfError(solverInit.solve()); solUnq = solverGen.checkIfUniqueSolution(); ErrorCodes.consolePrintlnIfError(solUnq); solvedGen = solverGen.getSolvedBoard(); solvedInit = solverInit.getSolvedBoard(); if ( (solUnq == SudokuSolver.SOLUTION_UNIQUE) && ( SudokuStore.boardsAreEqual(solvedGen, solvedInit) == true ) ) { //SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by example board, example: " + example + ", solution unique and correct: YES, time (g, s1, s2): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., " + solverInit.getComputingTime() + " s."); } else { testResult = false; SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by example board, example: " + example + ", solution unique and correct: NO, time (g, s1, s2): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., " + solverInit.getComputingTime() + " s."); Console.WriteLine("Initial board"); SudokuStore.consolePrintBoard(initBoard); Console.WriteLine("Generated puzzle"); SudokuStore.consolePrintBoard(genPuzzle); Console.WriteLine("Solved initial board"); SudokuStore.consolePrintBoard(solvedInit); Console.WriteLine("Solved generated puzzle"); SudokuStore.consolePrintBoard(solvedGen); } } break; case 2: for (int example = 0; example < SudokuPuzzles.NUMBER_OF_PUZZLE_EXAMPLES; example++) { g = new SudokuGenerator(example); genPuzzle = g.generate(); solverGen = new SudokuSolver(genPuzzle); ErrorCodes.consolePrintlnIfError(solverGen.solve()); solUnq = solverGen.checkIfUniqueSolution(); ErrorCodes.consolePrintlnIfError(solUnq); solvedGen = solverGen.getSolvedBoard(); if ( (solUnq == SudokuSolver.SOLUTION_UNIQUE) && ( SudokuStore.checkPuzzle(genPuzzle) == true ) ) { //SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by example number, example: " + example + ", solution unique and correct: YES, time (g, s): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., "); } else { testResult = false; SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by example number, example: " + example + ", solution unique and correct: NO, time (g, s): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., "); Console.WriteLine("Generated puzzle"); SudokuStore.consolePrintBoard(genPuzzle); Console.WriteLine("Solved generated puzzle"); SudokuStore.consolePrintBoard(solvedGen); } } break; case 3: for (int example = 0; example < SudokuPuzzles.NUMBER_OF_PUZZLE_EXAMPLES; example++) { initBoard = SudokuStore.getPuzzleExample(example); g = new SudokuGenerator(initBoard, SudokuGenerator.PARAM_DO_NOT_SOLVE); genPuzzle = g.generate(); solverGen = new SudokuSolver(genPuzzle); ErrorCodes.consolePrintlnIfError(solverGen.solve()); solUnq = solverGen.checkIfUniqueSolution(); ErrorCodes.consolePrintlnIfError(solUnq); solvedGen = solverGen.getSolvedBoard(); if ( (solUnq == SudokuSolver.SOLUTION_UNIQUE) && ( SudokuStore.checkPuzzle(genPuzzle) == true ) ) { //SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by example board, example: " + example + ", solution unique and correct: YES, time (g, s): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., "); } else { testResult = false; SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by example board, example: " + example + ", solution unique and correct: NO, time (g, s): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., "); Console.WriteLine("Generated puzzle"); SudokuStore.consolePrintBoard(genPuzzle); Console.WriteLine("Solved initial board"); SudokuStore.consolePrintBoard(solvedGen); } } break; case 5: initBoard = SudokuPuzzles.PUZZLE_EMPTY; g = new SudokuGenerator(initBoard); genPuzzle = g.generate(); solverGen = new SudokuSolver(genPuzzle); ErrorCodes.consolePrintlnIfError(solverGen.solve()); solUnq = solverGen.checkIfUniqueSolution(); ErrorCodes.consolePrintlnIfError(solUnq); solvedGen = solverGen.getSolvedBoard(); if ( (solUnq == SudokuSolver.SOLUTION_UNIQUE) && ( SudokuStore.checkPuzzle(genPuzzle) == true ) ) { //SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by empty board, solution unique and correct: YES, time (g, s): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., "); } else { testResult = false; SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by empty board, solution unique and correct: NO, time (g, s): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., "); Console.WriteLine("Generated puzzle"); SudokuStore.consolePrintBoard(genPuzzle); Console.WriteLine("Solved initial board"); SudokuStore.consolePrintBoard(solvedGen); } break; case 6: initBoard = SudokuPuzzles.PUZZLE_EMPTY; g = new SudokuGenerator(initBoard, SudokuGenerator.PARAM_DO_NOT_SOLVE); if ( g.getGeneratorState() == SudokuGenerator.GENERATOR_INIT_FAILED ) { SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by empty board, solution unique and correct: YES, time (g, s): "); } else { testResult = false; SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by empty board, solution unique and correct: NO, time (g, s): "); SudokuStore.consolePrintln("Generator state: " + g.getGeneratorState()); Console.WriteLine(g.getMessages()); } break; case 7: initBoard = SudokuPuzzles.PUZZLE_ERROR; g = new SudokuGenerator(initBoard, SudokuGenerator.PARAM_DO_NOT_SOLVE); if ( g.getGeneratorState() == SudokuGenerator.GENERATOR_INIT_FAILED ) { SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by PUZZLE_ERROR + PARAM_DO_NOT_SOLVE, init failed: YES."); } else { testResult = false; SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by PUZZLE_ERROR + PARAM_DO_NOT_SOLVE, init failed: NO."); SudokuStore.consolePrintln("Generator state: " + g.getGeneratorState()); Console.WriteLine(g.getMessages()); } break; case 8: initBoard = SudokuPuzzles.PUZZLE_NON_UNIQUE_SOLUTION; g = new SudokuGenerator(initBoard); genPuzzle = g.generate(); solverGen = new SudokuSolver(genPuzzle); ErrorCodes.consolePrintlnIfError(solverGen.solve()); solUnq = solverGen.checkIfUniqueSolution(); ErrorCodes.consolePrintlnIfError(solUnq); solvedGen = solverGen.getSolvedBoard(); if ( (solUnq == SudokuSolver.SOLUTION_UNIQUE) && ( SudokuStore.checkPuzzle(genPuzzle) == true ) ) { //SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by empty board, solution unique and correct: YES, time (g, s): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., "); } else { testResult = false; SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by empty board, solution unique and correct: NO, time (g, s): " + g.getComputingTime() + " s., " + solverGen.getComputingTime() + " s., "); Console.WriteLine("Generated puzzle"); SudokuStore.consolePrintBoard(genPuzzle); Console.WriteLine("Solved initial board"); SudokuStore.consolePrintBoard(solvedGen); } break; case 9: initBoard = SudokuPuzzles.PUZZLE_NON_UNIQUE_SOLUTION; g = new SudokuGenerator(initBoard, SudokuGenerator.PARAM_DO_NOT_SOLVE); if ( g.getGeneratorState() == SudokuGenerator.GENERATOR_INIT_FAILED ) { SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by PUZZLE_NON_UNIQUE_SOLUTION + PARAM_DO_NOT_SOLVE, init failed: YES."); } else { testResult = false; SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + ", generate by PUZZLE_NON_UNIQUE_SOLUTION + PARAM_DO_NOT_SOLVE, init failed: NO."); SudokuStore.consolePrintln("Generator state: " + g.getGeneratorState()); Console.WriteLine(g.getMessages()); } break; } if (testResult == true) SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + " >>>>>>>>>>>>>>>>>>>>>> SudokuGenerator, result: OK"); else SudokuStore.consolePrintln("(Thread: " + threadId + ") " + "Test: " + testId + " >>>>>>>>>>>>>>>>>>>>>> SudokuGenerator, result: ERROR"); return testResult; }
/** * Generates puzzle based on current puzzle * (different puzzle, same solution). * * @see SudokuGenerator * @see SudokuGenerator#PARAM_DO_NOT_TRANSFORM * @see SudokuGenerator#generate() */ private void generateFromCurrentPuzzle() { generator = new SudokuGenerator(puzzle, SudokuGenerator.PARAM_DO_NOT_TRANSFORM); setGeneratorOptions(); int[,] generated = generator.generate(); if (generator.getGeneratorState() == SudokuGenerator.GENERATOR_GEN_FINISHED) { trackPuzzleUndo(); puzzle = generated; } else { JanetConsole.println(">>> !!! Error while generating puzzle !!! <<<"); JanetConsole.println(generator.getMessages()); } }
/** * Generates random puzzle with unique solution. * Evaluates puzzle difficulty rating. * * @see SudokuGenerator * @see SudokuGenerator#PARAM_GEN_RND_BOARD * @see SudokuGenerator#generate() * @see SudokuStore#calculatePuzzleRating(int[,]) */ private void generateAndRateRandomPuzzle() { generator = new SudokuGenerator(SudokuGenerator.PARAM_GEN_RND_BOARD); setGeneratorOptions(); int[,] generated = generator.generate(); if (generator.getGeneratorState() == SudokuGenerator.GENERATOR_GEN_FINISHED) { trackPuzzleUndo(); puzzle = generated; ratePuzzleDifficulty(); } else { JanetConsole.println(">>> !!! Error while generating random puzzle !!! <<<"); JanetConsole.println(generator.getMessages()); } }