ai-22 / src / am / aua / npuzzle / GGSH2_Demo.java
GGSH2_Demo.java
Raw
package am.aua.npuzzle;

import am.aua.search.BestFirstGraphSearch;
import am.aua.search.GoalTest;
import am.aua.search.Node;

public class GGSH2_Demo {
    public static void main(String[] args) {
        Tiles initialConfiguration = new Tiles(new int[][] {
                { 7, 4, 2 },
                { 8, 1, 3 },
                { 5, 0, 6 }
        });

        GoalTest goalTest = new TilesGoalTest();
        BestFirstGraphSearch search = new BestFirstGraphSearch(new ManhattanDistanceHeuristic(goalTest)){
            @Override
            public String toString() {
                return "Greedy Graph Search with h2 manhattan distance";
            }
        };
        Node solution = search.search(initialConfiguration, goalTest);

        if (args.length == 0) {
            System.out.println("This is a demonstration of Greedy Graph Search on 8-puzzle with h2 manhattan distance");
            System.out.println();
            new NPuzzlePrinting().printSolution(solution);
        } else if (args[0].equals("-s")) {
            new NPuzzlePrinting().printStatistics(search);
        }
    }
}