Search in sources :

Example 41 with EightPuzzleBoard

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);
}
Also used : EightPuzzleBoard(aima.core.environment.eightpuzzle.EightPuzzleBoard) Test(org.junit.Test)

Example 42 with EightPuzzleBoard

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.");
    }
}
Also used : Action(aima.core.agent.Action) MoveToAction(aima.core.environment.map.MoveToAction) EightPuzzleBoard(aima.core.environment.eightpuzzle.EightPuzzleBoard) SearchAgent(aima.core.search.framework.SearchAgent) BidirectionalEightPuzzleProblem(aima.core.environment.eightpuzzle.BidirectionalEightPuzzleProblem) GreedyBestFirstSearch(aima.core.search.informed.GreedyBestFirstSearch) Test(org.junit.Test) GoalTest(aima.core.search.framework.problem.GoalTest)

Example 43 with EightPuzzleBoard

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);
}
Also used : EightPuzzleBoard(aima.core.environment.eightpuzzle.EightPuzzleBoard) Random(java.util.Random)

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