Algorithm
Development Kit 1.0

algs.model.problems.eightpuzzle
Class BadEvaluator

java.lang.Object
  extended by algs.model.problems.eightpuzzle.BadEvaluator
All Implemented Interfaces:
IScore

public class BadEvaluator
extends java.lang.Object
implements IScore

Bad evaluation function.

Instead of considering the goal, take differences of distant cells and sum. Note that we subtract in (what should be) decreasing order of the results. Then compare against 16 (the ideal). For example,

   8 1 -       6 - 3   = 3
   6 7 3       2 - 0   = 2
   2 5 4       5 - 1   = 4
               4 - 8   = -4
                       -----
                        5
                        
   1 4 8       7 - 0   = 7
   7 3 -       6 - 8   = -2
   6 5 2       5 - 4   = 1
               2 - 1   = 1
                        ----
                         7                    
 
Has distance of 19 from the ideal of 16.

Since:
1.0
Version:
1.0, 6/15/08
Author:
George Heineman

Constructor Summary
BadEvaluator()
           
 
Method Summary
 int eval(INode state)
          Eval = g(n) + W(n), where g(n) is length of the path from initial to node n, and W(n) counts number of misplaced tiles in the state description
 void score(INode state)
          Evaluate the given state and update its score using our scoring function.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BadEvaluator

public BadEvaluator()
Method Detail

score

public void score(INode state)
Description copied from interface: IScore
Evaluate the given state and update its score using our scoring function.

Specified by:
score in interface IScore
Parameters:
state - The board state whose score value is to be updated.
See Also:
IScore.score(INode)

eval

public int eval(INode state)
Eval = g(n) + W(n), where g(n) is length of the path from initial to node n, and W(n) counts number of misplaced tiles in the state description

Specified by:
eval in interface IScore
Parameters:
state - state being evaluated
See Also:
IScore.score(INode)

Algorithm Development Kit 1.0

This code supports the Algorithms in a Nutshell book, published by O'Reilly Media, Inc. in November 2008. Please visit the book web page to learn of any changes to the code repository or to record a potential defect.