示例#1
0
        public void NoItems_ItemCountValidator_GreaterThanZero_FailureResult()
        {
            // configure our validators
            // there are none
            var moqValidators = new Mock <IDefaultValidators>();

            moqValidators.Setup(m => m.GetValidators()).Returns(new List <IValidator> {
                new ItemCountValidator {
                    Comparison = ECompareType.GREATERTHAN, Value = 0
                }
            });

            // configure our logging
            var moqLogging = new Mock <ILogger <ISolverService> >();

            // create our system
            var sut = new SolverService(moqLogging.Object, moqValidators.Object);

            // solve
            IAtlas <IItem> sutAtlas;
            bool           sutResult = sut.Solve <IItem>(64, 64, new List <IItem>(), out sutAtlas);

            Assert.False(sutResult);
            Assert.Null(sutAtlas);
        }
示例#2
0
        public void FindNeighbors(string seed, int expectedNeighbors)
        {
            var board           = seed.FromString();
            int actualNeighbors = SolverService.FindNeighborCount(board.First(), board);

            Assert.AreEqual(expectedNeighbors, actualNeighbors);
        }
示例#3
0
        static void Main(string[] args)
        {
            var table = FileService.ReadTable(Settings.ReadPath);

            Console.WriteLine(table.ToString());
            SolverService.Solve(table);
            Console.WriteLine(table.ToString());
            Console.ReadKey();
        }
        public void Solve_ForHardGridTwo_ShouldReturnSuccessStatus()
        {
            var solver   = new SolverService();
            var hardGrid = SudokuGrids.HardGridTwo;

            var result = solver.Solve(hardGrid);

            Assert.True(result.IsSuccess);
        }
        public void Solve_ForHardGridTwo_ShouldSolveWhole()
        {
            var solver   = new SolverService();
            var hardGrid = SudokuGrids.HardGridTwo;

            var result = solver.Solve(hardGrid);

            Assert.Equal(SudokuGrids.HardGridTwoSolution, result.SudokuGrid);
        }
        public void Solve_ForPartiallyHardGridThree_ShouldSolveWhole()
        {
            var solver   = new SolverService();
            var hardGrid = SudokuGrids.HardGridThreePartiallySolved;

            var result = solver.Solve(hardGrid);

            Assert.Equal(SudokuGrids.HardGridThreeSolution, result.SudokuGrid);
        }
        public void Solve_ForEasyGridThree_ShouldSolveWhole()
        {
            var solver   = new SolverService();
            var easyGrid = SudokuGrids.EasyGridThree;

            var result = solver.Solve(easyGrid);

            Assert.Equal(SudokuGrids.EasyGridThreeSolution, result.SudokuGrid);
        }
        public void Solve_ForExtremeGridFour_ShouldSolveWhole()
        {
            var solver      = new SolverService();
            var extremeGrid = SudokuGrids.ExtremeGridFour;

            var result = solver.Solve(extremeGrid);

            Assert.Equal(SudokuGrids.ExtremeGridFourSolution, result.SudokuGrid);
        }
        public void Solve_ForMediumGridFour_ShouldSolveWhole()
        {
            var solver     = new SolverService();
            var mediumGrid = SudokuGrids.MediumGridFourSolution;

            var result = solver.Solve(mediumGrid);

            Assert.Equal(SudokuGrids.MediumGridFourSolution, result.SudokuGrid);
        }
        public void Solve_ForExtremeGridThree_ShouldReturnSuccessStatus()
        {
            var solver      = new SolverService();
            var extremeGrid = SudokuGrids.ExtremeGridThree;

            var result = solver.Solve(extremeGrid);

            Assert.True(result.IsSuccess);
        }
        public void Solve_ForEmptyGrid_ShouldNotFillAnyCell()
        {
            var solver    = new SolverService();
            var emptyGrid = SudokuGrids.EmptyGrid;

            var result = solver.Solve(emptyGrid);

            Assert.Equal(SudokuGrids.EmptyGrid, result.SudokuGrid);
        }
        public void Solve_ForMediumGridOne_ShouldReturnSuccessStatus()
        {
            var solver     = new SolverService();
            var mediumGrid = SudokuGrids.MediumGridOne;

            var result = solver.Solve(mediumGrid);

            Assert.True(result.IsSuccess);
        }
        public void Solve_ForEmptyGrid_ShouldReturnFailedStatus()
        {
            var solver    = new SolverService();
            var emptyGrid = SudokuGrids.EmptyGrid;

            var result = solver.Solve(emptyGrid);

            Assert.False(result.IsSuccess);
        }
        public void Solve_ForEasyGridFour_ShouldReturnSuccessStatus()
        {
            var solver   = new SolverService();
            var easyGrid = SudokuGrids.EasyGridFour;

            var result = solver.Solve(easyGrid);

            Assert.True(result.IsSuccess);
        }
示例#15
0
        public void FourItems_NoValidators_SuccessResult()
        {
            // configure our validators
            // there are none
            var moqValidators = new Mock <IDefaultValidators>();

            moqValidators.Setup(m => m.GetValidators()).Returns(new List <IValidator>());

            // configure our logging
            var moqLogging = new Mock <ILogger <ISolverService> >();

            // create our system
            var sut = new SolverService(moqLogging.Object, moqValidators.Object);

            // solve
            IAtlas <IItem> sutAtlas;
            bool           sutResult = sut.Solve <IItem>(64, 64, CreateMockIItems(), out sutAtlas);

            // ensure we have an atlas
            Assert.True(sutResult);
            Assert.NotNull(sutAtlas);

            // get our asset items
            var sutAtlasItems = sutAtlas.GetConfiguredItems();

            // ensure we have a count of 4
            Assert.Equal(4, sutAtlasItems.Count);

            // compare the item placement
            // items 0 - 3
            Assert.Equal(0, sutAtlasItems[0].X);
            Assert.Equal(0, sutAtlasItems[0].Y);
            Assert.Equal(1, sutAtlasItems[0].Scale);
            Assert.Equal(32, sutAtlasItems[0].Width);
            Assert.Equal(32, sutAtlasItems[0].Height);

            Assert.Equal(32, sutAtlasItems[1].X);
            Assert.Equal(0, sutAtlasItems[1].Y);
            Assert.Equal(1, sutAtlasItems[1].Scale);
            Assert.Equal(32, sutAtlasItems[1].Width);
            Assert.Equal(32, sutAtlasItems[1].Height);

            Assert.Equal(0, sutAtlasItems[2].X);
            Assert.Equal(32, sutAtlasItems[2].Y);
            Assert.Equal(1, sutAtlasItems[2].Scale);
            Assert.Equal(32, sutAtlasItems[2].Width);
            Assert.Equal(32, sutAtlasItems[2].Height);

            Assert.Equal(32, sutAtlasItems[3].X);
            Assert.Equal(32, sutAtlasItems[3].Y);
            Assert.Equal(1, sutAtlasItems[3].Scale);
            Assert.Equal(32, sutAtlasItems[3].Width);
            Assert.Equal(32, sutAtlasItems[3].Height);
        }
        public void SearchForPairsInSquare_SpecificCase_ShouldFindPair()
        {
            var grid = SudokuGrids.SpecificCaseForPairInSquare;

            var context = new SolvingContext
            {
                ContinueSolving = true,
                Grid            = grid
            };

            SolverService.SearchForPairsInSquares(context);

            Assert.True(context.PairFound);
        }
示例#17
0
        public void TestSolveGeneration(string seed, string result, int numGenerations, string reason)
        {
            var seedBoard      = seed.FromString().ToList();
            var expectedResult = result.FromString().ToList();

            var actualResult = new List <Cell>();

            for (int i = 0; i < numGenerations; i++)
            {
                actualResult = SolverService.SolveGeneration(seedBoard);
            }

            expectedResult.Should().BeEquivalentTo(actualResult, because: reason);
        }
示例#18
0
        static void Main(string[] args)
        {
            Cell test  = new Cell(3, 5, 4, 0);
            var  setUp = new SetUpService();
            var  grid  = setUp.InitialiseGrid();

            var solver = new SolverService(grid);

            Console.WriteLine("Sudoku solver\n");
            Console.WriteLine("Grid to be solved\n");
            Console.WriteLine(grid.ToString());

            grid = solver.Solve();

            Console.WriteLine("\nGrid solved\n");
            Console.WriteLine(grid.ToString());
        }
示例#19
0
        static async Task Main(string[] args)
        {
            int generationsComputed = 0;

            Console.WriteLine("Hello World!");
            UpdateResponse updateResponse = new UpdateResponse();
            var            serverAPI      = RestService.For <IServerAPI>("http://daybellphotography.com");
            var            apiService     = new GOLAPIService(serverAPI);
            var            solverService  = new GOLService(apiService);
            var            random         = new Random();
            var            time           = DateTime.UtcNow.TimeOfDay;
            var            token          = await solverService.GetToken("BarnDoorMike" + random.Next().ToString());

            Console.WriteLine("Received Token: " + token);

            do
            {
                if (updateResponse != null)
                {
                    Console.WriteLine("Waiting for game to start... {0}", DateTime.Now);
                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
                updateResponse = await solverService.PostUpdate(token, 0);
            } while (updateResponse.GameState == GameState.NotStarted);

            var board = updateResponse.seedBoard;

            //game loop
            while (updateResponse.GameState == GameState.InProgress && generationsComputed < updateResponse.generationsToCompute)
            {
                var      newTime = DateTime.UtcNow.TimeOfDay;
                TimeSpan diff    = newTime.Subtract(time).Duration();
                if (diff.TotalSeconds >= 1)
                {
                    time = newTime;
                    _    = solverService.PostUpdate(token, generationsComputed);
                }
                board = SolverService.SolveGeneration(board);
                generationsComputed++;
            }

            _ = await solverService.PostCompleted(token, generationsComputed, board);

            Console.WriteLine("Game solved");
        }
        public void SearchSingleNumbersInSquares_SpecificCase_ShouldCrossOut2InFourthRow()
        {
            var grid = SudokuGrids.SpecificCaseForPairInSquare;

            var context = new SolvingContext
            {
                ContinueSolving = true,
                Grid            = grid
            };

            SolverService.SearchSingleNumbersInSquares(context);
            var updatedGrid = context.Grid;
            var row         = updatedGrid.GetRow(3);
            var eigthCell   = row.GetCell(7);
            var ninthCell   = row.GetCell(8);

            Assert.False(eigthCell.CanPutCandidate(2));
            Assert.False(ninthCell.CanPutCandidate(2));
        }
        public void SearchForPairsInSquareColumns_ForPartaillySolvedHardGridThree_ShouldRemovesTwosInFirstSquare()
        {
            var grid = SudokuGrids.HardGridThreePartiallySolved;

            var context = new SolvingContext
            {
                ContinueSolving = true,
                Grid            = grid
            };

            var allSquareIndices = new short[] { 0, 1, 2 };

            SolverService.SearchForPairsInSquareColumns(context, allSquareIndices);
            var updatedGrid = context.Grid;

            var firstRow  = updatedGrid.GetRow(0);
            var firstCell = firstRow.GetCell(0);

            Assert.False(firstCell.CanPutCandidate(2));
        }
示例#22
0
 public IAsyncEnumerable <Result <PasswordSolution> > GetResults(
     CancellationTokenSource token,
     SolverParameters parameters) =>
 SolverService.GetPasswordSolution(token, password, parameters);
示例#23
0
 public IAsyncEnumerable <Result <EightQueensSolution> > GetResults(
     CancellationTokenSource token,
     SolverParameters parameters) =>
 SolverService.GetEightQueensSolution(token, numQueens, parameters);
示例#24
0
 public IAsyncEnumerable <Result <FiveHousesSolution> > GetResults(
     CancellationTokenSource token,
     SolverParameters parameters) =>
 SolverService.GetFiveHousesSolution(token, parameters);
 public IAsyncEnumerable <Result <TravellingSalesmanSolution> > GetResults(
     CancellationTokenSource token,
     SolverParameters parameters) =>
 SolverService.GetTravellingSalesmanSolution(token, inputPoints, parameters);
示例#26
0
 public IAsyncEnumerable <Result <GeniusSquareSolution> > GetResults(
     CancellationTokenSource token,
     SolverParameters parameters) =>
 SolverService.GetGeniusSquareSolution(token, blockers, parameters);