klaus.engine
Class UCIEngine

java.lang.Object
  extended by klaus.engine.Engine
      extended by klaus.engine.UCIEngine
All Implemented Interfaces:
Runnable

public class UCIEngine
extends Engine
implements Runnable

This class is used for binding an UCI engine (e. g. Toga, Fruit) to Klaus.


Field Summary
private  boolean blocked
          Check if anything can be sent to the engine
private  int btime
           
private  int bTimeUsed
           
private  Process connection
           
private  Thread engineThread
           
private  int increment
           
private  BufferedReader input
           
private  long lastUpdateTime
          System time at last update
private  Vector<String> messageStack
           
private  int movesToGo
           
private  PrintWriter output
           
private  boolean running
          Flag for shutting down the engine
private  int wtime
           
private  int wtimeUsed
           
 
Fields inherited from class klaus.engine.Engine
debuggingListeners, moveListeners, party
 
Constructor Summary
UCIEngine(String commandLine)
          Create and start a new UCI engine.
 
Method Summary
 void addMove(Move m)
           
 void cancel()
           
 void forceMove()
           
private  void handle(String message)
          Handle an engine command
private  void lockEngine()
           
 void run()
           
 void sendMessage(String message, boolean force)
          Send a string to the engine.
 void setTimeModel(int timeInMinutes, int moves, int increment)
          Set the time model, equivalent to XBoards "level" command.
 void startCalculation()
           
 void unload()
           
private  void unlockEngine()
           
private  void updateTime()
          Updates clocks, needs to be called exactly once a second.
 
Methods inherited from class klaus.engine.Engine
addDebuggingListener, addMoveListener, clearDebuggingListeners, fireDebuggingListeners, fireMoveListeners, removeAllMoveListeners, removeDebuggingListener, removeMoveListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connection

private Process connection

input

private BufferedReader input

output

private PrintWriter output

engineThread

private Thread engineThread

running

private boolean running
Flag for shutting down the engine


blocked

private boolean blocked
Check if anything can be sent to the engine


wtime

private int wtime

btime

private int btime

wtimeUsed

private int wtimeUsed

bTimeUsed

private int bTimeUsed

increment

private int increment

movesToGo

private int movesToGo

messageStack

private Vector<String> messageStack

lastUpdateTime

private long lastUpdateTime
System time at last update

Constructor Detail

UCIEngine

public UCIEngine(String commandLine)
          throws IOException

Create and start a new UCI engine. This method is almost the same as in WinBoardXBoardEngine since actually both are started the same way.

Still, there are some differences: Unlike XBoard engines, UCI engines require some initialization stuff, this is done in the run() method.

Parameters:
commandLine - the command line (consisting of an executable's path and (optionally) arguments passed to the engine). Note: If there are spaces or some special characters in the path, "" will be required.
Throws:
IOException - if the engine could not be started correctly for some reason (file not found, crash during startup)
Method Detail

addMove

public void addMove(Move m)
Overrides:
addMove in class Engine

startCalculation

public void startCalculation()
Specified by:
startCalculation in class Engine

cancel

public void cancel()
Specified by:
cancel in class Engine

unload

public void unload()
Specified by:
unload in class Engine

forceMove

public void forceMove()
Specified by:
forceMove in class Engine

setTimeModel

public void setTimeModel(int timeInMinutes,
                         int moves,
                         int increment)
Description copied from class: Engine

Set the time model, equivalent to XBoards "level" command.

This method should be called in two situations:

Specified by:
setTimeModel in class Engine
Parameters:
timeInMinutes - the time for this period
moves - the number of moves to the next period
increment - the increment per move (Fischer clock) (in seconds)

updateTime

private void updateTime()
Updates clocks, needs to be called exactly once a second.


sendMessage

public void sendMessage(String message,
                        boolean force)
Send a string to the engine.

Parameters:
message - the message, command, whatsoever
force - force sending the message if blocked is true? This should only be set to true by run()!

lockEngine

private void lockEngine()

unlockEngine

private void unlockEngine()

handle

private void handle(String message)
Handle an engine command

Parameters:
message - a string sent by the engine

run

public void run()
Specified by:
run in interface Runnable