ai.search
Class Puzzle8Problem

java.lang.Object
  extended byai.search.Problem
      extended byai.search.Puzzle8Problem
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener, java.lang.Runnable

public class Puzzle8Problem
extends Problem
implements java.awt.event.ActionListener

The 8-puzzle Problem In this implementation of the 8-puzzle we have a mix of priorities between efficiency and simplicity. The representation of states is not the obvious one (a 3x3 array), but it is both efficient and fairly easy to manipulate. We represent each tile as an integer from 0 to 8, arranged as follows: 0 1 2 3 4 5 6 7 8 Finally, we represent a state (i.e. a complete puzzle) as the sum of the tile numbers times 9 to the power of the tile's square number. For example, the state state from p63: 1 2 3 1*9^0 + 2*9^1 + 3*9^2 8 . 4 is represented by: + 8*9^3 + 0*9^4 + 4*9^5 7 6 5 + 7*9^6 + 6*9^7 + 5*9^8 = 247893796 We represent actions with the four symbols <, >, ^, V to stand for moving the blank tile left, right, up and down respectively.

Author:
Jill Zimmerman -- jill.zimmerman@goucher.edu

Field Summary
 
Fields inherited from class ai.search.Problem
algorithm, canvas, currentNode, display, goal, heuristic, initialState, numExpanded, q, search, searchResult
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
           
 java.lang.String actionToString(java.lang.Object action)
          Convert an action to a string.
 boolean equalState(java.lang.Object state1, java.lang.Object state2)
          Determine if two states are equivalent.
 boolean goalReached(java.lang.Object state)
          Is the state a goal state?
 int hCost(java.lang.Object state)
          Estimate the number of moves to the goal using heuristic.
 java.lang.String stateToString(java.lang.Object state)
          Convert a state to a string.
 java.util.Vector successors(java.lang.Object state)
          Determine all the states which are successors of the given state.
 
Methods inherited from class ai.search.Problem
edgeCost, run, solve, start, stop
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

goalReached

public boolean goalReached(java.lang.Object state)
Is the state a goal state?

Overrides:
goalReached in class Problem

successors

public java.util.Vector successors(java.lang.Object state)
Determine all the states which are successors of the given state.

Specified by:
successors in class Problem
Parameters:
state - is the given state
Returns:
a vector of successors

hCost

public int hCost(java.lang.Object state)
Estimate the number of moves to the goal using heuristic.

Overrides:
hCost in class Problem
Parameters:
state - is the given state

equalState

public boolean equalState(java.lang.Object state1,
                          java.lang.Object state2)
Description copied from class: Problem
Determine if two states are equivalent.

Specified by:
equalState in class Problem
Parameters:
state1 - and states are the two states
Returns:
true if equal

stateToString

public java.lang.String stateToString(java.lang.Object state)
Description copied from class: Problem
Convert a state to a string.

Specified by:
stateToString in class Problem
Parameters:
state - is the given state
Returns:
a string expressing the state

actionToString

public java.lang.String actionToString(java.lang.Object action)
Description copied from class: Problem
Convert an action to a string.

Specified by:
actionToString in class Problem
Parameters:
action - is the given action
Returns:
a string expressing the action

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Specified by:
actionPerformed in interface java.awt.event.ActionListener
Overrides:
actionPerformed in class Problem