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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations