Beispiel #1
0
        public void TestNPuzzleProblemGoalTest()
        {
            int[] state = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            NPuzzleState <int[]> initialState = new NPuzzleState <int[]>(state);

            int[] state2 = { 1, 2, 3, 4, 5, 6, 7, 9, 8 };

            NPuzzleState <int[]> initialState2 = new NPuzzleState <int[]>(state2);

            Problem.NPuzzleProblem <NPuzzleState <int[]>, int, int> problem = CreateProblem(initialState);
            Assert.False(problem.GoalTest(initialState2));
            Assert.True(problem.GoalTest(initialState));
        }
Beispiel #2
0
        public void TestNPuzzleInitialState()
        {
            int[] goal    = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            int[] initial = { 1, 2, 3, 4, 5, 6, 7, 9, 8 };
            NPuzzleState <int[]> goalState    = new NPuzzleState <int[]>(goal);
            NPuzzleState <int[]> initialState = new NPuzzleState <int[]>(initial);


            try {
                Problem.NPuzzleProblem <NPuzzleState <int[]>, int, int> problem = new Problem.NPuzzleProblem <NPuzzleState <int[]>, int, int>(goalState, initialState);
                Assert.NotNull(problem);
                Assert.NotNull(problem.InitialState);
                Assert.AreEqual(problem.InitialState, initialState);
                Problem.AbstractProblem <NPuzzleState <int[]>, int, int> p2 = new Problem.NPuzzleProblem <NPuzzleState <int[]>, int, int>(goalState, initialState);
                Assert.NotNull(p2);
                Assert.True(p2.GoalTest(goalState));
                Assert.AreEqual(p2.Result(initialState, 1), goalState);
                List <int> results = new List <int>();
                results.Add(1);
                results.Add(-1);
                results.Add(2);
                Assert.AreEqual(p2.Actions(initialState), results);
            } catch (NPuzzleUtils.InvalidNPuzzleStatesException ex) {
            }
        }