de.java_chess.javaChess.engine
Class ChessEngineImpl

java.lang.Object
  |
  +--de.java_chess.javaChess.engine.ChessEngineImpl

public class ChessEngineImpl
extends java.lang.Object
implements ChessEngine, java.lang.Runnable, java.awt.event.ActionListener

This class implements the functionality to play the actual game of chess


Constructor Summary
ChessEngineImpl(Game game, Board board, boolean white)
          Create a new engine instance with a given board.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent actionEvent)
          Perform a action (could be a menu related action).
 short analyzeBoard(Board board)
          Compute a score for a game position.
 Ply computeBestPly()
          Compute the best ply for the current position.
 Board getBoard()
          Get the current board.
 Game getGame()
          Get the current game.
 int getMaximumSearchTime()
          Get the maximum search time.
 javax.swing.JMenu getMenu()
          Return a menu from the chess engine, where the user can change the settings.
 boolean isWhite()
          Get the color of this engine.
 void run()
          The main method of the search thread.
 void setBoard(Board board)
          Set the board.
 void setEnginePanel(EnginePanel panel)
          Sets the EnginePanel to be able to output in the panel and not only with System.out.println(...)
 void setGame(Game game)
          Set the current game.
 void setMaximumSearchTime(int time)
          Set the maximum search time.
 void setWhite(boolean white)
          Set the color of the engine.
 void start()
          Start a new thread to search for a ply.
 boolean validateUserPly(Ply ply)
          Check if a ply made by the user is valid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChessEngineImpl

public ChessEngineImpl(Game game,
                       Board board,
                       boolean white)
Create a new engine instance with a given board.
Parameters:
board - The new board.
white - Flag, to indicate if the engine operates on the white pieces.
Method Detail

getGame

public final Game getGame()
Get the current game.
Specified by:
getGame in interface ChessEngine
Returns:
The current game.

setGame

public final void setGame(Game game)
Set the current game.
Specified by:
setGame in interface ChessEngine
Parameters:
The - current game.

getBoard

public Board getBoard()
Get the current board.
Specified by:
getBoard in interface ChessEngine
Returns:
The current board.

setBoard

public void setBoard(Board board)
Set the board.
Specified by:
setBoard in interface ChessEngine
Parameters:
board - The new board.

getMaximumSearchTime

public final int getMaximumSearchTime()
Get the maximum search time.
Returns:
The maximum search time.

setMaximumSearchTime

public final void setMaximumSearchTime(int time)
Set the maximum search time.
Parameters:
depth - The new search time.

isWhite

public boolean isWhite()
Get the color of this engine.
Specified by:
isWhite in interface ChessEngine
Parameters:
white - true, if the engine operates with the white pieces.

setWhite

public void setWhite(boolean white)
Set the color of the engine.
Specified by:
setWhite in interface ChessEngine
Parameters:
white - flag to indicate if the engine operates on the white pieces.

start

public void start()
Start a new thread to search for a ply.

computeBestPly

public Ply computeBestPly()
Compute the best ply for the current position.
Specified by:
computeBestPly in interface ChessEngine
Returns:
The best known ply for the current position.

run

public void run()
The main method of the search thread.
Specified by:
run in interface java.lang.Runnable

analyzeBoard

public final short analyzeBoard(Board board)
Compute a score for a game position.
Returns:
A score for the current game position.

validateUserPly

public final boolean validateUserPly(Ply ply)
Check if a ply made by the user is valid.
Specified by:
validateUserPly in interface ChessEngine
Parameters:
ply - The user ply.
Returns:
true, if the ply is valid. false otherwise.

getMenu

public final javax.swing.JMenu getMenu()
Return a menu from the chess engine, where the user can change the settings.
Specified by:
getMenu in interface ChessEngine
Returns:
A menu for the engine settings.

actionPerformed

public final void actionPerformed(java.awt.event.ActionEvent actionEvent)
Perform a action (could be a menu related action).
Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
actionEvent - The event.

setEnginePanel

public void setEnginePanel(EnginePanel panel)
Sets the EnginePanel to be able to output in the panel and not only with System.out.println(...)
Parameters:
panel - The EnginePanel to set