コード例 #1
0
        public void Generate_Should_Return_A_Solvable_Puzzle()
        {
            SudokuPuzzle   puzzle   = _sudokuPuzzleService.Generate();
            PuzzleSolveDto solveDto = _sudokuPuzzleService.Solve(puzzle);

            Assert.IsTrue(solveDto.Success);
        }
コード例 #2
0
        public void Solve_Should_Fail_When_PuzzleState_Is_Not_Solvable()
        {
            SudokuPuzzle   sudoku   = CreateInValidSudokuPuzzle();
            PuzzleSolveDto solveDto = _sudokuPuzzleService.Solve(sudoku);

            Assert.IsFalse(solveDto.Success);
        }
コード例 #3
0
        public void Solve_Should_Return_A_Solved_PuzzleState_Equal_To_Expected_Solution()
        {
            const string   solution = "534297618187465329962381574246819753718543296395726841459632187823174965671958432";
            SudokuPuzzle   puzzle   = CreateValidSudokuPuzzle();
            PuzzleSolveDto solveDto = _sudokuPuzzleService.Solve(puzzle);

            Assert.AreEqual(solution, solveDto.SolvedState.ToString());
            Assert.IsTrue(solveDto.PuzzleStates.Count == 6599);
        }
コード例 #4
0
        public static async Task Main(string[] args)
        {
            Startup startup = new Startup();
            await startup.InitializeAsync();

            IGenericServiceProvider       serviceProvider = startup.GetServiceProvider();
            IPuzzleService <SudokuPuzzle> puzzleService   = serviceProvider.GetService <IPuzzleService <SudokuPuzzle> >();

            SudokuPuzzle puzzle       = puzzleService.Generate();
            string       beforePuzzle = puzzleService.Print(puzzle);

            Console.WriteLine("Sudoku");
            Console.Write(beforePuzzle);
            Stopwatch      stopwatch      = Stopwatch.StartNew();
            PuzzleSolveDto puzzleSolveDto = puzzleService.Solve(puzzle);

            stopwatch.Stop();

            if (puzzleSolveDto.Success)
            {
                Console.WriteLine($"Solved in: {stopwatch.ElapsedMilliseconds}ms");
                string afterPuzzle = puzzleService.Print(puzzle);
                Console.WriteLine(afterPuzzle);
                ConsoleKeyInfo input;
                do
                {
                    Console.Write("\rPrint all puzzle states? [y/n]\n");
                    input = Console.ReadKey();
                    if (input.KeyChar == 'y')
                    {
                        foreach (PuzzleState state in puzzleSolveDto.PuzzleStates)
                        {
                            Console.Write("\n" + state);
                        }
                        Console.WriteLine();
                        break;
                    }

                    if (!input.KeyChar.Equals('n'))
                    {
                        continue;
                    }
                    Console.WriteLine();
                    break;
                } while (!input.KeyChar.Equals('y') || !input.KeyChar.Equals('n'));
            }
            else
            {
                Console.WriteLine("Failed to solve puzzle!");
            }

            Console.WriteLine("Done. Press any key to quit.");
            Console.ReadKey();
        }
コード例 #5
0
ファイル: PuzzleHandler.cs プロジェクト: metalglove/Pazuru
        private async Task SudokuVerifyPuzzleRequest(IWebSocket socket, string json)
        {
            VerifySudokuRequest        sudokuPuzzleStateMessage = JsonConvert.DeserializeObject <VerifySudokuRequest>(json);
            SudokuPuzzle               puzzle = new SudokuPuzzle(new PuzzleState(Encoding.Default.GetBytes(sudokuPuzzleStateMessage.Data.PuzzleAsString)));
            PuzzleSolveDto             solve  = _sudokuPuzzleService.Solve(puzzle);
            VerifySudokuPuzzleResponse verifySudokuEvenMessage;

            if (!solve.Success)
            {
                verifySudokuEvenMessage = new VerifySudokuPuzzleResponse
                {
                    Data      = default,