[jgogears commit] r44 - trunk/jgogears/jgogears

0 views
Skip to first unread message

codesite...@google.com

unread,
Feb 26, 2008, 7:44:06 PM2/26/08
to jgog...@googlegroups.com
Author: syeates
Date: Tue Feb 26 16:43:25 2008
New Revision: 44

Modified:
trunk/jgogears/jgogears/GTPParserUtils.java
trunk/jgogears/jgogears/GTPParserUtilsTest.java
trunk/jgogears/jgogears/GnuGoEngine.java
trunk/jgogears/jgogears/GnuGoEngineTest2.java

Log:
GTP updates

Modified: trunk/jgogears/jgogears/GTPParserUtils.java
==============================================================================
--- trunk/jgogears/jgogears/GTPParserUtils.java (original)
+++ trunk/jgogears/jgogears/GTPParserUtils.java Tue Feb 26 16:43:25 2008
@@ -29,7 +29,7 @@
int i;
for (i = 1; (s.length() > i) && Character.isDigit(s.charAt(i)); i++)
;
- return new Error(s.substring(i));
+ return new GTPError(s.substring(i));
}
return null;
}
@@ -102,7 +102,6 @@
if (s.charAt(0) == '?') {
throw getError(s);
}
-
return s;
}


Modified: trunk/jgogears/jgogears/GTPParserUtilsTest.java
==============================================================================
--- trunk/jgogears/jgogears/GTPParserUtilsTest.java (original)
+++ trunk/jgogears/jgogears/GTPParserUtilsTest.java Tue Feb 26 16:43:25 2008
@@ -4,13 +4,13 @@

import junit.framework.TestCase;

-// TODO: Auto-generated Javadoc
+
/**
* The Class GTPParserUtilsTest.
*/
public class GTPParserUtilsTest extends TestCase {

- /** The DEBUG. */
+ /** Are we being verbose? */
boolean DEBUG = false;

/** The engine. */
@@ -48,6 +48,7 @@
assertNotNull(move);
BoardI board = this.engine.showBoard();
System.err.println("testLoadsgf:: the following board should have
moves on it:");
+ assertNotNull(board);
System.err.println(board);
this.engine.quit();
} catch (Throwable t) {
@@ -59,10 +60,9 @@

/**
* Test parse gnu go board.
+ * @throws IOException if the underlying engine can't be created or
communicated with
*/
- public void testParseGnuGoBoard() {
- this.testParseGnuGoBoard((short) 3);
- this.testParseGnuGoBoard((short) 5);
+ public void testParseGnuGoBoard() throws IOException {
this.testParseGnuGoBoard((short) 7);
this.testParseGnuGoBoard((short) 9);
this.testParseGnuGoBoard((short) 11);
@@ -80,7 +80,7 @@
*
* @param i the i
*/
- public void testParseGnuGoBoard(short i) {
+ public void testParseGnuGoBoard(short i) throws IOException {
try {
this.engine = new GnuGoEngine();
boolean result = this.engine.initialise();
@@ -88,13 +88,17 @@
result = this.engine.setBoardSize(i);
assertTrue(result);
this.engine.quit();
- } catch (IOException e) {
-
+ } catch (GTPError e) {
+ System.err.println("testParseGnuGoBoard(" + i + ") failed");
+ //System.err.println(e);
+ //e.printStackTrace();
+ fail();
}
}

/**
- * Test show board.
+ *
+ * This is currently failing because I don't have good code to parse
the ASCII board back into a BoardI
*/
public final void testShowBoard() {
try {

Modified: trunk/jgogears/jgogears/GnuGoEngine.java
==============================================================================
--- trunk/jgogears/jgogears/GnuGoEngine.java (original)
+++ trunk/jgogears/jgogears/GnuGoEngine.java Tue Feb 26 16:43:25 2008
@@ -36,7 +36,7 @@
private BufferedReader reader = null;

/** The errreader. */
- private BufferedReader errreader = null;
+ private BufferedReader errReader = null;

/** The process. */
private Process process = null;
@@ -78,8 +78,8 @@
*/
protected synchronized void check() {
try {
- while (this.errreader.ready()) {
- System.err.print("GnuGo Process Error:\"" +
this.errreader.readLine() + "\"");
+ while (this.errReader.ready()) {
+ System.err.print("GnuGo Process Error:\"" +
this.errReader.readLine() + "\"");
}
} catch (Throwable t) {
t.printStackTrace();
@@ -170,12 +170,12 @@
}

/**
- * Gets the errreader.
+ * Gets the Reader for the error stream
*
- * @return the errreader
+ * @return the errReader
*/
- public BufferedReader getErrreader() {
- return this.errreader;
+ public BufferedReader getErrReader() {
+ return this.errReader;
}

/* (non-Javadoc)
@@ -269,7 +269,7 @@
String command = executable + " " + this.args;
this.process = java.lang.Runtime.getRuntime().exec(command);
this.reader = new java.io.BufferedReader(new InputStreamReader(this.process.getInputStream()));
- this.errreader = new java.io.BufferedReader(new InputStreamReader(this.process.getErrorStream()));
+ this.errReader = new java.io.BufferedReader(new InputStreamReader(this.process.getErrorStream()));
this.writer = new OutputStreamWriter(this.process.getOutputStream());
this.initialised = true;

@@ -345,8 +345,8 @@
return false;
}

- /* (non-Javadoc)
- * @see jgogears.GTPInterfaceRaw#quit()
+ /**
+ * quit notifies the remote engine, flushes all buffers and sets
variables to null
*/
public synchronized boolean quit() {
if (this.initialised) {
@@ -360,8 +360,8 @@
this.initialised = false;
this.reader.close();
this.reader = null;
- this.errreader.close();
- this.errreader = null;
+ this.errReader.close();
+ this.errReader = null;
this.writer.close();
this.writer = null;
this.process.destroy();
@@ -386,7 +386,11 @@
String s = "";
String result = "";
try {
- Thread.sleep(SMALL_PAUSE);
+ try {
+ Thread.sleep(SMALL_PAUSE);
+ } catch (Throwable t) {
+ // do nothing
+ }
while ((s != null) && (s.compareTo("") == 0)) {
s = this.reader.readLine();
}
@@ -398,10 +402,15 @@
System.err.println("GnuGo Process Output:\"" + s + "\" ==> \"" +
result + "\"");

this.check();
- } catch (Throwable t) {
+ } catch (GTPError t) {
t.printStackTrace();
System.err.println(t);
+ throw t;
}
+ catch (IOException t) {
+ t.printStackTrace();
+ System.err.println(t);
+ }
return result;
}

@@ -457,19 +466,16 @@
System.err.println("clearBoard:" + s);
if (null == e)
return true;
- if (this.DEBUG)
- System.err.println("clearBoard:" + s);
- return false;
-
+ return false;
}

/**
- * Sets the errreader.
+ * Sets the errReader.
*
- * @param errreader the new errreader
+ * @param errReader the new errReader
*/
- public void setErrreader(BufferedReader errreader) {
- this.errreader = errreader;
+ public void setErrReader(BufferedReader errReader) {
+ this.errReader = errReader;
}

/* (non-Javadoc)

Modified: trunk/jgogears/jgogears/GnuGoEngineTest2.java
==============================================================================
--- trunk/jgogears/jgogears/GnuGoEngineTest2.java (original)
+++ trunk/jgogears/jgogears/GnuGoEngineTest2.java Tue Feb 26 16:43:25 2008
@@ -432,7 +432,7 @@
}

/**
- * Test show board.
+ * This is currently failing because I don't have good code to parse
the ASCII board back into a BoardI
*/
public final void testShowBoard() {
try {

Reply all
Reply to author
Forward
0 new messages