Search in sources :

Example 26 with EightPuzzleBoard

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

the class MisplacedTileHeuristicFunctionTest method testHeuristicCalculation.

@Test
public void testHeuristicCalculation() {
    ToDoubleFunction<Node<EightPuzzleBoard, Action>> h = EightPuzzleFunctions.createMisplacedTileHeuristicFunction();
    EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 2, 0, 5, 6, 4, 8, 3, 7, 1 });
    Assert.assertEquals(6.0, h.applyAsDouble(new Node<>(board)), 0.001);
    board = new EightPuzzleBoard(new int[] { 6, 2, 5, 3, 4, 8, 0, 7, 1 });
    Assert.assertEquals(5.0, h.applyAsDouble(new Node<>(board)), 0.001);
    board = new EightPuzzleBoard(new int[] { 6, 2, 5, 3, 4, 8, 7, 0, 1 });
    Assert.assertEquals(6.0, h.applyAsDouble(new Node<>(board)), 0.001);
    board = new EightPuzzleBoard(new int[] { 8, 1, 2, 3, 4, 5, 6, 7, 0 });
    Assert.assertEquals(1.0, h.applyAsDouble(new Node<>(board)), 0.001);
    board = new EightPuzzleBoard(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 });
    Assert.assertEquals(0.0, h.applyAsDouble(new Node<>(board)), 0.001);
}
Also used : EightPuzzleBoard(aima.core.environment.eightpuzzle.EightPuzzleBoard) Node(aima.core.search.framework.Node) Test(org.junit.Test)

Example 27 with EightPuzzleBoard

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

the class EightPuzzleBoardMoveTest method testPosition3MoveLeft.

@Test
public void testPosition3MoveLeft() {
    // { 5, 4, 0, 6, 1, 8, 7, 3, 2 }
    setGapToPosition3();
    board.moveGapLeft();
    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 28 with EightPuzzleBoard

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

the class EightPuzzleBoardMoveTest method testPosition2MoveLeft.

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

Example 29 with EightPuzzleBoard

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

the class EightPuzzleBoardMoveTest method testPosition9MoveUp.

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

Example 30 with EightPuzzleBoard

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

the class EightPuzzleBoardMoveTest method testPosition7MoveLeft.

@Test
public void testPosition7MoveLeft() {
    // { 6, 5, 4, 7, 1, 8, 0, 3, 2 }
    setGapToPosition7();
    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)

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