com.carlosbcruz.engine
Class BoardSolver

java.lang.Object
  extended by java.lang.Thread
      extended by com.carlosbcruz.engine.BoardSolver
All Implemented Interfaces:
java.lang.Runnable

public class BoardSolver
extends java.lang.Thread

Apply a backtrack algorith to solve the board problem.

Author:
Carlos Fernando Bella Cruz - pessoal@carlosbcruz.com

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
BoardSolver(Board boardToBeSolver)
          Thread that will work on a specific board.
 
Method Summary
 Board getLastFoundSolution()
          Return the last found soulution.
 int getNumberOfSolutions()
          Inform the number of solutions found.
 int getStepsAnalyzed()
          Get the number of steps executed.
 boolean isStopAtFirstSolution()
          Indicate if the flat stop after a solution is set or not.
 void run()
           
 void setExitRequested(boolean exitRequested)
          Request the solver to exit.
 void setStopAtFirstSolution(boolean stopAtFirstSolution)
          set if the it is required to stop after a solution.
 boolean solveBoard(Board board)
          Start the seek for a solution.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BoardSolver

public BoardSolver(Board boardToBeSolver)
Thread that will work on a specific board.

Parameters:
boardToBeSolver -
Method Detail

setExitRequested

public void setExitRequested(boolean exitRequested)
Request the solver to exit.

Parameters:
exitRequested - The exitRequested to set.

getNumberOfSolutions

public int getNumberOfSolutions()
Inform the number of solutions found.

Returns:
Returns the numberOfSolutions.

isStopAtFirstSolution

public boolean isStopAtFirstSolution()
Indicate if the flat stop after a solution is set or not.

Returns:
Returns the stopAtFirstSolution.

setStopAtFirstSolution

public void setStopAtFirstSolution(boolean stopAtFirstSolution)
set if the it is required to stop after a solution.

Parameters:
stopAtFirstSolution - The stopAtFirstSolution to set.

getStepsAnalyzed

public int getStepsAnalyzed()
Get the number of steps executed.

Returns:
Returns the stepsAnalyzed.

getLastFoundSolution

public Board getLastFoundSolution()
Return the last found soulution.

Returns:
Returns the lastFoundSolution.

solveBoard

public boolean solveBoard(Board board)
Start the seek for a solution.

Parameters:
board - the problem describe in the board
Returns:
true if it is solved and false otherwise. Also return false if requested to stop.

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread