コード例 #1
0
        public void Test1()
        {
            // Arrange
            BoardState state = new BoardState(3, 3, new[] { 1, 2, 0, 4, 5, 3, 7, 8, 6 });
            BoardGoal goal = BoardGoal.CreateCompleted(3, 3);
            IBoardSolverService solver = new BoardSolverService();

            // Act
            Step[] steps = solver.GetSolution(state, goal, CancellationToken.None)[0];

            // Assert
            CollectionAssert.AreEqual(new[] { Step.Up, Step.Up }, steps);
        }
コード例 #2
0
        public void RandomTests()
        {
            BoardTemplate template = BoardTemplate.CreateEmpty(3, 3);
            BoardGoal goal = BoardGoal.CreateCompleted(3, 3);

            IBoardGeneratorService generator = new BoardGeneratorService();
            IBoardSolverService solver = new BoardSolverService();

            for (int i = 0; i < 100; i++)
            {
                BoardState state = generator.Generate(template);
                Step[] solution = solver.GetSolution(state, goal, CancellationToken.None)[0];
                foreach (Step step in solution)
                {
                    switch (step)
                    {
                        case Step.Left:
                            state = state.SlideLeft();
                            break;
                        case Step.Up:
                            state = state.SlideUp();
                            break;
                        case Step.Right:
                            state = state.SlideRight();
                            break;
                        case Step.Down:
                            state = state.SlideDown();
                            break;
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                }

                Assert.IsTrue(state.Satisfies(goal));
            }
        }
コード例 #3
0
 new = SolverService(MessageBus, GameService, BoardSolverService, Dispatcher);