Added:
trunk/jgogears/jgogears/SmallBoard.java
- copied, changed from r54, /trunk/jgogears/jgogears/FastBoard.java
trunk/jgogears/jgogears/SmallBoardTest.java
- copied, changed from r55, /trunk/jgogears/jgogears/FastBoardTest.java
trunk/jgogears/jgogears/SmallerBoard.java
- copied, changed from r55, /trunk/jgogears/jgogears/FasterBoard.java
trunk/jgogears/jgogears/SmallerBoardTest.java
- copied, changed from r55, /trunk/jgogears/jgogears/FasterBoardTest.java
Removed:
trunk/jgogears/jgogears/FastBoard.java
trunk/jgogears/jgogears/FastBoardTest.java
trunk/jgogears/jgogears/FasterBoard.java
trunk/jgogears/jgogears/FasterBoardTest.java
Modified:
trunk/jgogears/jgogears/AllTests.java
trunk/jgogears/jgogears/Board.java
trunk/jgogears/jgogears/BoardI.java
trunk/jgogears/jgogears/BoardToASCIITest.java
trunk/jgogears/jgogears/GlobalTests.java
trunk/jgogears/jgogears/NoKoRuleSetTest.java
trunk/jgogears/jgogears/TwoGTP.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/SufgoEngine.java
trunk/jgogears/jgogears/engine/SufogoEngineTest.java
trunk/jgogears/jgogears/engine/Trainer.java
trunk/jgogears/jgogears/engine/TrainerTest.java
trunk/jgogears/jgogears/engine/VertexLineariser.java
trunk/jgogears/jgogears/engine/VertexLineariserTest.java
Log:
rename Fast(er)Board Small(er)Board after profiling reveals that Board
is faster but larger
Modified: trunk/jgogears/jgogears/AllTests.java
==============================================================================
--- trunk/jgogears/jgogears/AllTests.java (original)
+++ trunk/jgogears/jgogears/AllTests.java Mon Mar 10 21:42:36 2008
@@ -30,14 +30,14 @@
suite.addTestSuite(RankTest.class);
suite.addTestSuite(ZobristTest.class);
suite.addTestSuite(SGFNodeTest.class);
- suite.addTestSuite(FasterBoardTest.class);
+ suite.addTestSuite(SmallerBoardTest.class);
suite.addTestSuite(SGFPropertyTest.class);
suite.addTestSuite(BoardTest.class);
suite.addTestSuite(BoardToASCIITest.class);
suite.addTestSuite(SGFParserTest.class);
suite.addTest(GlobalTests.suite());
suite.addTestSuite(MoveTest.class);
- suite.addTestSuite(FastBoardTest.class);
+ suite.addTestSuite(SmallBoardTest.class);
// $JUnit-END$
return suite;
}
Modified: trunk/jgogears/jgogears/Board.java
==============================================================================
--- trunk/jgogears/jgogears/Board.java (original)
+++ trunk/jgogears/jgogears/Board.java Mon Mar 10 21:42:36 2008
@@ -150,16 +150,6 @@
return this.board[row][column];
}
- /*
- * (non-Javadoc)
- *
- * @see jgogears.BoardInterface#getSize()
- */
- @Override
- public short getSize() {
- return this.size;
- }
-
/**
* initialise the board, creating it and setting it empty.
*/
Modified: trunk/jgogears/jgogears/BoardI.java
==============================================================================
--- trunk/jgogears/jgogears/BoardI.java (original)
+++ trunk/jgogears/jgogears/BoardI.java Mon Mar 10 21:42:36 2008
@@ -78,7 +78,7 @@
* @return the new empty board
*/
public static BoardI newBoard() {
- return new FasterBoard(DEFAULT_BOARD_SIZE);
+ return new Board(DEFAULT_BOARD_SIZE);
}
/**
@@ -89,7 +89,7 @@
* @return the new empty board
*/
public static BoardI newBoard(boolean zobrist) {
- return new FasterBoard(zobrist);
+ return new Board(zobrist);
}
/**
@@ -100,7 +100,7 @@
* @return the new empty board
*/
public static BoardI newBoard(int size) {
- return new FasterBoard((short) size);
+ return new Board((short) size);
}
/**
@@ -113,7 +113,7 @@
* @return the new empty board
*/
public static BoardI newBoard(int size, boolean zobrist) {
- return new FasterBoard((short) size, zobrist);
+ return new Board((short) size, zobrist);
}
/**
@@ -126,7 +126,7 @@
* @return the new empty board
*/
public static BoardI newBoard(int size, RuleSet rule) {
- return new FasterBoard((short) size, rule);
+ return new Board((short) size, rule);
}
/**
@@ -141,7 +141,7 @@
* @return the new empty board
*/
public static BoardI newBoard(int size, RuleSet rule, boolean
zobrist) {
- return new FasterBoard((short) size, rule, zobrist);
+ return new Board((short) size, rule, zobrist);
}
/**
Modified: trunk/jgogears/jgogears/BoardToASCIITest.java
==============================================================================
--- trunk/jgogears/jgogears/BoardToASCIITest.java (original)
+++ trunk/jgogears/jgogears/BoardToASCIITest.java Mon Mar 10 21:42:36 2008
@@ -12,7 +12,7 @@
public class BoardToASCIITest extends TestCase {
/** The Constant DEBUG. */
- static final public boolean DEBUG = true;
+ static final public boolean DEBUG = false;
/**
* Test empty.
@@ -22,11 +22,11 @@
String string = BoardToASCII.Transform(board);
assertNotNull(board);
assertNotNull(string);
- board = new FastBoard();
+ board = new SmallBoard();
string = BoardToASCII.Transform(board);
assertNotNull(board);
assertNotNull(string);
- board = new FasterBoard();
+ board = new SmallerBoard();
string = BoardToASCII.Transform(board);
assertNotNull(board);
assertNotNull(string);
Modified: trunk/jgogears/jgogears/GlobalTests.java
==============================================================================
--- trunk/jgogears/jgogears/GlobalTests.java (original)
+++ trunk/jgogears/jgogears/GlobalTests.java Mon Mar 10 21:42:36 2008
@@ -38,8 +38,8 @@
suite.addTestSuite(SGFGameTest.class);
suite.addTestSuite(GTPScoreTest.class);
suite.addTestSuite(GnuGoEngineTest2.class);
- suite.addTestSuite(FastBoardTest.class);
- suite.addTestSuite(FasterBoardTest.class);
+ suite.addTestSuite(SmallBoardTest.class);
+ suite.addTestSuite(SmallerBoardTest.class);
suite.addTestSuite(NoKoRuleSetTest.class);
suite.addTestSuite(ZobristTest.class);
suite.addTestSuite(CheckAllSGFFilesTest.class);
Modified: trunk/jgogears/jgogears/NoKoRuleSetTest.java
==============================================================================
--- trunk/jgogears/jgogears/NoKoRuleSetTest.java (original)
+++ trunk/jgogears/jgogears/NoKoRuleSetTest.java Mon Mar 10 21:42:36 2008
@@ -13,7 +13,7 @@
public class NoKoRuleSetTest extends TestCase {
/** The Constant DEBUG. */
- static final boolean DEBUG = true;
+ static final boolean DEBUG = false;
/**
* Test capture complex.
Copied: trunk/jgogears/jgogears/SmallBoard.java (from r54, /trunk/jgogears/jgogears/FastBoard.java)
==============================================================================
--- /trunk/jgogears/jgogears/FastBoard.java (original)
+++ trunk/jgogears/jgogears/SmallBoard.java Mon Mar 10 21:42:36 2008
@@ -7,7 +7,7 @@
*
* @author syeates
*/
-public class FastBoard extends BoardI {
+public class SmallBoard extends BoardI {
/** How many bits we're allocating per square on the board. */
final static short BITS_PER_VERTEX = 4;
@@ -19,7 +19,7 @@
* Constructor for default board size.
*/
- public FastBoard() {
+ public SmallBoard() {
// nothing
}
@@ -30,7 +30,7 @@
* true if we're using zobrist hashing
*/
- public FastBoard(boolean zobrist) {
+ public SmallBoard(boolean zobrist) {
super(zobrist);
}
@@ -42,7 +42,7 @@
* @param move
* the move
*/
- public FastBoard(FastBoard board, Move move) {
+ public SmallBoard(SmallBoard board, Move move) {
this.size = board.getSize();
this.copydata(board, move);
}
@@ -54,7 +54,7 @@
* size of the board
*/
- public FastBoard(int size) {
+ public SmallBoard(int size) {
this.size = (short) size;
}
@@ -66,7 +66,7 @@
* @param rule
* the ruleset to use
*/
- public FastBoard(int size, RuleSet rule) {
+ public SmallBoard(int size, RuleSet rule) {
this.size = (short) size;
this.ruleSet = rule;
}
@@ -77,7 +77,7 @@
* @param rule
* the rule
*/
- public FastBoard(RuleSet rule) {
+ public SmallBoard(RuleSet rule) {
this.ruleSet = rule;
}
@@ -88,7 +88,7 @@
* size of the board
*/
- public FastBoard(short size) {
+ public SmallBoard(short size) {
this.size = size;
}
@@ -100,7 +100,7 @@
* @param rule
* the ruleset to use
*/
- public FastBoard(short size, RuleSet rule) {
+ public SmallBoard(short size, RuleSet rule) {
this.size = size;
this.ruleSet = rule;
}
@@ -139,8 +139,8 @@
* @return the new board
*/
@Override
- public final FastBoard newBoard(Move move) {
- return new FastBoard(this, move);
+ public final SmallBoard newBoard(Move move) {
+ return new SmallBoard(this, move);
}
/*
Copied: trunk/jgogears/jgogears/SmallBoardTest.java (from r55, /trunk/jgogears/jgogears/FastBoardTest.java)
==============================================================================
--- /trunk/jgogears/jgogears/FastBoardTest.java (original)
+++ trunk/jgogears/jgogears/SmallBoardTest.java Mon Mar 10 21:42:36 2008
@@ -7,9 +7,9 @@
// TODO: Auto-generated Javadoc
/**
- * The Class FastBoardTest.
+ * The Class SmallBoardTest.
*/
-public class FastBoardTest extends TestCase {
+public class SmallBoardTest extends TestCase {
/**
* Test all vertexes on a board of size N.
@@ -18,7 +18,7 @@
* the size
*/
public void testAllVertexesN(int size) {
- BoardI board = new FastBoard(size);
+ BoardI board = new SmallBoard(size);
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
@@ -34,7 +34,7 @@
assertTrue(board.getColour(l, m) == board.getColour(l, m));
assertTrue(board.getColour(l, m) == BoardI.VERTEX_EMPTY);
// assertTrue(board.getColour(l, m) ==
- // FastBoard.VERTEX_EMPTY);
+ // SmallBoard.VERTEX_EMPTY);
assertTrue("" + size + "," + i + "," + j + "," + l + "," + m
+ "," + board.getColour(l, m)
+ "," + BoardI.VERTEX_EMPTY, board.getColour(l, m) == BoardI.VERTEX_EMPTY);
}
@@ -111,7 +111,7 @@
if (game.getSize() == 19) {
Iterator<Move> i = game.getMoves();
Move move = null;
- BoardI board = new FastBoard(game.getSize());
+ BoardI board = new SmallBoard(game.getSize());
// System.err.println("board size is: \"" + goGame.getSize()
// + "\"");
while (i.hasNext()) {
@@ -153,7 +153,7 @@
Game game = Game.loadFromFile(new File("sgf/testing/simpleGnuGo.sgf"));
Iterator<Move> i = game.getMoves();
Move move = null;
- BoardI board = new FastBoard(game.getSize());
+ BoardI board = new SmallBoard(game.getSize());
while (i.hasNext()) {
move = i.next();
assertNotNull(move);
@@ -320,7 +320,7 @@
* Test to string.
*/
public void testToString() {
- BoardI working = new FastBoard((short) 19);
+ BoardI working = new SmallBoard((short) 19);
assertNotNull(working);
working = working.newBoard(new Move("B q10"));
// System.out.println(working);
@@ -334,7 +334,7 @@
for (int j = 0; j < Zobrist.MAX_BOARD_SIZE; j++)
for (int k = 0; k < Zobrist.MAX_COLOUR; k++) {
- BoardI board1 = new FastBoard();
+ BoardI board1 = new SmallBoard();
BoardI board2 = board1.newBoard(new Move((short) 1, (short) 1, BoardI.VERTEX_BLACK));
BoardI board3 = board1.newBoard(new Move((short) 1, (short) 1, BoardI.VERTEX_BLACK));
// BoardI board4 = board2.newBoard(new Move((short) 1, (short) 1, BoardI.VERTEX_BLACK));
@@ -364,7 +364,7 @@
for (int j = 0; j < Zobrist.MAX_BOARD_SIZE; j++)
for (int k = 0; k < Zobrist.MAX_COLOUR; k++) {
- BoardI board1 = new FastBoard(true);
+ BoardI board1 = new SmallBoard(true);
BoardI board2 = board1.newBoard(new Move((short) 1, (short) 1, BoardI.VERTEX_BLACK));
BoardI board3 = board1.newBoard(new Move((short) 1, (short) 1, BoardI.VERTEX_BLACK));
// BoardI board4 = board2.newBoard(new Move((short) 1, (short) 1, BoardI.VERTEX_BLACK));
@@ -394,7 +394,7 @@
for (int j = 0; j < Zobrist.MAX_BOARD_SIZE; j++)
for (int k = 0; k < Zobrist.MAX_COLOUR; k++) {
- BoardI board1 = new FastBoard(false);
+ BoardI board1 = new SmallBoard(false);
BoardI board2 = board1.newBoard(new Move((short) 1, (short) 1, BoardI.VERTEX_BLACK));
BoardI board3 = board1.newBoard(new Move((short) 1, (short) 1, BoardI.VERTEX_BLACK));
// BoardI board4 = board2.newBoard(new Move((short) 1, (short) 1, BoardI.VERTEX_BLACK));
Copied: trunk/jgogears/jgogears/SmallerBoard.java (from r55, /trunk/jgogears/jgogears/FasterBoard.java)
==============================================================================
--- /trunk/jgogears/jgogears/FasterBoard.java (original)
+++ trunk/jgogears/jgogears/SmallerBoard.java Mon Mar 10 21:42:36 2008
@@ -8,7 +8,7 @@
*
* @author syeates
*/
-public class FasterBoard extends BoardI {
+public class SmallerBoard extends BoardI {
/** the bit number for empty. */
final static short OFFSET_EMPTY = 0;
@@ -17,7 +17,7 @@
final static short OFFSET_COLOUR = 1;
/** verbose debugging info. */
- private final boolean DEBUG = true;
+ private final boolean DEBUG = false;
/** the underlying bitset holding the data. */
private final BitSet bits = new BitSet();
@@ -25,7 +25,7 @@
/**
* Create a new board.
*/
- public FasterBoard() {
+ public SmallerBoard() {
// nothing
}
@@ -35,7 +35,7 @@
* @param zobrist
* true if using zorbist hashing
*/
- public FasterBoard(boolean zobrist) {
+ public SmallerBoard(boolean zobrist) {
super(zobrist);
}
@@ -47,7 +47,7 @@
* @param move
* the move
*/
- public FasterBoard(FasterBoard board, Move move) {
+ public SmallerBoard(SmallerBoard board, Move move) {
this.size = board.getSize();
this.copydata(board, move);
}
@@ -58,7 +58,7 @@
* @param size
* the size of the board
*/
- public FasterBoard(int size) {
+ public SmallerBoard(int size) {
this.size = (short) size;
}
@@ -70,7 +70,7 @@
* @param rule
* the ruleset to use
*/
- public FasterBoard(int size, RuleSet rule) {
+ public SmallerBoard(int size, RuleSet rule) {
this.size = (short) size;
this.ruleSet = rule;
}
@@ -81,7 +81,7 @@
* @param rule
* the ruleset to use
*/
- public FasterBoard(RuleSet rule) {
+ public SmallerBoard(RuleSet rule) {
this.ruleSet = rule;
}
@@ -92,7 +92,7 @@
* the size of the board
*/
- public FasterBoard(short size) {
+ public SmallerBoard(short size) {
this.size = size;
}
@@ -104,7 +104,7 @@
* @param size
* the board size
*/
- public FasterBoard(short size, boolean zobrist) {
+ public SmallerBoard(short size, boolean zobrist) {
super(zobrist);
this.size = size;
}
@@ -117,7 +117,7 @@
* @param rule
* the ruleset to use
*/
- public FasterBoard(short size, RuleSet rule) {
+ public SmallerBoard(short size, RuleSet rule) {
this.size = size;
this.ruleSet = rule;
}
@@ -132,7 +132,7 @@
* @param rule
* the ruleset in use
*/
- public FasterBoard(short size, RuleSet rule, boolean zobrist) {
+ public SmallerBoard(short size, RuleSet rule, boolean zobrist) {
super(zobrist);
this.size = size;
this.ruleSet = rule;
@@ -190,16 +190,6 @@
return OFFSET_EMPTY * this.size * this.size + row * this.size + column;
}
- /*
- * (non-Javadoc)
- *
- * @see jgogears.BoardInterface#getSize()
- */
- @Override
- public short getSize() {
- return this.size;
- }
-
/**
* create a new board based on the current board plus a move.
*
@@ -208,8 +198,8 @@
* @return the new board
*/
@Override
- public final FasterBoard newBoard(Move move) {
- return new FasterBoard(this, move);
+ public final SmallerBoard newBoard(Move move) {
+ return new SmallerBoard(this, move);
}
/**
Copied: trunk/jgogears/jgogears/SmallerBoardTest.java (from r55, /trunk/jgogears/jgogears/FasterBoardTest.java)
==============================================================================
--- /trunk/jgogears/jgogears/FasterBoardTest.java (original)
+++ trunk/jgogears/jgogears/SmallerBoardTest.java Mon Mar 10 21:42:36 2008
@@ -7,9 +7,9 @@
// TODO: Auto-generated Javadoc
/**
- * The Class FasterBoardTest.
+ * The Class SmallerBoardTest.
*/
-public class FasterBoardTest extends TestCase {
+public class SmallerBoardTest extends TestCase {
/**
* Test all sizes.
@@ -42,7 +42,7 @@
* the size
*/
public void testAllVertexesN(int size) {
- BoardI board = new FasterBoard(size);
+ BoardI board = new SmallerBoard(size);
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
@@ -141,7 +141,7 @@
if (game.getSize() == 19) {
Iterator<Move> i = game.getMoves();
Move move = null;
- BoardI board = new FasterBoard(game.getSize());
+ BoardI board = new SmallerBoard(game.getSize());
// System.err.println("board size is: \"" + goGame.getSize()
// + "\"");
while (i.hasNext()) {
@@ -184,7 +184,7 @@
Game game = Game.loadFromFile(new File("sgf/testing/simpleGnuGo.sgf"));
Iterator<Move> i = game.getMoves();
Move move = null;
- BoardI board = new FasterBoard(game.getSize());
+ BoardI board = new SmallerBoard(game.getSize());
while (i.hasNext()) {
move = i.next();
assertNotNull(move);
@@ -197,7 +197,7 @@
* Test to string.
*/
public void testToString() {
- BoardI working = new FasterBoard((short) 19);
+ BoardI working = new SmallerBoard((short) 19);
assertNotNull(working);
working = working.newBoard(new Move("B q10"));
System.out.println(working);
@@ -211,7 +211,7 @@
for (int j = 0; j < Zobrist.MAX_BOARD_SIZE; j++)
for (int k = 0; k < Zobrist.MAX_COLOUR; k++) {
- BoardI board1 = new FasterBoard();
+ BoardI board1 = new SmallerBoard();
BoardI board2 = board1.newBoard(new Move((short) 1, (short) 1, BoardI.VERTEX_BLACK));
BoardI board3 = board1.newBoard(new Move((short) 1, (short) 1, BoardI.VERTEX_BLACK));
// BoardI board4 = board2.newBoard(new Move((short) 1, (short) 1, BoardI.VERTEX_BLACK));
@@ -241,7 +241,7 @@
for (int j = 0; j < Zobrist.MAX_BOARD_SIZE; j++)
for (int k = 0; k < Zobrist.MAX_COLOUR; k++) {
- BoardI board1 = new FasterBoard(true);
+ BoardI board1 = new SmallerBoard(true);
BoardI board2 = board1.newBoard(new Move((short) 1, (short) 1, BoardI.VERTEX_BLACK));
BoardI board3 = board1.newBoard(new Move((short) 1, (short) 1, BoardI.VERTEX_BLACK));
// BoardI board4 = board2.newBoard(new Move((short) 1, (short) 1, BoardI.VERTEX_BLACK));
@@ -271,7 +271,7 @@
for (int j = 0; j < Zobrist.MAX_BOARD_SIZE; j++)
for (int k = 0; k < Zobrist.MAX_COLOUR; k++) {
- BoardI board1 = new FasterBoard(false);
+ BoardI board1 = new SmallerBoard(false);
BoardI board2 = board1.newBoard(new Move((short) 1, (short) 1, BoardI.VERTEX_BLACK));
BoardI board3 = board1.newBoard(new Move((short) 1, (short) 1, BoardI.VERTEX_BLACK));
// BoardI board4 = board2.newBoard(new Move((short) 1, (short) 1, BoardI.VERTEX_BLACK));
Modified: trunk/jgogears/jgogears/TwoGTP.java
==============================================================================
--- trunk/jgogears/jgogears/TwoGTP.java (original)
+++ trunk/jgogears/jgogears/TwoGTP.java Mon Mar 10 21:42:36 2008
@@ -9,7 +9,7 @@
public class TwoGTP {
/** are we spewing debugging information? */
- public static final boolean DEBUG = true;
+ public static final boolean DEBUG = false;
/** The black player. */
private GTPInterface black = null;
@@ -22,8 +22,6 @@
private int passes = 0;
private boolean blackNext = true;
-
- private RuleSet rules = new NoKoRuleSet();
/**
* get the black
@@ -65,21 +63,17 @@
Move move = null;
if (this.blackNext) {
move = this.black.genMove(BoardI.VERTEX_BLACK, this.state);
- assert move != null;
- if (move.getPass())
- this.passes++;
- else
- this.passes = 0;
- this.blackNext = false;
} else {
move = this.white.genMove(BoardI.VERTEX_WHITE, this.state);
- assert move != null;
- if (move.getPass())
- this.passes++;
- else
- this.passes = 0;
- this.blackNext = true;
}
+ if (!RuleSet.DEFAULT.moveIsLegal(null, this.state.getBoard(), move))
+ throw new Error();
+ if (move.getPass())
+ this.passes++;
+ else
+ this.passes = 0;
+ this.blackNext = !this.blackNext;
+
if (DEBUG)
System.err.println("TwoGTP: played " + move);
if (DEBUG)
Modified: trunk/jgogears/jgogears/ZobristTest.java
==============================================================================
--- trunk/jgogears/jgogears/ZobristTest.java (original)
+++ trunk/jgogears/jgogears/ZobristTest.java Mon Mar 10 21:42:36 2008
@@ -220,7 +220,7 @@
* Test with board.
*/
public void testWithFastBoard() {
- BoardI board = new FastBoard(true);
+ 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());
@@ -238,7 +238,7 @@
* Test with board.
*/
public void testWithFasterBoard() {
- BoardI board = new FasterBoard(true);
+ BoardI board = new SmallerBoard(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));
assertTrue(board2.getZobrist().equals(board3.getZobrist()));
Modified: trunk/jgogears/jgogears/engine/Engine.java
==============================================================================
--- trunk/jgogears/jgogears/engine/Engine.java (original)
+++ trunk/jgogears/jgogears/engine/Engine.java Mon Mar 10 21:42:36 2008
@@ -26,7 +26,9 @@
Model model = new Model();
System.out.println("about to train model");
- new Trainer().train(20,model);
+ Trainer trainer = new Trainer();
+ trainer.setModel(model);
+ trainer.train(20);
System.out.println("model trained");
SufgoEngine black = new SufgoEngine();
@@ -39,6 +41,8 @@
two.setBlack(black);
two.setWhite(white);
+
+
for (int i = 0; i < 200; i++) {
state = two.move();
System.out.println(state.getBoard());
Modified: trunk/jgogears/jgogears/engine/Model.java
==============================================================================
--- trunk/jgogears/jgogears/engine/Model.java (original)
+++ trunk/jgogears/jgogears/engine/Model.java Mon Mar 10 21:42:36 2008
@@ -2,7 +2,6 @@
import java.util.*;
-import jgogears.*;
/**
* A probability model of Go
Modified: trunk/jgogears/jgogears/engine/ModelTest.java
==============================================================================
--- trunk/jgogears/jgogears/engine/ModelTest.java (original)
+++ trunk/jgogears/jgogears/engine/ModelTest.java Mon Mar 10 21:42:36 2008
@@ -31,7 +31,9 @@
public ModelTest() throws IOException {
if (model == null) {
model = new Model();
- new Trainer().train(2, model);
+ Trainer trainer = new Trainer();
+ trainer.setModel(model);
+ trainer.train(2);
}
}
@@ -233,7 +235,10 @@
public void testTrainedModel() throws IOException {
assertNotNull(model);
System.err.println("ModeTest::testTrainedModel() model size = " + model.getRoot().size());
- new Trainer().train(model, this.loadTestGame());
+ Trainer trainer = new Trainer();
+ trainer.setModel(model);
+ trainer.train(this.loadTestGame());
+
System.err.println("ModeTest::testTrainedModel() model size = " + model.getRoot().size());
BoardI board = BoardI.newBoard(19);
board = board.newBoard(new Move("white b2"));
@@ -264,7 +269,10 @@
public void testTrainedModelEmptyBoard() throws IOException {
assertNotNull(model);
System.err.println("ModeTest::testTrainedModelEmptyBoard() model
size = " + model.getRoot().size());
- new Trainer().train(model, this.loadTestGame());
+ Trainer trainer = new Trainer();
+ trainer.setModel(model);
+ trainer.train(this.loadTestGame());
+
System.err.println("ModeTest::testTrainedModelEmptyBoard() model
size = " + model.getRoot().size());
BoardI board = BoardI.newBoard(19);
double[][] r = new Scorer().getScores(model, board, false);
Modified: trunk/jgogears/jgogears/engine/Scorer.java
==============================================================================
--- trunk/jgogears/jgogears/engine/Scorer.java (original)
+++ trunk/jgogears/jgogears/engine/Scorer.java Mon Mar 10 21:42:36 2008
@@ -33,7 +33,8 @@
for (j = 0; j < board.getSize(); j++) {
if (result[i][j] < best) {
if (RuleSet.DEFAULT.moveIsLegal(null, board, new Move(i, j,
white ? BoardI.VERTEX_WHITE
- : BoardI.VERTEX_BLACK))) {
+ : BoardI.VERTEX_BLACK))
+ && best < result[i][j]) {
best = result[i][j];
I = i;
J = j;
@@ -56,12 +57,12 @@
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;
VertexLineariser linear = new VertexLineariser(board, row,
column, sym, white);
- double estimate = 1.0;
+ double estimate = 0.0;
int depth = 0;
while (linear.hasNext() && node != null) {
depth++;
@@ -104,7 +105,7 @@
// estimate = (1 + previous.getPlayed()) / (previous.getPlayed()
+ previous.getNotPlayed()) * (1 -
// (1 /depth));
- if (result[row][column] < estimate) {
+ if (result[row][column] <= estimate) {
result[row][column] = estimate;
if (DEBUG)
System.err.println("Model::getScores " + estimate);
Modified: trunk/jgogears/jgogears/engine/SufgoEngine.java
==============================================================================
--- trunk/jgogears/jgogears/engine/SufgoEngine.java (original)
+++ trunk/jgogears/jgogears/engine/SufgoEngine.java Mon Mar 10 21:42:36 2008
@@ -81,9 +81,7 @@
*/
public Move regGenMove(int colour, GTPState state) {
BoardI board = state.getBoard();
-
Vertex vertex = new Scorer().getBestScore(this.model, board, colour
== BoardI.VERTEX_WHITE);
-
return new Move(vertex.getRow(), vertex.getColumn(), colour);
}
Modified: trunk/jgogears/jgogears/engine/SufogoEngineTest.java
==============================================================================
--- trunk/jgogears/jgogears/engine/SufogoEngineTest.java (original)
+++ trunk/jgogears/jgogears/engine/SufogoEngineTest.java Mon Mar 10
21:42:36 2008
@@ -15,7 +15,7 @@
public class SufogoEngineTest extends TestCase {
/** The Constant DEBUG. */
- static final boolean DEBUG = true;
+ static final boolean DEBUG = false;
/**
* Test simple.
@@ -27,7 +27,9 @@
GTPState state = new GTPState();
Model model = new Model();
- new Trainer().train(10, model);
+ Trainer trainer = new Trainer();
+ trainer.setModel(model);
+ trainer.train(10);
SufgoEngine black = new SufgoEngine();
black.setModel(model);
Modified: trunk/jgogears/jgogears/engine/Trainer.java
==============================================================================
--- trunk/jgogears/jgogears/engine/Trainer.java (original)
+++ trunk/jgogears/jgogears/engine/Trainer.java Mon Mar 10 21:42:36 2008
@@ -9,7 +9,6 @@
import jgogears.*;
/**
- * TODO
*
* @author syeates
*/
@@ -17,15 +16,13 @@
static final private boolean DEBUG = false;
static final private boolean PROGRESS = true;
private boolean onlyOneNewNodePerSymmetry = true;
- private int minBranchSize = 20;
- private int defaultNumberOfFiles = Integer.MAX_VALUE;
+ public final int DEFAULT_NUMBER_OF_FILES = Integer.MAX_VALUE;
+ private Model model = null;
final public static String LIBRARY = "sgf/2004-12";
/**
* Loads all the default SGF files
*
- * @param directory
- * the directory to load
* @throws IOException
* Signals that an I/O exception has occurred.
* @return a Collection of Strings
@@ -80,14 +77,10 @@
/**
* Train on files.
*
- * @param model
- * the model
* @return the model
- * @throws IOException
- * Signals that an I/O exception has occurred.
*/
- public Model train(Model model) throws IOException {
- return train(defaultNumberOfFiles, model);
+ public Model train() {
+ return train(DEFAULT_NUMBER_OF_FILES);
}
/**
@@ -95,13 +88,10 @@
*
* @param count
* the count
- * @param model
- * the model
* @return the model
- * @throws IOException
- * Signals that an I/O exception has occurred.
*/
- public Model train(int count, Model model) throws IOException {
+ public Model train(int count) {
+ try {
Collection<String> files = loadAllSGFfiles();
int filecount = 0;
int examined = 0;
@@ -113,7 +103,7 @@
examined++;
if (game.getSize() == 19) {
filecount++;
- train(model, game);
+ train( game);
} else {
if (DEBUG)
System.err.print("!");
@@ -132,6 +122,10 @@
if (DEBUG)
System.err.println("\nTrainer::trainNFiles loaded " + filecount + " files ");
+ }catch (IOException e) {
+ System.err.println(e);
+ return null;
+ }
return model;
}
@@ -141,7 +135,7 @@
* @param game
* the game
*/
- public void train(Model model, Game game) {
+ public void train(Game game) {
short size = game.getSize();
Iterator<BoardI> boards = game.getBoards();
if (boards == null)
@@ -149,11 +143,9 @@
Iterator<Move> moves = game.getMoves();
if (moves == null)
throw new Error();
- int movecounter = 1;
model.setGamesTrained(model.getGamesTrained() + 1);
while (boards.hasNext() && moves.hasNext()) {
- movecounter++;
model.setBoardsTrained(model.getBoardsTrained() + 1);
BoardI board = boards.next();
if (board == null)
@@ -169,18 +161,23 @@
boolean isBlack = colour == BoardI.VERTEX_BLACK;
// float str = (float) (isBlack ? strengthB : strengthW);
- if (game != null && !move.getPass()) {
- movecounter++;
+ if (move != null)
+ if ( move.getPlay()){
for (short i = 0; i < size; i++)
for (short j = 0; j < size; j++)
for (short sym = 0; sym < 8; sym++) {
- // TODO this needs a lot of work, i think
-
VertexLineariser linear = new VertexLineariser(board, i, j, sym, !isBlack);
- if (!move.getPass() && move.getRow() != i &&
move.getColumn() != j)
- train(model.getRoot(), linear, true, true, 100);
+ if (move.getRow() != i && move.getColumn() != j)
+ train( linear, true, true, 100);//TODO
else
- train(model.getRoot(), linear, false, true, 30);
+ train( linear, false, true, 100);//TODO
+ }
+ } else if ( move.getPass()) {
+ for (short i = 0; i < size; i++)
+ for (short j = 0; j < size; j++)
+ for (short sym = 0; sym < 8; sym++) {
+ VertexLineariser linear = new VertexLineariser(board, i, j, sym, !isBlack);
+ train(linear, false, true, 100);//TODO
}
}
}
@@ -200,11 +197,12 @@
* @param playeda
* the played
*/
- public void train(Node root, VertexLineariser linear, boolean
playeda, boolean expand, int depth) {
+ public void train(VertexLineariser linear, boolean playeda, boolean
expand, int depth) {
+ Node root = model.getRoot();
while (root !=null && linear.hasNext()){
if (depth <= 0)
expand = false;
- if (root.getNotPlayed() + root.getPlayed() < minBranchSize)
+ if (root.getNotPlayed() + root.getPlayed() < this.getMinBranchSize())
expand = false;
depth--;
if (playeda)
@@ -290,37 +288,25 @@
*
* @return the minBranchSize
*/
- public final int getMinBranchSize() {
- return minBranchSize;
+ public final double getMinBranchSize() {
+ return model.getGamesTrained()*2 + 10;
}
- /**
- * set the minBranchSize
- *
- * @param minBranchSize
- * the minBranchSize to set
- */
- public final void setMinBranchSize(int minBranchSize) {
- this.minBranchSize = minBranchSize;
- }
/**
- * get the defaultNumberOfFiles
- *
- * @return the defaultNumberOfFiles
+ * get the model
+ * @return the model
*/
- public final int getDefaultNumberOfFiles() {
- return defaultNumberOfFiles;
+ public final Model getModel() {
+ return model;
}
/**
- * set the defaultNumberOfFiles
- *
- * @param defaultNumberOfFiles
- * the defaultNumberOfFiles to set
+ * set the model
+ * @param model the model to set
*/
- public final void setDefaultNumberOfFiles(int defaultNumberOfFiles) {
- this.defaultNumberOfFiles = defaultNumberOfFiles;
+ public final void setModel(Model model) {
+ this.model = model;
}
}
Modified: trunk/jgogears/jgogears/engine/TrainerTest.java
==============================================================================
--- trunk/jgogears/jgogears/engine/TrainerTest.java (original)
+++ trunk/jgogears/jgogears/engine/TrainerTest.java Mon Mar 10 21:42:36 2008
@@ -71,12 +71,13 @@
Trainer trainer = new Trainer();
assertNotNull(trainer);
Model model = new Model();
+ trainer.setModel(model);
assertNotNull(model);
- trainer.train(1, model);
+ trainer.train(1);
assertNotNull(trainer);
assertTrue(model.getGamesTrained() == 1);
assertTrue("" + model.getBoardsTrained(), model.getBoardsTrained()
> 1);
- } catch (IOException e) {
+ } catch (Throwable e) {
fail("" + e);
}
}
@@ -86,12 +87,13 @@
Trainer trainer = new Trainer();
assertNotNull(trainer);
Model model = new Model();
+ trainer.setModel(model);
assertNotNull(model);
- trainer.train(2, model);
+ trainer.train(2);
assertNotNull(trainer);
assertTrue(model.getGamesTrained() == 2);
assertTrue("" + model.getBoardsTrained(), model.getBoardsTrained()
> 1);
- } catch (IOException e) {
+ } catch (Throwable e) {
fail("" + e);
}
}
@@ -101,17 +103,18 @@
Trainer trainer = new Trainer();
assertNotNull(trainer);
Model model = new Model();
+ trainer.setModel(model);
assertNotNull(model);
- trainer.train(2, model);
+ trainer.train(2);
assertNotNull(model);
assertTrue(model.getGamesTrained() == 2);
assertTrue("" + model.getBoardsTrained(), model.getBoardsTrained()
> 20);
- trainer.train(2, model);
+ trainer.train(2);
assertNotNull(trainer);
assertNotNull(model);
assertTrue(model.getGamesTrained() == 4);
assertTrue("" + model.getBoardsTrained(), model.getBoardsTrained()
> 100);
- } catch (IOException e) {
+ } catch (Throwable e) {
fail("" + e);
}
}
Modified: trunk/jgogears/jgogears/engine/VertexLineariser.java
==============================================================================
--- trunk/jgogears/jgogears/engine/VertexLineariser.java (original)
+++ trunk/jgogears/jgogears/engine/VertexLineariser.java Mon Mar 10
21:42:36 2008
@@ -8,7 +8,7 @@
/**
* The Class VertexLineariser.
*/
-public class VertexLineariser implements Iterator<Short> {
+final public class VertexLineariser implements Iterator<Short> {
// Table of sequences
/** The cache. */
static private short[][][][][] cache = null;
@@ -43,6 +43,9 @@
/** Have the colours been inverted? */
boolean invert = false;
+
+ /** are we being verbose */
+ final static boolean PROGRESS = true;
/**
* Instantiates a new vertex lineariser.
@@ -159,7 +162,7 @@
column_offset = -SMALL_OFFSET;
break;
default:
- throw new Error();
+ throw new Error("VertexLineariser::init bad symmetry: " + sym);
}
double d = Math.pow(row - i + row_offset, 2) + Math.pow(column
- j + column_offset, 2);
@@ -190,9 +193,14 @@
}
if (values.size() > 0)
throw new Error("values should be empty but was " + values.size());
+ if (PROGRESS)
+ System.err.print(":");
}
}
// System.out.println();
+ if (PROGRESS)
+ System.err.println();
+
return true;
}
Modified: trunk/jgogears/jgogears/engine/VertexLineariserTest.java
==============================================================================
--- trunk/jgogears/jgogears/engine/VertexLineariserTest.java (original)
+++ trunk/jgogears/jgogears/engine/VertexLineariserTest.java Mon Mar 10
21:42:36 2008
@@ -31,8 +31,6 @@
* @return true, if successful
*/
boolean identicalLinearisation(BoardI board, short rowa, short
columna, short rowb, short columnb) {
- if (board == null)
- return false;
for (short j = 0; j < 8; j++) {
boolean matchFound = false;
for (short i = 0; i < 8; i++) {
@@ -381,6 +379,84 @@
result = this.identicalLinearisation(board, row, column, column, row);
assertTrue(result);
}
+ }
+
+ /**
+ * make sure that all the linearisations are different.
+ */
+ public void testEmptyBoardSymmetryReimplematation() {
+ BoardI board = BoardI.newBoard();
+ short size = board.getSize();
+ boolean matches[][][] = new boolean[3][8][8];
+
+ for (short sym1 = 0; sym1 < 8; sym1++) {
+
+ for (short sym2 = 0; sym2 < 8; sym2++) {
+ matches[0][sym1][sym2] = true;
+ Iterator<Short> lineara = new VertexLineariser(board, (short) 0,
(short) 0, sym1, false);
+ Iterator<Short> linearb = new VertexLineariser(board, (short)
(size - 1), (short) (size - 1), sym2,
+ false);
+ while (lineara.hasNext()) {
+ assertTrue(lineara.hasNext());
+ assertTrue(linearb.hasNext());
+ Short a = lineara.next();
+ Short b = linearb.next();
+ if (!a.equals(b))
+ matches[0][sym1][sym2] = false;
+ }
+ assertFalse(linearb.hasNext());
+ }
+
+ for (short sym2 = 0; sym2 < 8; sym2++) {
+ matches[1][sym1][sym2] = true;
+ Iterator<Short> lineara = new VertexLineariser(board, (short) 0,
(short) 0, sym1, false);
+ Iterator<Short> linearb = new VertexLineariser(board, (short) 0,
(short) (size - 1), sym2, false);
+ while (lineara.hasNext()) {
+ assertTrue(lineara.hasNext());
+ assertTrue(linearb.hasNext());
+ Short a = lineara.next();
+ Short b = linearb.next();
+ if (!a.equals(b))
+ matches[1][sym1][sym2] = false;
+ }
+ assertFalse(linearb.hasNext());
+ }
+
+ for (short sym2 = 0; sym2 < 8; sym2++) {
+ matches[2][sym1][sym2] = true;
+ Iterator<Short> lineara = new VertexLineariser(board, (short) 0,
(short) 0, sym1, false);
+ Iterator<Short> linearb = new VertexLineariser(board, (short)
(size - 1), (short) 0, sym2, false);
+ while (lineara.hasNext()) {
+ assertTrue(lineara.hasNext());
+ assertTrue(linearb.hasNext());
+ Short a = lineara.next();
+ Short b = linearb.next();
+ if (!a.equals(b))
+ matches[2][sym1][sym2] = false;
+ }
+ assertFalse(linearb.hasNext());
+ }
+ }
+ for (short corn = 0; corn < 3; corn++) {
+ for (short sym1 = 0; sym1 < 8; sym1++) {
+ boolean tfound= false;
+ boolean ffound= false;
+ for (short sym2 = 0; sym2 < 8; sym2++) {
+ if(DEBUG)
+ System.err.print(matches[corn][sym1][sym2] + " ");
+ if (matches[corn][sym1][sym2])
+ tfound = true;
+ else
+ ffound = true;
+ }
+ assertTrue(tfound);
+ assertTrue(ffound);
+ if(DEBUG)
+ System.err.println();
+ }
+ if(DEBUG)
+ System.err.println();
+ }
}
/**