Search in sources :

Example 6 with EightPuzzleBoard

use of aima.core.environment.eightpuzzle.EightPuzzleBoard in project aima-java by aimacode.

the class EightPuzzleBoardMoveTest method testPosition2MoveUp.

@Test
public void testPosition2MoveUp() {
    // { 5, 0, 4, 6, 1, 8, 7, 3, 2 }
    setGapToPosition2();
    board.moveGapUp();
    Assert.assertEquals(new EightPuzzleBoard(new int[] { 5, 0, 4, 6, 1, 8, 7, 3, 2 }), board);
}
Also used : EightPuzzleBoard(aima.core.environment.eightpuzzle.EightPuzzleBoard) Test(org.junit.Test)

Example 7 with EightPuzzleBoard

use of aima.core.environment.eightpuzzle.EightPuzzleBoard in project aima-java by aimacode.

the class EightPuzzleBoardMoveTest method testPosition8MoveLeft.

@Test
public void testPosition8MoveLeft() {
    // { 6, 5, 4, 7, 1, 8, 3, 0, 2 }
    setGapToPosition8();
    board.moveGapLeft();
    Assert.assertEquals(new EightPuzzleBoard(new int[] { 6, 5, 4, 7, 1, 8, 0, 3, 2 }), board);
}
Also used : EightPuzzleBoard(aima.core.environment.eightpuzzle.EightPuzzleBoard) Test(org.junit.Test)

Example 8 with EightPuzzleBoard

use of aima.core.environment.eightpuzzle.EightPuzzleBoard in project aima-java by aimacode.

the class EightPuzzleFunctionsTest method testGenerateCorrect3Successors.

@Test
public void testGenerateCorrect3Successors() {
    List<Action> actions = new ArrayList<>(EightPuzzleFunctions.getActions(board));
    Assert.assertEquals(3, actions.size());
    // test first successor
    EightPuzzleBoard expectedFirst = new EightPuzzleBoard(new int[] { 1, 2, 0, 3, 4, 5, 6, 7, 8 });
    EightPuzzleBoard actualFirst = (EightPuzzleBoard) EightPuzzleFunctions.getResult(board, actions.get(0));
    Assert.assertEquals(expectedFirst, actualFirst);
    Assert.assertEquals(EightPuzzleBoard.UP, actions.get(0));
    // test second successor
    EightPuzzleBoard expectedSecond = new EightPuzzleBoard(new int[] { 1, 2, 5, 3, 4, 8, 6, 7, 0 });
    EightPuzzleBoard actualSecond = (EightPuzzleBoard) EightPuzzleFunctions.getResult(board, actions.get(1));
    Assert.assertEquals(expectedSecond, actualSecond);
    Assert.assertEquals(EightPuzzleBoard.DOWN, actions.get(1));
    // test third successor
    EightPuzzleBoard expectedThird = new EightPuzzleBoard(new int[] { 1, 2, 5, 3, 0, 4, 6, 7, 8 });
    EightPuzzleBoard actualThird = (EightPuzzleBoard) EightPuzzleFunctions.getResult(board, actions.get(2));
    Assert.assertEquals(expectedThird, actualThird);
    Assert.assertEquals(EightPuzzleBoard.LEFT, actions.get(2));
}
Also used : Action(aima.core.agent.Action) EightPuzzleBoard(aima.core.environment.eightpuzzle.EightPuzzleBoard) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 9 with EightPuzzleBoard

use of aima.core.environment.eightpuzzle.EightPuzzleBoard in project aima-java by aimacode.

the class EightPuzzleBoardMoveTest method testPosition1MoveDown.

@Test
public void testPosition1MoveDown() {
    board.moveGapDown();
    Assert.assertEquals(new EightPuzzleBoard(new int[] { 6, 5, 4, 0, 1, 8, 7, 3, 2 }), board);
}
Also used : EightPuzzleBoard(aima.core.environment.eightpuzzle.EightPuzzleBoard) Test(org.junit.Test)

Example 10 with EightPuzzleBoard

use of aima.core.environment.eightpuzzle.EightPuzzleBoard in project aima-java by aimacode.

the class EightPuzzleBoardMoveTest method testPosition5MoveLeft.

@Test
public void testPosition5MoveLeft() {
    // { 6, 5, 4, 1, 0, 8, 7, 3, 2 }
    setGapToPosition5();
    board.moveGapLeft();
    Assert.assertEquals(new EightPuzzleBoard(new int[] { 6, 5, 4, 0, 1, 8, 7, 3, 2 }), board);
}
Also used : EightPuzzleBoard(aima.core.environment.eightpuzzle.EightPuzzleBoard) Test(org.junit.Test)

Aggregations

EightPuzzleBoard (aima.core.environment.eightpuzzle.EightPuzzleBoard)43 Test (org.junit.Test)42 Action (aima.core.agent.Action)5 BidirectionalEightPuzzleProblem (aima.core.environment.eightpuzzle.BidirectionalEightPuzzleProblem)3 SearchAgent (aima.core.search.framework.SearchAgent)3 GoalTest (aima.core.search.framework.problem.GoalTest)3 MoveToAction (aima.core.environment.map.MoveToAction)2 GreedyBestFirstSearch (aima.core.search.informed.GreedyBestFirstSearch)2 ArrayList (java.util.ArrayList)2 Node (aima.core.search.framework.Node)1 AStarSearch (aima.core.search.informed.AStarSearch)1 Random (java.util.Random)1