public final class GtpClient extends GtpClientBase
This class is final because it starts a thread in its constructor which might conflict with subclassing because the subclass constructor will be called after the thread is started.
Callbacks can be registered to monitor the input, output and error stream and to handle timeout and invalid responses.
Modifier and Type | Class and Description |
---|---|
static class |
GtpClient.ExecFailed
Exception thrown if executing a GTP engine failed.
|
static interface |
GtpClient.InvalidResponseCallback
Callback if an invalid response occured.
|
static interface |
GtpClient.IOCallback
Callback interface for logging or displaying the GTP stream.
|
static interface |
GtpClient.TimeoutCallback
Callback if a timeout occured.
|
m_name
Constructor and Description |
---|
GtpClient(java.io.InputStream in,
java.io.OutputStream out,
boolean log,
GtpClient.IOCallback callback)
Constructor for given input and output streams.
|
GtpClient(java.lang.String program,
java.io.File workingDirectory,
boolean log,
GtpClient.IOCallback callback)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the output stream to the program.
|
void |
destroyProcess()
Kill the Go program.
|
boolean |
getAnyCommandsResponded()
Did the engine ever send a valid response to a command?
|
java.lang.String |
getFullResponse()
Get full response including status and ID and last command.
|
java.lang.String |
getProgramCommand()
Get the command line that was used for invoking the Go program.
|
java.lang.String |
getResponse()
Get response to last command sent.
|
boolean |
isProgramDead()
Check if program is dead.
|
void |
queryName(long timeout,
GtpClient.TimeoutCallback timeoutCallback) |
java.lang.String |
send(java.lang.String command)
Send a command.
|
java.lang.String |
send(java.lang.String command,
long timeout,
GtpClient.TimeoutCallback timeoutCallback)
Send a command with timeout.
|
void |
sendComment(java.lang.String comment)
Send comment.
|
void |
sendPlay(Move move,
long timeout,
GtpClient.TimeoutCallback timeoutCallback) |
void |
setAutoNumber(boolean enable)
Enable auto-numbering commands.
|
void |
setInvalidResponseCallback(GtpClient.InvalidResponseCallback callback)
Set the callback for invalid responses.
|
void |
setIOCallback(GtpClient.IOCallback callback) |
void |
setLogPrefix(java.lang.String prefix)
Set a prefix for logging to standard error.
|
void |
waitForExit()
Wait until the process of the program exits.
|
void |
waitForExit(int timeout,
GtpClient.TimeoutCallback timeoutCallback)
More sophisticated version of waitFor with timeout.
|
boolean |
wasKilled()
Was program forcefully terminated by calling destroyProcess()
|
getCommandBoardsize, getCommandClearBoard, getCommandGenmove, getCommandPlay, getCpuTime, getLabel, getName, getProtocolVersion, getSupportedCommands, isCpuTimeSupported, isGenmoveSupported, isInterruptSupported, isSupported, queryInterruptSupport, queryName, queryProtocolVersion, querySupportedCommands, queryVersion, sendBoardsize, sendClearBoard, sendInterrupt, sendPlay, setLowerCase
public GtpClient(java.lang.String program, java.io.File workingDirectory, boolean log, GtpClient.IOCallback callback) throws GtpClient.ExecFailed
program
- Command line for program.
Will be split into words with respect to " as in StringUtil.tokenize.
If the command line contains the string "%SRAND", it will be replaced
by a random seed. This is useful if the random seed can be set by
a command line option to produce deterministic randomness (the
command returned by getProgramCommand() will contain the actual
random seed used).workingDirectory
- The working directory to run the program in or
null for the current directorylog
- Log input, output and error stream to standard error.callback
- Callback for external display of the streams.GtpClient.ExecFailed
public GtpClient(java.io.InputStream in, java.io.OutputStream out, boolean log, GtpClient.IOCallback callback) throws GtpError
GtpError
public void close()
close
in class GtpClientBase
public void destroyProcess()
public boolean getAnyCommandsResponded()
public java.lang.String getResponse()
public java.lang.String getFullResponse()
public java.lang.String getProgramCommand()
public boolean isProgramDead()
isProgramDead
in class GtpClientBase
public java.lang.String send(java.lang.String command) throws GtpError
send
in class GtpClientBase
GtpError
- containing the response if the command fails.public void queryName(long timeout, GtpClient.TimeoutCallback timeoutCallback) throws GtpError
GtpError
public java.lang.String send(java.lang.String command, long timeout, GtpClient.TimeoutCallback timeoutCallback) throws GtpError
command
- The command to sendtimeout
- Timeout in milliseconds or -1, if no timeouttimeoutCallback
- Timeout callback or null if no timeout.GtpError
- containing the response if the command fails.GtpClient.TimeoutCallback
public void sendPlay(Move move, long timeout, GtpClient.TimeoutCallback timeoutCallback) throws GtpError
GtpError
public void sendComment(java.lang.String comment)
sendComment
in class GtpClientBase
comment
- comment line (must start with '#').public void setAutoNumber(boolean enable)
public void setInvalidResponseCallback(GtpClient.InvalidResponseCallback callback)
GtpClient.InvalidResponseCallback
public void setIOCallback(GtpClient.IOCallback callback)
public void setLogPrefix(java.lang.String prefix)
public void waitForExit()
waitForExit
in class GtpClientBase
public void waitForExit(int timeout, GtpClient.TimeoutCallback timeoutCallback)
public boolean wasKilled()