use of aima.core.environment.eightpuzzle.EightPuzzleBoard in project aima-java by aimacode.
the class EightPuzzleBoardMoveTest method testPosition4MoveDown.
@Test
public void testPosition4MoveDown() {
// { 6, 5, 4, 0, 1, 8, 7, 3, 2 }
setGapToPosition4();
board.moveGapDown();
Assert.assertEquals(new EightPuzzleBoard(new int[] { 6, 5, 4, 7, 1, 8, 0, 3, 2 }), board);
}
use of aima.core.environment.eightpuzzle.EightPuzzleBoard in project aima-java by aimacode.
the class GreedyBestFirstSearchTest method testGreedyBestFirstSearchReducedFrontier.
@Test
public void testGreedyBestFirstSearchReducedFrontier() {
try {
// EightPuzzleBoard extreme = new EightPuzzleBoard(new int[]
// {2,0,5,6,4,8,3,7,1});
// EightPuzzleBoard extreme = new EightPuzzleBoard(new int[]
// {0,8,7,6,5,4,3,2,1});
EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 7, 1, 8, 0, 4, 6, 2, 3, 5 });
Problem<EightPuzzleBoard, Action> problem = new BidirectionalEightPuzzleProblem(board);
QueueBasedSearch<EightPuzzleBoard, Action> search = new GreedyBestFirstSearch<>(new GraphSearchReducedFrontier<>(), EightPuzzleFunctions.createManhattanHeuristicFunction());
SearchAgent<EightPuzzleBoard, Action> agent = new SearchAgent<>(problem, search);
Assert.assertEquals(49, agent.getActions().size());
Assert.assertEquals("197", agent.getInstrumentation().getProperty("nodesExpanded"));
Assert.assertEquals("140", agent.getInstrumentation().getProperty("queueSize"));
Assert.assertEquals("141", agent.getInstrumentation().getProperty("maxQueueSize"));
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Exception thrown.");
}
}
use of aima.core.environment.eightpuzzle.EightPuzzleBoard in project aima-java by aimacode.
the class GenerateRandomEightPuzzleDemo method main.
public static void main(String[] args) {
Random r = new Random();
EightPuzzleBoard board = new EightPuzzleBoard(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 });
for (int i = 0; i < 50; i++) {
int th = r.nextInt(4);
if (th == 0) {
board.moveGapUp();
}
if (th == 1) {
board.moveGapDown();
}
if (th == 2) {
board.moveGapLeft();
}
if (th == 3) {
board.moveGapRight();
}
}
System.out.println(board);
}
Aggregations