Added:
trunk/jgogears/jgogears/GameTest.java
Modified:
trunk/jgogears/doc/TODO
trunk/jgogears/jgogears/BoardI.java
trunk/jgogears/jgogears/GTPParserUtilsTest.java
trunk/jgogears/jgogears/Game.java
trunk/jgogears/jgogears/GnuGoEngineTest2.java
trunk/jgogears/jgogears/KoRuleSet.java
trunk/jgogears/jgogears/Move.java
trunk/jgogears/jgogears/NoKoRuleSet.java
trunk/jgogears/jgogears/NoKoRuleSetTest.java
trunk/jgogears/jgogears/Random.java
trunk/jgogears/jgogears/RandomEngine.java
trunk/jgogears/jgogears/RandomTest.java
trunk/jgogears/jgogears/SGFGameTree.java
trunk/jgogears/jgogears/SmallerBoardTest.java
trunk/jgogears/jgogears/Zobrist.java
trunk/jgogears/jgogears/ZobristTest.java
trunk/jgogears/jgogears/engine/Engine.java
trunk/jgogears/jgogears/engine/Model.java
trunk/jgogears/jgogears/engine/ModelTest.java
trunk/jgogears/jgogears/engine/Scorer.java
trunk/jgogears/jgogears/engine/StraightVertexLineariserTest.java
trunk/jgogears/jgogears/engine/Trainer.java
trunk/jgogears/jgogears/engine/VertexLineariser.java
trunk/jgogears/jgogears/engine/VertexLineariserTest.java
Log:
only train on winning moves. GameTest. formatting. make tests less verbose
Modified: trunk/jgogears/doc/TODO
==============================================================================
--- trunk/jgogears/doc/TODO (original)
+++ trunk/jgogears/doc/TODO Tue Mar 25 21:19:55 2008
@@ -8,7 +8,6 @@
* update javacc generated files in svn (eclipse javacc plugin is
preventing this happening via eclipse)
* commandline program to play jgogears against gnugo
* commandline program to guess moves from real games
-* change training to only train on winning moves rather than all moves
* decided whether to dual licence under the Apache 2 license
* find a decent training corpus
@@ -49,4 +48,5 @@
* better tests of the Board implementations
* jgogears.engine.Engine now up and running
* make moves a little more random. They're meant to be random at the
moment, but apparently aren't...
+* change training to only train on winning moves rather than all moves
Modified: trunk/jgogears/jgogears/BoardI.java
==============================================================================
--- trunk/jgogears/jgogears/BoardI.java (original)
+++ trunk/jgogears/jgogears/BoardI.java Tue Mar 25 21:19:55 2008
@@ -425,8 +425,8 @@
public String toString() {
return BoardToASCII.Transform(this);
}
-
- public boolean isOffBoard(int row, int column){
+
+ public boolean isOffBoard(int row, int column) {
if (row < 0)
return true;
if (column < 0)
@@ -437,14 +437,15 @@
return true;
return false;
}
- public boolean isWayOffBoard(int row, int column){
+
+ public boolean isWayOffBoard(int row, int column) {
if (row < -1)
return true;
if (column < -1)
return true;
- if (row >= this.getSize()+1)
+ if (row >= this.getSize() + 1)
return true;
- if (column >= this.getSize()+1)
+ if (column >= this.getSize() + 1)
return true;
return false;
}
Modified: trunk/jgogears/jgogears/GTPParserUtilsTest.java
==============================================================================
--- trunk/jgogears/jgogears/GTPParserUtilsTest.java (original)
+++ trunk/jgogears/jgogears/GTPParserUtilsTest.java Tue Mar 25 21:19:55 2008
@@ -11,7 +11,7 @@
public class GTPParserUtilsTest extends TestCase {
/** Are we being verbose?. */
- boolean DEBUG = false;
+ final static public boolean DEBUG = false;
/** The engine. */
GnuGoEngine engine = null;
@@ -56,7 +56,8 @@
// System.err.println(board);
this.engine.quit();
} catch (Throwable t) {
- System.err.println(t);
+ if (DEBUG)
+ System.err.println(t);
t.printStackTrace();
fail();
}
@@ -95,9 +96,12 @@
assertTrue(result);
this.engine.quit();
} catch (GTPError e) {
- System.err.println("testParseGnuGoBoard(" + i + ") failed");
- // System.err.println(e);
- // e.printStackTrace();
+ if (DEBUG)
+ System.err.println("testParseGnuGoBoard(" + i + ") failed");
+ if (DEBUG)
+ System.err.println(e);
+ if (DEBUG)
+ e.printStackTrace();
fail();
}
}
@@ -113,8 +117,10 @@
// TODO actually test the generated board here...
this.engine.quit();
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG)
+ System.err.println(t);
+ if (DEBUG)
+ t.printStackTrace();
fail();
}
}
Modified: trunk/jgogears/jgogears/Game.java
==============================================================================
--- trunk/jgogears/jgogears/Game.java (original)
+++ trunk/jgogears/jgogears/Game.java Tue Mar 25 21:19:55 2008
@@ -129,6 +129,24 @@
// "\" e=\"" + this.extraTime +"\" PC=\"" + this.PC +"\"");
}
+ public boolean getBlackWin() {
+ if (score != null && score.getBlackWin())
+ return true;
+ return false;
+ }
+
+ public boolean getWhiteWin() {
+ if (score != null && score.getWhiteWin())
+ return true;
+ return false;
+ }
+
+ public boolean getNeitherWin() {
+ if (score == null || score.getDraw() || score.getVoid())
+ return true;
+ return false;
+ }
+
/**
* get the blackPlayer.
*
Added: trunk/jgogears/jgogears/GameTest.java
==============================================================================
--- (empty file)
+++ trunk/jgogears/jgogears/GameTest.java Tue Mar 25 21:19:55 2008
@@ -0,0 +1,59 @@
+/**
+ *
+ */
+package jgogears;
+
+import java.io.*;
+import java.util.*;
+
+import junit.framework.TestCase;
+
+/**
+ * TODO
+ *
+ * @author syeates
+ */
+public class GameTest extends TestCase {
+ /** are we being verbose ? */
+ static final private boolean DEBUG = true;
+
+ public void testOneSGFFile() throws Exception {
+
+ Collection<String> filenames = jgogears.engine.Trainer.loadAllSGFfiles();
+ assertNotNull(filenames);
+ String filename = filenames.iterator().next();
+ assertNotNull(filename);
+ Game game = Game.loadFromFilename(filename);
+ GTPScore score = game.getScore();
+ if (score.getBlackWin())
+
+ System.err.println(score + " black win");
+ else if (score.getWhiteWin())
+ System.err.println(score + " black win");
+ else
+ System.err.println(score + " neither win");
+ }
+
+ public void testManySGFFile() throws Exception {
+
+ Collection<String> filenames = jgogears.engine.Trainer.loadAllSGFfiles();
+ assertNotNull(filenames);
+ Iterator<String> iterator = filenames.iterator();
+ while (iterator.hasNext()) {
+ String filename = iterator.next();
+ assertNotNull(filename);
+ Game game = Game.loadFromFilename(filename);
+ assertNotNull(game);
+ GTPScore score = game.getScore();
+ if (score == null)
+ System.err.println("null unknown score");
+ else if (score.getBlackWin())
+ System.err.println(score + " black win");
+ else if (score.getWhiteWin())
+ System.err.println(score + " white win");
+ else
+ System.err.println(score + " neither win");
+ }
+ }
+
+}
Modified: trunk/jgogears/jgogears/GnuGoEngineTest2.java
==============================================================================
--- trunk/jgogears/jgogears/GnuGoEngineTest2.java (original)
+++ trunk/jgogears/jgogears/GnuGoEngineTest2.java Tue Mar 25 21:19:55 2008
@@ -14,7 +14,7 @@
public class GnuGoEngineTest2 extends TestCase {
/** The DEBUG. */
- boolean DEBUG = false;
+ final static private boolean DEBUG = false;
/** The engine. */
GnuGoEngine engine = null;
@@ -82,8 +82,10 @@
assertNotNull(seki);
engine.quit();
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG)
+ System.err.println(t);
+ if (DEBUG)
+ t.printStackTrace();
fail();
}
}
@@ -102,8 +104,10 @@
}
this.engine.quit();
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG)
+ System.err.println(t);
+ if (DEBUG)
+ t.printStackTrace();
fail();
}
}
@@ -121,8 +125,10 @@
System.err.println(move);
this.engine.quit();
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG)
+ System.err.println(t);
+ if (DEBUG)
+ t.printStackTrace();
fail();
}
@@ -139,8 +145,10 @@
System.err.println(s);
this.engine.quit();
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG) {
+ System.err.println(t);
+ t.printStackTrace();
+ }
fail();
}
}
@@ -152,11 +160,14 @@
try {
this.engine.initialise();
String s = this.engine.getEngineVersion();
- System.err.println(s);
+ if (DEBUG)
+ System.err.println(s);
this.engine.quit();
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG)
+ System.err.println(t);
+ if (DEBUG)
+ t.printStackTrace();
fail();
}
}
@@ -176,8 +187,10 @@
this.engine.quit();
// TODO
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG)
+ System.err.println(t);
+ if (DEBUG)
+ t.printStackTrace();
fail();
}
}
@@ -192,8 +205,10 @@
this.engine.quit();
// TODO
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG)
+ System.err.println(t);
+ if (DEBUG)
+ t.printStackTrace();
fail();
}
}
@@ -208,8 +223,10 @@
this.engine.quit();
// TODO
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG)
+ System.err.println(t);
+ if (DEBUG)
+ t.printStackTrace();
fail();
}
@@ -227,8 +244,10 @@
this.engine.quit();
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG)
+ System.err.println(t);
+ if (DEBUG)
+ t.printStackTrace();
fail();
}
}
@@ -244,13 +263,17 @@
Move move = this.engine.genMove(BoardI.VERTEX_BLACK);
assertNotNull(move);
BoardI board = this.engine.showBoard();
- System.err.println("testLoadsgf:: the following board should have
moves on it:");
- System.err.println(board);
+ if (DEBUG)
+ System.err.println("testLoadsgf:: the following board should have
moves on it:");
+ if (DEBUG)
+ System.err.println(board);
this.engine.quit();
// TODO
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG)
+ System.err.println(t);
+ if (DEBUG)
+ t.printStackTrace();
fail();
}
}
@@ -265,8 +288,10 @@
this.engine.quit();
// TODO
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG)
+ System.err.println(t);
+ if (DEBUG)
+ t.printStackTrace();
fail();
}
}
@@ -284,8 +309,10 @@
assertTrue(moves.size() == 9);
this.engine.quit();
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG)
+ System.err.println(t);
+ if (DEBUG)
+ t.printStackTrace();
fail();
}
}
@@ -321,8 +348,10 @@
this.engine.quit();
}
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG)
+ System.err.println(t);
+ if (DEBUG)
+ t.printStackTrace();
fail();
}
}
@@ -338,8 +367,10 @@
this.engine.play(new Move("white c3"));
this.engine.quit();
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG)
+ System.err.println(t);
+ if (DEBUG)
+ t.printStackTrace();
fail();
}
}
@@ -352,8 +383,10 @@
this.engine.initialise();
this.engine.quit();
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG)
+ System.err.println(t);
+ if (DEBUG)
+ t.printStackTrace();
fail();
}
}
@@ -365,11 +398,14 @@
try {
this.engine.initialise();
Move move = this.engine.regGenMove(BoardI.VERTEX_BLACK);
- System.err.println(move);
+ if (DEBUG)
+ System.err.println(move);
this.engine.quit();
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG)
+ System.err.println(t);
+ if (DEBUG)
+ t.printStackTrace();
fail();
}
}
@@ -386,8 +422,10 @@
assertTrue(result);
this.engine.quit();
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG)
+ System.err.println(t);
+ if (DEBUG)
+ t.printStackTrace();
fail();
}
}
@@ -401,8 +439,10 @@
this.engine.setKomi(7.0);
this.engine.quit();
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG)
+ System.err.println(t);
+ if (DEBUG)
+ t.printStackTrace();
fail();
}
}
@@ -416,8 +456,10 @@
this.engine.setTimeLeft(BoardI.VERTEX_BLACK, 1.0, 1.0);
this.engine.quit();
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG)
+ System.err.println(t);
+ if (DEBUG)
+ t.printStackTrace();
fail();
}
}
@@ -431,8 +473,10 @@
this.engine.setTimeSettings(1.0, 1.0, 1.0);
this.engine.quit();
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG)
+ System.err.println(t);
+ if (DEBUG)
+ t.printStackTrace();
fail();
}
}
@@ -448,8 +492,10 @@
// TODO
this.engine.quit();
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG)
+ System.err.println(t);
+ if (DEBUG)
+ t.printStackTrace();
fail();
}
}
@@ -464,10 +510,12 @@
assertFalse(result);
this.engine.quit();
} catch (Throwable t) {
- System.err.println(t);
- t.printStackTrace();
+ if (DEBUG)
+ System.err.println(t);
+ if (DEBUG)
+ t.printStackTrace();
// TODO
- // fail(t.toString());
+ fail(t.toString());
}
}
Modified: trunk/jgogears/jgogears/KoRuleSet.java
==============================================================================
--- trunk/jgogears/jgogears/KoRuleSet.java (original)
+++ trunk/jgogears/jgogears/KoRuleSet.java Tue Mar 25 21:19:55 2008
@@ -5,21 +5,25 @@
/**
* TODO
+ *
* @author syeates
- *
*/
public class KoRuleSet extends NoKoRuleSet {
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.NoKoRuleSet#getDescription()
*/
@Override
public String getDescription() {
// TODO Auto-generated method stub
-throw new Error();
+ throw new Error();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.NoKoRuleSet#getName()
*/
@Override
@@ -29,7 +33,9 @@
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.NoKoRuleSet#moveIsLegal(jgogears.Game,
jgogears.BoardI, jgogears.Move)
*/
@Override
Modified: trunk/jgogears/jgogears/Move.java
==============================================================================
--- trunk/jgogears/jgogears/Move.java (original)
+++ trunk/jgogears/jgogears/Move.java Tue Mar 25 21:19:55 2008
@@ -305,7 +305,7 @@
rowS = "z";
break;
default:
- throw new java.lang.InternalError("bad row="+s);
+ throw new java.lang.InternalError("bad row=" + s);
}
return rowS;
}
Modified: trunk/jgogears/jgogears/NoKoRuleSet.java
==============================================================================
--- trunk/jgogears/jgogears/NoKoRuleSet.java (original)
+++ trunk/jgogears/jgogears/NoKoRuleSet.java Tue Mar 25 21:19:55 2008
@@ -277,7 +277,7 @@
short row = move.getRow();
short column = move.getColumn();
short colour = move.getColour();
-
+
if (board.getColour(row, column) != BoardI.VERTEX_EMPTY) {
if (DEBUG)
System.err.println("illegal move, not empty");
Modified: trunk/jgogears/jgogears/NoKoRuleSetTest.java
==============================================================================
--- trunk/jgogears/jgogears/NoKoRuleSetTest.java (original)
+++ trunk/jgogears/jgogears/NoKoRuleSetTest.java Tue Mar 25 21:19:55 2008
@@ -647,7 +647,8 @@
Game game = Game.loadFromFile(file);
if (game.getSize() == 19) {
BoardI board = BoardI.newBoard(game.getSize());
- System.err.println(filename);
+ if (DEBUG)
+ System.err.println(filename);
Iterator<Move> i = game.getMovelist().iterator();
while (i.hasNext()) {
Modified: trunk/jgogears/jgogears/Random.java
==============================================================================
--- trunk/jgogears/jgogears/Random.java (original)
+++ trunk/jgogears/jgogears/Random.java Tue Mar 25 21:19:55 2008
@@ -3,11 +3,10 @@
*/
package jgogears;
-
/**
* A random number generator
+ *
* @author syeates
- *
*/
public class Random {
/** The random number generator */
@@ -16,31 +15,34 @@
public static final double DELTA = (double) 0.01;
/**
- *
* get the next double
+ *
* @return the next double
*/
static public final double nextDouble() {
double r = random.nextDouble();
return r;
}
+
/**
- *
* get the next boolean
+ *
* @return the next boolean
*/
static public final boolean nextBoolean() {
- boolean r = random.nextBoolean();
+ boolean r = random.nextBoolean();
return r;
}
+
/**
- *
* get the next integer
- * @param max the maximum integer
+ *
+ * @param max
+ * the maximum integer
* @return the next integer
*/
static public final int nextInt(int max) {
- int r = random.nextInt(max);
+ int r = random.nextInt(max);
return r;
}
@@ -53,33 +55,39 @@
double r = random.nextDouble();
return r * DELTA;
}
+
/**
* a randomised max function
- * @param first the first double
- * @param second the second double
+ *
+ * @param first
+ * the first double
+ * @param second
+ * the second double
* @return the largest or a random value if equal
*/
- static public final double getRandomBest(double first,double second){
+ static public final double getRandomBest(double first, double second) {
if (first > second)
return first;
if (second > first)
return second;
return first;
}
+
/**
* a randomised max function
- * @param first the first double
- * @param second the second double
+ *
+ * @param first
+ * the first double
+ * @param second
+ * the second double
* @return the largest or a random value if equal
*/
- static public final boolean isLarger(double first,double second){
+ static public final boolean isLarger(double first, double second) {
if (first > second)
return true;
if (second > first)
return false;
return nextBoolean();
}
-
-
}
Modified: trunk/jgogears/jgogears/RandomEngine.java
==============================================================================
--- trunk/jgogears/jgogears/RandomEngine.java (original)
+++ trunk/jgogears/jgogears/RandomEngine.java Tue Mar 25 21:19:55 2008
@@ -8,7 +8,6 @@
*/
public class RandomEngine extends SkeletonEngine implements
GTPInterface {
-
/*
* (non-Javadoc)
*
Modified: trunk/jgogears/jgogears/RandomTest.java
==============================================================================
--- trunk/jgogears/jgogears/RandomTest.java (original)
+++ trunk/jgogears/jgogears/RandomTest.java Tue Mar 25 21:19:55 2008
@@ -7,28 +7,28 @@
/**
* TODO
+ *
* @author syeates
- *
*/
public class RandomTest extends TestCase {
- public void testisLarger(){
- assertTrue(Random.isLarger(9.0,1.0));
- assertTrue(Random.isLarger(1.1,1.0));
- assertTrue(Random.isLarger(1.2,1.0));
- assertTrue(Random.isLarger(0.2,0.0));
- assertTrue(Random.isLarger(0.2,0.1));
-
- assertFalse(Random.isLarger(1.0,9.0));
- assertFalse(Random.isLarger(1.0,1.1));
- assertFalse(Random.isLarger(1.0,1.2));
- assertFalse(Random.isLarger(0.0,0.2));
- assertFalse(Random.isLarger(0.1,0.2));
-
- while(Random.isLarger(0.1,0.1))
- ;
- while(!Random.isLarger(0.1,0.1))
- ;
-
+ public void testisLarger() {
+ assertTrue(Random.isLarger(9.0, 1.0));
+ assertTrue(Random.isLarger(1.1, 1.0));
+ assertTrue(Random.isLarger(1.2, 1.0));
+ assertTrue(Random.isLarger(0.2, 0.0));
+ assertTrue(Random.isLarger(0.2, 0.1));
+
+ assertFalse(Random.isLarger(1.0, 9.0));
+ assertFalse(Random.isLarger(1.0, 1.1));
+ assertFalse(Random.isLarger(1.0, 1.2));
+ assertFalse(Random.isLarger(0.0, 0.2));
+ assertFalse(Random.isLarger(0.1, 0.2));
+
+ while (Random.isLarger(0.1, 0.1))
+ ;
+ while (!Random.isLarger(0.1, 0.1))
+ ;
+
}
}
Modified: trunk/jgogears/jgogears/SGFGameTree.java
==============================================================================
--- trunk/jgogears/jgogears/SGFGameTree.java (original)
+++ trunk/jgogears/jgogears/SGFGameTree.java Tue Mar 25 21:19:55 2008
@@ -38,8 +38,8 @@
e.printStackTrace();
} finally {
try {
- if (reader != null)
- reader.close();
+ if (reader != null)
+ reader.close();
} catch (IOException e) {
System.err.println(e);
e.printStackTrace();
Modified: trunk/jgogears/jgogears/SmallerBoardTest.java
==============================================================================
--- trunk/jgogears/jgogears/SmallerBoardTest.java (original)
+++ trunk/jgogears/jgogears/SmallerBoardTest.java Tue Mar 25 21:19:55 2008
@@ -10,6 +10,8 @@
* The Class SmallerBoardTest.
*/
public class SmallerBoardTest extends TestCase {
+ /** Are we using verbose debugging?. */
+ public static final boolean DEBUG = false;
/**
* Test all sizes.
@@ -131,7 +133,8 @@
String filename = files.pop();
File file = new File(filename);
count++;
- System.err.println("examining \"" + filename + "\"");
+ if (DEBUG)
+ System.err.println("examining \"" + filename + "\"");
if (file.exists()) {
if (!file.isDirectory()) {
// System.err.println("\"" + filename + "\" is not a
@@ -158,7 +161,8 @@
}
} else {
- System.err.println("\"" + filename + "\" is a directory");
+ if (DEBUG)
+ System.err.println("\"" + filename + "\" is a directory");
if (!file.getName().contains(".svn")) {
String[] children = file.list();
for (int i = 0; i < children.length; i++) {
@@ -200,7 +204,8 @@
BoardI working = new SmallerBoard((short) 19);
assertNotNull(working);
working = working.newBoard(new Move("B q10"));
- System.out.println(working);
+ if (DEBUG)
+ System.out.println(working);
}
/**
Modified: trunk/jgogears/jgogears/Zobrist.java
==============================================================================
--- trunk/jgogears/jgogears/Zobrist.java (original)
+++ trunk/jgogears/jgogears/Zobrist.java Tue Mar 25 21:19:55 2008
@@ -29,7 +29,7 @@
static private void init() {
if (grid == null) {
grid = new BitSet[MAX_BOARD_SIZE][MAX_BOARD_SIZE][MAX_COLOUR];
-
+
for (int i = 0; i < MAX_BOARD_SIZE; i++)
for (int j = 0; j < MAX_BOARD_SIZE; j++)
for (int k = 0; k < MAX_COLOUR; k++) {
Modified: trunk/jgogears/jgogears/ZobristTest.java
==============================================================================
--- trunk/jgogears/jgogears/ZobristTest.java (original)
+++ trunk/jgogears/jgogears/ZobristTest.java Tue Mar 25 21:19:55 2008
@@ -10,6 +10,8 @@
*/
public class ZobristTest extends TestCase {
+ /** Are we using verbose debugging?. */
+ public static final boolean DEBUG = false;
/**
* Check that all of the hashes are different.
@@ -49,10 +51,12 @@
assertNotNull(z3);
assertNotNull(z4);
assertNotNull(z5);
- System.err.println(z);
- System.err.println(z3);
- System.err.println(z2);
- System.err.println(zz);
+ if (DEBUG) {
+ System.err.println(z);
+ System.err.println(z3);
+ System.err.println(z2);
+ System.err.println(zz);
+ }
assertTrue(z2.equals(zz));
assertFalse(z2.equals(z));
assertFalse(z4.equals(z));
@@ -82,9 +86,11 @@
assertNotNull(z);
assertNotNull(z2);
- System.err.println(z);
- System.err.println(z2);
- System.err.println(z3);
+ if (DEBUG) {
+ System.err.println(z);
+ System.err.println(z2);
+ System.err.println(z3);
+ }
assertFalse(z2.equals(z));
assertTrue(z2.equals(z3));
@@ -179,9 +185,10 @@
BoardI board6 = board.newBoard(new Move((short) 2, (short) 2, BoardI.VERTEX_BLACK));
BoardI board7 = board6.newBoard(new Move((short) 1, (short) 1, BoardI.VERTEX_WHITE));
- System.err.println(board5.getZobrist());
- System.err.println(board7.getZobrist());
-
+ if (DEBUG) {
+ System.err.println(board5.getZobrist());
+ System.err.println(board7.getZobrist());
+ }
assertTrue(board5.getZobrist().equals(board7.getZobrist()));
BoardI board8 = board.newBoard(new Move((short) 1, (short) 1, BoardI.VERTEX_WHITE));
@@ -223,9 +230,11 @@
BoardI board = new SmallBoard(true);
BoardI board2 = board.newBoard(new Move((short) 1, (short) 1, BoardI.VERTEX_BLACK));
BoardI board3 = board.newBoard(new Move((short) 1, (short) 1, BoardI.VERTEX_BLACK));
- System.err.println(board.getZobrist());
- System.err.println(board2.getZobrist());
- System.err.println(board3.getZobrist());
+ if (DEBUG) {
+ System.err.println(board.getZobrist());
+ System.err.println(board2.getZobrist());
+ System.err.println(board3.getZobrist());
+ }
assertTrue(board2.getZobrist().equals(board3.getZobrist()));
assertTrue(board3.getZobrist().equals(board2.getZobrist()));
assertFalse(board.getZobrist().equals(board2.getZobrist()));
Modified: trunk/jgogears/jgogears/engine/Engine.java
==============================================================================
--- trunk/jgogears/jgogears/engine/Engine.java (original)
+++ trunk/jgogears/jgogears/engine/Engine.java Tue Mar 25 21:19:55 2008
@@ -28,7 +28,7 @@
Trainer trainer = new Trainer();
trainer.setModel(model);
- //trainer.train(200);
+ // trainer.train(200);
trainer.train();
System.out.println("model trained");
System.out.println(model.getRoot());
Modified: trunk/jgogears/jgogears/engine/Model.java
==============================================================================
--- trunk/jgogears/jgogears/engine/Model.java (original)
+++ trunk/jgogears/jgogears/engine/Model.java Tue Mar 25 21:19:55 2008
@@ -2,13 +2,11 @@
import java.util.*;
-
/**
* A probability model of Go
*/
public final class Model {
-
/** are we being verbose? */
public static boolean DEBUG = false;
@@ -113,6 +111,7 @@
public final void setGamesTrained(int gamesTrained) {
this.gamesTrained = gamesTrained;
}
+
/**
* get the size of the model
*
Modified: trunk/jgogears/jgogears/engine/ModelTest.java
==============================================================================
--- trunk/jgogears/jgogears/engine/ModelTest.java (original)
+++ trunk/jgogears/jgogears/engine/ModelTest.java Tue Mar 25 21:19:55 2008
@@ -17,9 +17,9 @@
/** The model. */
static Model model = null;
-
- boolean compare(double first,double second){
- return ((float)first) == ((float)second);
+
+ boolean compare(double first, double second) {
+ return ((float) first) == ((float) second);
}
/**
@@ -135,12 +135,12 @@
for (int i = 0; i < r.length; i++)
for (int j = 0; j < r[i].length; j++) {
assertTrue(i + " " + j + " " + r[i][j] + " " + r[j][i], r[i][j] == r[j][i]);
- assertTrue(i + " " + j + " " + r[i][j] + " " + r[r.length - i -
1][r.length - j - 1],
- this.compare(r[i][j] , r[r.length - i - 1][r.length - j - 1]));
- assertTrue(i + " " + j + " " + r[i][j] + " " + r[r.length - i - 1][j],
- this.compare(r[i][j] , r[r.length - i - 1][j]));
- assertTrue(i + " " + j + " " + r[i][j] + " " + r[i][r.length - j - 1],
- this.compare(r[i][j] , r[i][r.length - j - 1]));
+ assertTrue(i + " " + j + " " + r[i][j] + " " + r[r.length - i -
1][r.length - j - 1], this.compare(
+ r[i][j], r[r.length - i - 1][r.length - j - 1]));
+ assertTrue(i + " " + j + " " + r[i][j] + " " + r[r.length - i -
1][j], this.compare(r[i][j], r[r.length
+ - i - 1][j]));
+ assertTrue(i + " " + j + " " + r[i][j] + " " + r[i][r.length - j -
1], this.compare(r[i][j],
+ r[i][r.length - j - 1]));
}
}
@@ -272,12 +272,12 @@
for (int i = 0; i < r.length; i++)
for (int j = 0; j < r[i].length; j++) {
assertTrue(i + " " + j + " " + r[i][j] + " " + r[j][i], r[i][j] == r[j][i]);
- assertTrue(i + " " + j + " " + r[i][j] + " " + r[r.length - i -
1][r.length - j - 1],
- this.compare(r[i][j], r[r.length - i - 1][r.length - j - 1]));
- assertTrue(i + " " + j + " " + r[i][j] + " " + r[r.length - i - 1][j],
- this.compare(r[i][j] , r[r.length - i - 1][j]));
- assertTrue(i + " " + j + " " + r[i][j] + " " + r[i][r.length - j - 1],
- this.compare(r[i][j] , r[i][r.length - j - 1]));
+ assertTrue(i + " " + j + " " + r[i][j] + " " + r[r.length - i -
1][r.length - j - 1], this.compare(
+ r[i][j], r[r.length - i - 1][r.length - j - 1]));
+ assertTrue(i + " " + j + " " + r[i][j] + " " + r[r.length - i -
1][j], this.compare(r[i][j], r[r.length
+ - i - 1][j]));
+ assertTrue(i + " " + j + " " + r[i][j] + " " + r[i][r.length - j -
1], this.compare(r[i][j],
+ r[i][r.length - j - 1]));
}
}
Modified: trunk/jgogears/jgogears/engine/Scorer.java
==============================================================================
--- trunk/jgogears/jgogears/engine/Scorer.java (original)
+++ trunk/jgogears/jgogears/engine/Scorer.java Tue Mar 25 21:19:55 2008
@@ -35,7 +35,7 @@
int i, j;
for (i = 0; i < board.getSize(); i++)
for (j = 0; j < board.getSize(); j++) {
- if (!Random.isLarger(result[i][j],best)) {
+ if (!Random.isLarger(result[i][j], best)) {
if (RuleSet.DEFAULT.moveIsLegal(null, board, new Move(i, j,
white ? BoardI.VERTEX_WHITE
: BoardI.VERTEX_BLACK))) {
best = result[i][j];
@@ -44,7 +44,7 @@
}
}
if (DEBUG)
- System.err.print("{" + i + ","+ j + "},");
+ System.err.print("{" + i + "," + j + "},");
}
if (DEBUG)
System.err.println("exiting getBestScore");
@@ -66,7 +66,7 @@
double[][] result = new double[size][size];
for (short row = 0; row < size; row++) {
for (short column = 0; column < size; column++) {
- for (short sym = 0; sym < 8; sym++) {
+ for (short sym = 0; sym < 8; sym++) {
result[row][column] = 0.0;
Node node = model.getRoot();
int maxdepth = 0;
@@ -113,18 +113,18 @@
// estimate = (1 + previous.getPlayed()) / (previous.getPlayed()
+ previous.getNotPlayed()) * (1 -
// (1 /depth));
- result[row][column] = Random.getRandomBest(estimate,result[row][column]);
- //if (DEBUG)
- // System.err.println("Model::getScores " + maxdepth);
+ result[row][column] = Random.getRandomBest(estimate, result[row][column]);
+ // if (DEBUG)
+ // System.err.println("Model::getScores " + maxdepth);
}
}
}
if (DEBUG)
- for (int i = 0; i < result.length; i++) {
- for (int j = 0; j < result[i].length; j++)
- System.err.print(" " + result[i][j]);
- System.err.println();
- }
+ for (int i = 0; i < result.length; i++) {
+ for (int j = 0; j < result[i].length; j++)
+ System.err.print(" " + result[i][j]);
+ System.err.println();
+ }
return result;
}
Modified: trunk/jgogears/jgogears/engine/StraightVertexLineariserTest.java
==============================================================================
--- trunk/jgogears/jgogears/engine/StraightVertexLineariserTest.java (original)
+++ trunk/jgogears/jgogears/engine/StraightVertexLineariserTest.java
Tue Mar 25 21:19:55 2008
@@ -14,7 +14,7 @@
/** Are we using verbose debugging?. */
public static final boolean DEBUG = false;
-
+
/**
* Identical linearisation.
*
@@ -197,7 +197,8 @@
board = board.newBoard(new Move("black a1"));
board = board.newBoard(new Move("white k10"));
board = board.newBoard(new Move("black g18"));
- System.err.println(board);
+ if (DEBUG)
+ System.err.println(board);
assertNotNull(board);
for (short row = 0; row < board.getSize(); row++)
@@ -256,21 +257,22 @@
* the exception
*/
public void testDifferenetSizes13() throws Exception {
- BoardI board = BoardI.newBoard();
- StraightVertexLineariser linear = new
StraightVertexLineariser(board, (short) 2, (short) 2, (short) 0, false);
- assertNotNull(linear);
- board = BoardI.newBoard(13);
- linear = new StraightVertexLineariser(board, (short) 2, (short) 2,
(short) 0, false);
- int count = 0;
- while (linear.hasNext()) {
- Short s = linear.next();
- assertNotNull(s);
- count++;
- }
- int plussize = (board.getSize()+2)*(board.getSize()+2) ;
+ BoardI board = BoardI.newBoard();
+ StraightVertexLineariser linear = new
StraightVertexLineariser(board, (short) 2, (short) 2, (short) 0, false);
+ assertNotNull(linear);
+ board = BoardI.newBoard(13);
+ linear = new StraightVertexLineariser(board, (short) 2, (short) 2,
(short) 0, false);
+ int count = 0;
+ while (linear.hasNext()) {
+ Short s = linear.next();
+ assertNotNull(s);
+ count++;
+ }
+ int plussize = (board.getSize() + 2) * (board.getSize() + 2);
- assertTrue(count + "/" + plussize+1, count == plussize+1);
+ assertTrue(count + "/" + plussize + 1, count == plussize + 1);
}
+
/**
* test what happens when linearising boards of different sizes.
*
@@ -278,21 +280,22 @@
* the exception
*/
public void testDifferenetSizes9() throws Exception {
- BoardI board = BoardI.newBoard();
- StraightVertexLineariser linear = new
StraightVertexLineariser(board, (short) 2, (short) 2, (short) 0, false);
- assertNotNull(linear);
- board = BoardI.newBoard(9);
- linear = new StraightVertexLineariser(board, (short) 2, (short) 2,
(short) 0, false);
- int count = 0;
- while (linear.hasNext()) {
- Short s = linear.next();
- assertNotNull(s);
- count++;
- }
- int plussize = (board.getSize()+2)*(board.getSize()+2) ;
+ BoardI board = BoardI.newBoard();
+ StraightVertexLineariser linear = new
StraightVertexLineariser(board, (short) 2, (short) 2, (short) 0, false);
+ assertNotNull(linear);
+ board = BoardI.newBoard(9);
+ linear = new StraightVertexLineariser(board, (short) 2, (short) 2,
(short) 0, false);
+ int count = 0;
+ while (linear.hasNext()) {
+ Short s = linear.next();
+ assertNotNull(s);
+ count++;
+ }
+ int plussize = (board.getSize() + 2) * (board.getSize() + 2);
- assertTrue(count + "/" + plussize+1, count == plussize+1);
+ assertTrue(count + "/" + plussize + 1, count == plussize + 1);
}
+
/**
* test what happens when linearising boards of different sizes.
*
@@ -300,21 +303,22 @@
* the exception
*/
public void testDifferenetSizes11() throws Exception {
- BoardI board = BoardI.newBoard();
- StraightVertexLineariser linear = new
StraightVertexLineariser(board, (short) 2, (short) 2, (short) 0, false);
- assertNotNull(linear);
- board = BoardI.newBoard(11);
- linear = new StraightVertexLineariser(board, (short) 2, (short) 2,
(short) 0, false);
- int count = 0;
- while (linear.hasNext()) {
- Short s = linear.next();
- assertNotNull(s);
- count++;
- }
- int plussize = (board.getSize()+2)*(board.getSize()+2) ;
+ BoardI board = BoardI.newBoard();
+ StraightVertexLineariser linear = new
StraightVertexLineariser(board, (short) 2, (short) 2, (short) 0, false);
+ assertNotNull(linear);
+ board = BoardI.newBoard(11);
+ linear = new StraightVertexLineariser(board, (short) 2, (short) 2,
(short) 0, false);
+ int count = 0;
+ while (linear.hasNext()) {
+ Short s = linear.next();
+ assertNotNull(s);
+ count++;
+ }
+ int plussize = (board.getSize() + 2) * (board.getSize() + 2);
- assertTrue(count + "/" + plussize+1, count == plussize+1);
+ assertTrue(count + "/" + plussize + 1, count == plussize + 1);
}
+
/**
* test what happens when linearising boards of different sizes.
*
@@ -322,21 +326,22 @@
* the exception
*/
public void testDifferenetSizes10() throws Exception {
- BoardI board = BoardI.newBoard();
- StraightVertexLineariser linear = new
StraightVertexLineariser(board, (short) 2, (short) 2, (short) 0, false);
- assertNotNull(linear);
- board = BoardI.newBoard(10);
- linear = new StraightVertexLineariser(board, (short) 2, (short) 2,
(short) 0, false);
- int count = 0;
- while (linear.hasNext()) {
- Short s = linear.next();
- assertNotNull(s);
- count++;
- }
- int plussize = (board.getSize()+2)*(board.getSize()+2) ;
+ BoardI board = BoardI.newBoard();
+ StraightVertexLineariser linear = new
StraightVertexLineariser(board, (short) 2, (short) 2, (short) 0, false);
+ assertNotNull(linear);
+ board = BoardI.newBoard(10);
+ linear = new StraightVertexLineariser(board, (short) 2, (short) 2,
(short) 0, false);
+ int count = 0;
+ while (linear.hasNext()) {
+ Short s = linear.next();
+ assertNotNull(s);
+ count++;
+ }
+ int plussize = (board.getSize() + 2) * (board.getSize() + 2);
- assertTrue(count + "/" + plussize+1, count == plussize+1);
+ assertTrue(count + "/" + plussize + 1, count == plussize + 1);
}
+
/**
* test what happens when linearising boards of different sizes.
*
@@ -344,21 +349,22 @@
* the exception
*/
public void testDifferenetSizes21() throws Exception {
- BoardI board = BoardI.newBoard();
- StraightVertexLineariser linear = new
StraightVertexLineariser(board, (short) 2, (short) 2, (short) 0, false);
- assertNotNull(linear);
- board = BoardI.newBoard(21);
- linear = new StraightVertexLineariser(board, (short) 2, (short) 2,
(short) 0, false);
- int count = 0;
- while (linear.hasNext()) {
- Short s = linear.next();
- assertNotNull(s);
- count++;
- }
- int plussize = (board.getSize()+2)*(board.getSize()+2) ;
+ BoardI board = BoardI.newBoard();
+ StraightVertexLineariser linear = new
StraightVertexLineariser(board, (short) 2, (short) 2, (short) 0, false);
+ assertNotNull(linear);
+ board = BoardI.newBoard(21);
+ linear = new StraightVertexLineariser(board, (short) 2, (short) 2,
(short) 0, false);
+ int count = 0;
+ while (linear.hasNext()) {
+ Short s = linear.next();
+ assertNotNull(s);
+ count++;
+ }
+ int plussize = (board.getSize() + 2) * (board.getSize() + 2);
- assertTrue(count + "/" + plussize+1, count == plussize+1);
+ assertTrue(count + "/" + plussize + 1, count == plussize + 1);
}
+
/**
* test what happens when linearising boards of different sizes.
*
@@ -366,20 +372,20 @@
* the exception
*/
public void testDifferenetSizes17() throws Exception {
- BoardI board = BoardI.newBoard();
- StraightVertexLineariser linear = new
StraightVertexLineariser(board, (short) 2, (short) 2, (short) 0, false);
- assertNotNull(linear);
- board = BoardI.newBoard(17);
- linear = new StraightVertexLineariser(board, (short) 2, (short) 2,
(short) 0, false);
- int count = 0;
- while (linear.hasNext()) {
- Short s = linear.next();
- assertNotNull(s);
- count++;
- }
- int plussize = (board.getSize()+2)*(board.getSize()+2) ;
+ BoardI board = BoardI.newBoard();
+ StraightVertexLineariser linear = new
StraightVertexLineariser(board, (short) 2, (short) 2, (short) 0, false);
+ assertNotNull(linear);
+ board = BoardI.newBoard(17);
+ linear = new StraightVertexLineariser(board, (short) 2, (short) 2,
(short) 0, false);
+ int count = 0;
+ while (linear.hasNext()) {
+ Short s = linear.next();
+ assertNotNull(s);
+ count++;
+ }
+ int plussize = (board.getSize() + 2) * (board.getSize() + 2);
- assertTrue(count + "/" + plussize+1, count == plussize+1);
+ assertTrue(count + "/" + plussize + 1, count == plussize + 1);
}
/**
@@ -454,8 +460,8 @@
for (short sym2 = 0; sym2 < 8; sym2++) {
matches[0][sym1][sym2] = true;
Iterator<Short> lineara = new StraightVertexLineariser(board,
(short) 0, (short) 0, sym1, false);
- Iterator<Short> linearb = new StraightVertexLineariser(board,
(short) (size - 1), (short) (size - 1), sym2,
- false);
+ Iterator<Short> linearb = new StraightVertexLineariser(board,
(short) (size - 1), (short) (size - 1),
+ sym2, false);
while (lineara.hasNext()) {
assertTrue(lineara.hasNext());
assertTrue(linearb.hasNext());
@@ -470,7 +476,8 @@
for (short sym2 = 0; sym2 < 8; sym2++) {
matches[1][sym1][sym2] = true;
Iterator<Short> lineara = new StraightVertexLineariser(board,
(short) 0, (short) 0, sym1, false);
- Iterator<Short> linearb = new StraightVertexLineariser(board,
(short) 0, (short) (size - 1), sym2, false);
+ Iterator<Short> linearb = new StraightVertexLineariser(board,
(short) 0, (short) (size - 1), sym2,
+ false);
while (lineara.hasNext()) {
assertTrue(lineara.hasNext());
assertTrue(linearb.hasNext());
@@ -485,7 +492,8 @@
for (short sym2 = 0; sym2 < 8; sym2++) {
matches[2][sym1][sym2] = true;
Iterator<Short> lineara = new StraightVertexLineariser(board,
(short) 0, (short) 0, sym1, false);
- Iterator<Short> linearb = new StraightVertexLineariser(board,
(short) (size - 1), (short) 0, sym2, false);
+ Iterator<Short> linearb = new StraightVertexLineariser(board,
(short) (size - 1), (short) 0, sym2,
+ false);
while (lineara.hasNext()) {
assertTrue(lineara.hasNext());
assertTrue(linearb.hasNext());
@@ -499,11 +507,11 @@
}
for (short corn = 0; corn < 3; corn++) {
for (short sym1 = 0; sym1 < 8; sym1++) {
- boolean tfound= false;
- boolean ffound= false;
+ boolean tfound = false;
+ boolean ffound = false;
for (short sym2 = 0; sym2 < 8; sym2++) {
- if(DEBUG)
- System.err.print(matches[corn][sym1][sym2] + " ");
+ if (DEBUG)
+ System.err.print(matches[corn][sym1][sym2] + " ");
if (matches[corn][sym1][sym2])
tfound = true;
else
@@ -511,11 +519,11 @@
}
assertTrue(tfound);
assertTrue(ffound);
- if(DEBUG)
- System.err.println();
+ if (DEBUG)
+ System.err.println();
}
- if(DEBUG)
- System.err.println();
+ if (DEBUG)
+ System.err.println();
}
}
@@ -670,9 +678,9 @@
assertNotNull(s);
count++;
}
- int plussize = StraightVertexLineariser.SIZE *StraightVertexLineariser.SIZE;
+ int plussize = StraightVertexLineariser.SIZE * StraightVertexLineariser.SIZE;
- assertTrue(count + "/" + plussize+1, count == plussize+1);
+ assertTrue(count + "/" + plussize + 1, count == plussize + 1);
}
/**
@@ -691,7 +699,8 @@
assertNotNull(board);
if (DEBUG)
-
System.err.print("StraightVertexLineariserTest::testVertexLineariser()
Black = " + BoardI.parseColour("black"));
+
System.err.print("StraightVertexLineariserTest::testVertexLineariser()
Black = "
+ + BoardI.parseColour("black"));
if (DEBUG)
System.err.print(" White = " + BoardI.parseColour("white"));
if (DEBUG)
@@ -733,11 +742,12 @@
Iterator<Short> linear = new StraightVertexLineariser(board,
(short) 2, (short) 2, j, false);
assertTrue(linear != null);
if (DEBUG)
- System.err.println(linear);
+ System.err.println(linear);
linear = new StraightVertexLineariser(board, (short) 2, (short) 2,
j, false);
- }
+ }
}
+
/**
* Test initialised master
*/
@@ -745,34 +755,40 @@
BoardI board = BoardI.newBoard();
assertNotNull(board);
- Iterator<Short> linear = new StraightVertexLineariser(board, (short)
2, (short) 2,(short) 0, false);
+ Iterator<Short> linear = new StraightVertexLineariser(board, (short)
2, (short) 2, (short) 0, false);
assertTrue(linear != null);
for (short j = 0; j < 8; j++) {
- int totalboardsizea = board.getSize() *board.getSize();
- int totalboardsizeb = board.getSize() *board.getSize();
- int totalboardsizec = board.getSize() *board.getSize();
- int totalboardsized = board.getSize() *board.getSize();
+ int totalboardsizea = board.getSize() * board.getSize();
+ int totalboardsizeb = board.getSize() * board.getSize();
+ int totalboardsizec = board.getSize() * board.getSize();
+ int totalboardsized = board.getSize() * board.getSize();
assertTrue(StraightVertexLineariser.master[j][0].length == StraightVertexLineariser.SEQUENCE_SIZE);
for (short seq = 0; seq <
StraightVertexLineariser.master[j][0].length; seq++) {
if (DEBUG && seq < 9)
- System.err.print("{" + StraightVertexLineariser.master[j][0][seq]
+ "," + StraightVertexLineariser.master[j][1][seq] + "},");
- if (board.getColour(StraightVertexLineariser.master[j][0][seq],
StraightVertexLineariser.master[j][1][seq]) == Board.VERTEX_EMPTY)
- totalboardsizea --;
- if (board.getColour(StraightVertexLineariser.master[j][0][seq]+18,
StraightVertexLineariser.master[j][1][seq]) == Board.VERTEX_EMPTY)
- totalboardsizeb --;
- if (board.getColour(StraightVertexLineariser.master[j][0][seq],
StraightVertexLineariser.master[j][1][seq]+18) == Board.VERTEX_EMPTY)
- totalboardsizec --;
- if (board.getColour(StraightVertexLineariser.master[j][0][seq]+18,
StraightVertexLineariser.master[j][1][seq]+18) == Board.VERTEX_EMPTY)
- totalboardsized --;
+ System.err.print("{" + StraightVertexLineariser.master[j][0][seq] + ","
+ + StraightVertexLineariser.master[j][1][seq] + "},");
+ if (board.getColour(StraightVertexLineariser.master[j][0][seq],
+ StraightVertexLineariser.master[j][1][seq]) == Board.VERTEX_EMPTY)
+ totalboardsizea--;
+ if (board.getColour(StraightVertexLineariser.master[j][0][seq] + 18,
+ StraightVertexLineariser.master[j][1][seq]) == Board.VERTEX_EMPTY)
+ totalboardsizeb--;
+ if (board.getColour(StraightVertexLineariser.master[j][0][seq],
+ StraightVertexLineariser.master[j][1][seq] + 18) == Board.VERTEX_EMPTY)
+ totalboardsizec--;
+ if (board.getColour(StraightVertexLineariser.master[j][0][seq] + 18,
+ StraightVertexLineariser.master[j][1][seq] + 18) == Board.VERTEX_EMPTY)
+ totalboardsized--;
}
if (DEBUG)
- System.err.println();
+ System.err.println();
assertTrue(totalboardsizea == 0);
assertTrue(totalboardsizeb == 0);
assertTrue(totalboardsizec == 0);
assertTrue(totalboardsized == 0);
}
}
+
/**
* Test initialised master
*/
@@ -780,30 +796,34 @@
BoardI board = BoardI.newBoard();
assertNotNull(board);
// this call makes sure that the master is initialised
- Iterator<Short> linear = new StraightVertexLineariser(board, (short)
2, (short) 2,(short) 0, false);
+ Iterator<Short> linear = new StraightVertexLineariser(board, (short)
2, (short) 2, (short) 0, false);
assertTrue(linear != null);
-
- for (short row= 0; row < board.getSize();row++)
- for (short column= 0; column < board.getSize();column++)
+
+ for (short row = 0; row < board.getSize(); row++)
+ for (short column = 0; column < board.getSize(); column++)
for (short j = 0; j < 8; j++) {
boolean found = false;
- for (short seq = 0; seq <
StraightVertexLineariser.master[j][0].length&& found == false; seq++)
- if (StraightVertexLineariser.master[j][0][seq] == row &&
StraightVertexLineariser.master[j][1][seq] == column && found == false )
+ for (short seq = 0; seq <
StraightVertexLineariser.master[j][0].length && found == false; seq++)
+ if (StraightVertexLineariser.master[j][0][seq] == row
+ && StraightVertexLineariser.master[j][1][seq] == column &&
found == false)
found = true;
assertTrue("" + row + " " + column + " " + j, found);
}
}
+
/**
* Test initialised master
*/
- public void testContants() {
+ public void testContants() {
BoardI board = BoardI.newBoard();
assertNotNull(board);
// this call makes sure that the master is initialised
- Iterator<Short> linear = new StraightVertexLineariser(board, (short)
2, (short) 2,(short) 0, false);
+ Iterator<Short> linear = new StraightVertexLineariser(board, (short)
2, (short) 2, (short) 0, false);
assertTrue(linear != null);
-
-System.err.println("BOARD_SIZE=" + StraightVertexLineariser.BOARD_SIZE
+ " SIZE=" + StraightVertexLineariser.SIZE + " SEQUENCE_SIZE=" + StraightVertexLineariser.SEQUENCE_SIZE);
-System.err.println("master[this.sym][0].length=" + StraightVertexLineariser.master[0][0].length);
+ if (DEBUG)
+ System.err.println("BOARD_SIZE=" +
StraightVertexLineariser.BOARD_SIZE + " SIZE="
+ + StraightVertexLineariser.SIZE + " SEQUENCE_SIZE=" + StraightVertexLineariser.SEQUENCE_SIZE);
+ if (DEBUG)
+ System.err.println("master[this.sym][0].length=" + StraightVertexLineariser.master[0][0].length);
}
}
Modified: trunk/jgogears/jgogears/engine/Trainer.java
==============================================================================
--- trunk/jgogears/jgogears/engine/Trainer.java (original)
+++ trunk/jgogears/jgogears/engine/Trainer.java Tue Mar 25 21:19:55 2008
@@ -14,13 +14,13 @@
public class Trainer {
/** arbitrarily large integer for use in counting variables */
static final private int BIG_INT = Integer.MAX_VALUE;
- /** are we being verbose ?*/
+ /** are we being verbose ? */
static final private boolean DEBUG = false;
- /** are we showing progress ? Useful in when training on large
numbers of games*/
+ /** are we showing progress ? Useful in when training on large
numbers of games */
static final private boolean PROGRESS = true;
- /** are we giving a free ride to EMPTY and OFF_BOARD ?*/
+ /** are we giving a free ride to EMPTY and OFF_BOARD ? */
static final private boolean freeRideForEmpty = true;
-
+
// these are all set side open to expand the tree as much as possible
static final private boolean onlyOneNewNodePerSymmetry = true;
static final private int trainPlaysToDepth = BIG_INT;
@@ -28,28 +28,24 @@
static final private int trainPassToDepth = BIG_INT;
static final private boolean expandNoPlay = true;
static final private boolean expandPass = true;
-
- /** how many games are we going to train on?*/
+
+ /** how many games are we going to train on? */
public final int DEFAULT_NUMBER_OF_FILES = Integer.MAX_VALUE;
/** the model we're going to train */
private Model model = null;
/** location of the small training library in svn */
final public static String LIBRARY = "sgf/2004-12";
-/**
- * Returns the minimum number of times we have to have visited a node
to expand it.
- *
- * Doesn't apply to nodes expanded with a free ride.
- *
- * This is the prime method of limiting the growth of the tree size.
- *
- * @return the minimum size, including both played and not-played visits.
- */
+ /**
+ * Returns the minimum number of times we have to have visited a node
to expand it. Doesn't apply to nodes expanded
+ * with a free ride. This is the prime method of limiting the growth
of the tree size.
+ *
+ * @return the minimum size, including both played and not-played visits.
+ */
public final double getMinBranchSize() {
return model.getGamesTrained() * 2.0 + 20.0;
}
-
/**
* Loads all the default SGF files
*
@@ -177,6 +173,26 @@
* the game
*/
public void train(Game game) {
+ if (game == null)
+ throw new Error("Internal error, null Game");
+ if (game.isBranched()) {
+ // if (DEBUG)
+ System.err.println("game branched, assuming it's a teaching game
and not training on it");
+ return;
+ }
+ if (game.getNeitherWin()) {
+ // if (DEBUG)
+ System.err.println("no obvious winner to the game, not using it as training");
+ return;
+ }
+ boolean playingBlack = false;
+ if (game.getBlackWin())
+ playingBlack = true;
+ else if (game.getWhiteWin())
+ playingBlack = false;
+ else
+ throw new Error("Bad score" + game.getScore());
+
short size = game.getSize();
Iterator<BoardI> boards = game.getBoards();
if (boards == null)
@@ -201,21 +217,27 @@
int colour = move.getColour();
boolean isBlack = colour == BoardI.VERTEX_BLACK;
// float str = (float) (isBlack ? strengthB : strengthW);
- if (move.getResign())
- return;
- else
- for (short i = 0; i < size; i++)
- for (short j = 0; j < size; j++)
- for (short sym = 0; sym < 8; sym++) {
- StraightVertexLineariser linear = new
StraightVertexLineariser(board, i, j, sym, !isBlack);
- if (move.getPlay())
- if (move.getRow() != i && move.getColumn() != j)
- train(linear, true, true, trainPlaysToDepth);
+
+ if (isBlack == playingBlack) {
+ if (move.getResign())
+ return;
+ else
+ for (short i = 0; i < size; i++)
+ for (short j = 0; j < size; j++)
+ for (short sym = 0; sym < 8; sym++) {
+ StraightVertexLineariser linear = new
StraightVertexLineariser(board, i, j, sym,
+ !isBlack);
+ if (move.getPlay())
+ if (move.getRow() != i && move.getColumn() != j)
+ train(linear, true, true, trainPlaysToDepth);
+ else
+ train(linear, false, expandNoPlay, trainNoPlaysToDepth);
+ else if (move.getPass())
+ train(linear, false, expandPass, trainPassToDepth);
else
- train(linear, false, expandNoPlay, trainNoPlaysToDepth);
- else if (move.getPass())
- train(linear, false, expandPass, trainPassToDepth);
- }
+ throw new Error("internal error, unknown move type");
+ }
+ }
}
}
@@ -286,7 +308,7 @@
break;
case BoardI.VERTEX_OFF_BOARD:
if (root.getOff() == null)
- if (expand|| (!freeRideUsed && freeRideForEmpty)) {
+ if (expand || (!freeRideUsed && freeRideForEmpty)) {
root.setOff(new Node());
expand = expandMore;
root = root.getOff();
Modified: trunk/jgogears/jgogears/engine/VertexLineariser.java
==============================================================================
--- trunk/jgogears/jgogears/engine/VertexLineariser.java (original)
+++ trunk/jgogears/jgogears/engine/VertexLineariser.java Tue Mar 25
21:19:55 2008
@@ -43,9 +43,9 @@
/** Have the colours been inverted? */
boolean invert = false;
-
+
/** are we being verbose */
- final static boolean PROGRESS = true;
+ final static boolean PROGRESS = false;
/**
* Instantiates a new vertex lineariser.
Modified: trunk/jgogears/jgogears/engine/VertexLineariserTest.java
==============================================================================
--- trunk/jgogears/jgogears/engine/VertexLineariserTest.java (original)
+++ trunk/jgogears/jgogears/engine/VertexLineariserTest.java Tue Mar 25
21:19:55 2008
@@ -6,7 +6,7 @@
import jgogears.*;
import junit.framework.TestCase;
-// TODO: Auto-generated Javadoc
+// TODO: Auto-generated Javadocs
/**
* The Class VertexLineariserTest.
*/
@@ -194,7 +194,8 @@
board = board.newBoard(new Move("black a1"));
board = board.newBoard(new Move("white k10"));
board = board.newBoard(new Move("black g18"));
- System.err.println(board);
+ if (DEBUG)
+ System.err.println(board);
assertNotNull(board);
for (short row = 0; row < board.getSize(); row++)
@@ -439,11 +440,11 @@
}
for (short corn = 0; corn < 3; corn++) {
for (short sym1 = 0; sym1 < 8; sym1++) {
- boolean tfound= false;
- boolean ffound= false;
+ boolean tfound = false;
+ boolean ffound = false;
for (short sym2 = 0; sym2 < 8; sym2++) {
- if(DEBUG)
- System.err.print(matches[corn][sym1][sym2] + " ");
+ if (DEBUG)
+ System.err.print(matches[corn][sym1][sym2] + " ");
if (matches[corn][sym1][sym2])
tfound = true;
else
@@ -451,11 +452,11 @@
}
assertTrue(tfound);
assertTrue(ffound);
- if(DEBUG)
- System.err.println();
+ if (DEBUG)
+ System.err.println();
}
- if(DEBUG)
- System.err.println();
+ if (DEBUG)
+ System.err.println();
}
}