Skip to content

Commit

Permalink
GoGuiAdapter: forward kgs-genmove_cleanup to the program if it suppor…
Browse files Browse the repository at this point in the history
…ts it
  • Loading branch information
enz committed Feb 9, 2010
1 parent 3eaf43b commit 01e2467
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
5 changes: 5 additions & 0 deletions doc/manual/xml/news.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ exists
</listitem>
<listitem>
<simpara>
GoGuiAdapter: forward kgs-genmove_cleanup to the program if it supports it
</simpara>
</listitem>
<listitem>
<simpara>
Small fixes
</simpara>
</listitem>
Expand Down
53 changes: 32 additions & 21 deletions src/net/sf/gogui/tools/adapter/Adapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,36 +121,24 @@ public void cmdForward(GtpCommand cmd) throws GtpError

public void cmdGenmove(GtpCommand cmd) throws GtpError
{
cmdGenmove(cmd.getColorArg(), cmd);
GoColor c = cmd.getColorArg();
cmdGenmove(c, cmd, m_gtp.getCommandGenmove(c));
}

public void cmdGenmoveBlack(GtpCommand cmd) throws GtpError
public void cmdGenmoveCleanup(GtpCommand cmd) throws GtpError
{
cmdGenmove(BLACK, cmd);
GoColor c = cmd.getColorArg();
cmdGenmove(c, cmd, "kgs-genmove_cleanup " + c.getUppercaseLetter());
}

public void cmdGenmoveWhite(GtpCommand cmd) throws GtpError
public void cmdGenmoveBlack(GtpCommand cmd) throws GtpError
{
cmdGenmove(WHITE, cmd);
cmdGenmove(BLACK, cmd, m_gtp.getCommandGenmove(BLACK));
}

public void cmdGenmove(GoColor color, GtpCommand cmd) throws GtpError
public void cmdGenmoveWhite(GtpCommand cmd) throws GtpError
{
String command = m_gtp.getCommandGenmove(color);
String response = send(command);
if (response.toLowerCase(Locale.ENGLISH).trim().equals("resign"))
return;
try
{
GoPoint point = GtpUtil.parsePoint(response, m_board.getSize());
m_board.play(color, point);
m_synchronizer.updateAfterGenmove(m_board);
cmd.setResponse(response);
}
catch (GtpResponseFormatError e)
{
throw new GtpError(e.getMessage());
}
cmdGenmove(WHITE, cmd, m_gtp.getCommandGenmove(WHITE));
}

public void cmdGGUndo(GtpCommand cmd) throws GtpError
Expand Down Expand Up @@ -363,6 +351,25 @@ public void run(GtpCommand cmd) throws GtpError {

private TimeSettings m_timeSettings;

private void cmdGenmove(GoColor color, GtpCommand cmd, String command)
throws GtpError
{
String response = send(command);
if (response.toLowerCase(Locale.ENGLISH).trim().equals("resign"))
return;
try
{
GoPoint point = GtpUtil.parsePoint(response, m_board.getSize());
m_board.play(color, point);
m_synchronizer.updateAfterGenmove(m_board);
cmd.setResponse(response);
}
catch (GtpResponseFormatError e)
{
throw new GtpError(e.getMessage());
}
}

private GoPoint getPointArg(GtpCommand cmd, int i) throws GtpError
{
return cmd.getPointArg(i, m_board.getSize());
Expand Down Expand Up @@ -394,6 +401,10 @@ private void registerCommands(boolean noScore, boolean version1)
if (! GtpUtil.isStateChangingCommand(command))
register(command, m_callbackForward);
}
if (m_gtp.isSupported("kgs-genmove_cleanup"))
register("kgs-genmove_cleanup", new GtpCallback() {
public void run(GtpCommand cmd) throws GtpError {
cmdGenmoveCleanup(cmd); } });
register("boardsize", new GtpCallback() {
public void run(GtpCommand cmd) throws GtpError {
cmdBoardsize(cmd); } });
Expand Down

0 comments on commit 01e2467

Please sign in to comment.