Translator Code




/**
 * Searcher.java - a superclass for AI searcher classes.
 *
 * @author Todd Neller
 * @version 1.0
 *

Copyright (C) 2003 Todd Neller

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

Information about the GNU General Public License is available online at:
  http://www.gnu.org/licenses/
To receive a copy of the GNU General Public License, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.

 */

public abstract class Searcher {

    /**
     * nodeCount - number of nodes that have been goal-checked
     */
    int nodeCount = 0;
    
    /**
     * goalNode - a goal node if the previous search was
     * successful; null otherwise.
     */
    MapNode goalNode = null;
    
    /**
     * search - Search for a goal node starting at the
     * given "root" MapNode, and return whether or not a goal node
     * was found.
     *
     * @param node a MapNode value - the initial
     * "root" search node
     * @return a boolean value - whether or not a goal
     * node was found */
    public abstract boolean search(MapNode node);
    

    /**
     * getGoalNode - Returns a goal node if the previous
     * search was successful, and null otherwise.
     *
     * @return a MapNode value - the goal node from
     * previous search or null if no goal node was found */
    public MapNode getGoalNode() 
    {
	return goalNode;
    }

    
    /**
     * getNodeCount - Returns the number of nodes
     * examined (goal-checked) in the previous search.
     *
     * @return an int value - the number of nodes checked
     * in the previous search.  This may be considerably less than the
     * number of children generated. */
    public int getNodeCount() 
    {
	return nodeCount;
    }


    /**
     * printGoalPath - If the previous search was
     * successful, print each node along the goal path in sequence
     * starting with the root node.  Otherwise, print "Goal node not
     * found".  */
    public void printGoalPath() 
    {
	if (goalNode == null)
	    //System.out.println("Goal node not found");
;	else
	    printPath(goalNode);
    }
    

    /**
     * printPath - print each node along the path to the
     * given node in sequence starting with the root node.
     *
     * @param node a MapNode value */
    private void printPath(MapNode node) 
    {
	if (node.parent != null)
	    printPath(node.parent);
	//System.out.println(node);
    }


}// Searcher