implementation.gridpuzzle
Class GridProblem

java.lang.Object
  extended by implementation.gridpuzzle.GridProblem
All Implemented Interfaces:
HeuristicProblem<GridState>, Problem<GridState>, TreeProblem<GridState>

public class GridProblem
extends java.lang.Object
implements HeuristicProblem<GridState>


Constructor Summary
GridProblem(GameGrid initial, GameGrid goal, AbstractHeuristic heuristic)
           
 
Method Summary
 int depth(GridState state)
          Returns the depth of the given state in the search tree.
 java.util.List<GridState> expand(GridState state)
          Generates all successor states of the given state.
 double g(GridState state)
          This method returns the sum of all path costs from the initial to the given state.
 double h(GridState state)
          This method computes the proximity of the given state to a goal.
 GridState initial()
          Returns the starting state of the search.
 boolean isGoal(GridState state)
          Checks whether a given state is a goal of the search or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GridProblem

public GridProblem(GameGrid initial,
                   GameGrid goal,
                   AbstractHeuristic heuristic)
Method Detail

g

public double g(GridState state)
Description copied from interface: HeuristicProblem
This method returns the sum of all path costs from the initial to the given state.

Specified by:
g in interface HeuristicProblem<GridState>
Parameters:
state - to be inspected
Returns:
the sum of the path costs from the initial state to the given state

h

public double h(GridState state)
Description copied from interface: HeuristicProblem
This method computes the proximity of the given state to a goal. The value returned should express how much the path from the given state to a goal state may cost. Note: For optimality and completeness it is important to obeys the following rules.

Specified by:
h in interface HeuristicProblem<GridState>
Returns:
an approximation of the path costs needed to reach a goal.

depth

public int depth(GridState state)
Description copied from interface: TreeProblem
Returns the depth of the given state in the search tree.
Note: Only initial states should have a depth of 0.

Specified by:
depth in interface TreeProblem<GridState>
Parameters:
state - the state to be inspected
Returns:
a positive integer indicating the depth of a state.

expand

public java.util.List<GridState> expand(GridState state)
Description copied from interface: Problem
Generates all successor states of the given state.
This method should never return null. If the state can not be expanded than you should return an empty List.
Note: Most search algorithms have the ability to check for duplicate states, but if you want to implement your own duplicate handling than this method is the place to put it in.

Specified by:
expand in interface Problem<GridState>
Parameters:
state - to be expanded
Returns:
a List of all successor states

initial

public GridState initial()
Description copied from interface: Problem
Returns the starting state of the search.
Note: In some cases (e.g. HillClimbing) it is feasible to return a random generated state, instead of one single starting state.

Specified by:
initial in interface Problem<GridState>
Returns:
the initial state of your search domain

isGoal

public boolean isGoal(GridState state)
Description copied from interface: Problem
Checks whether a given state is a goal of the search or not.

Specified by:
isGoal in interface Problem<GridState>
Parameters:
state - to be checked
Returns:
true only if the state is one of the goal states