Added:
trunk/jgogears/jgogears/engine/Engine.java
Modified:
trunk/jgogears/doc/TODO
trunk/jgogears/jgogears/AllTests.java
trunk/jgogears/jgogears/Board.java
trunk/jgogears/jgogears/BoardI.java
trunk/jgogears/jgogears/BoardTest.java
trunk/jgogears/jgogears/BoardToASCII.java
trunk/jgogears/jgogears/BoardToASCIITest.java
trunk/jgogears/jgogears/CachingKoRule.java
trunk/jgogears/jgogears/CopyOfRank.java
trunk/jgogears/jgogears/CopyOfRankToRating.java
trunk/jgogears/jgogears/CorpusBuilder.java
trunk/jgogears/jgogears/FastBoard.java
trunk/jgogears/jgogears/FastBoardTest.java
trunk/jgogears/jgogears/FasterBoard.java
trunk/jgogears/jgogears/FasterBoardTest.java
trunk/jgogears/jgogears/GTPConstants.java
trunk/jgogears/jgogears/GTPController.java
trunk/jgogears/jgogears/GTPEngine.java
trunk/jgogears/jgogears/GTPError.java
trunk/jgogears/jgogears/GTPHandicaps.java
trunk/jgogears/jgogears/GTPInterface.java
trunk/jgogears/jgogears/GTPInterfaceRaw.java
trunk/jgogears/jgogears/GTPParserUtils.java
trunk/jgogears/jgogears/GTPParserUtilsTest.java
trunk/jgogears/jgogears/GTPScore.java
trunk/jgogears/jgogears/GTPState.java
trunk/jgogears/jgogears/Game.java
trunk/jgogears/jgogears/GlobalTests.java
trunk/jgogears/jgogears/GnuGoEngine.java
trunk/jgogears/jgogears/GnuGoEngineTest2.java
trunk/jgogears/jgogears/GnuGoSeki.java
trunk/jgogears/jgogears/Move.java
trunk/jgogears/jgogears/MoveTest.java
trunk/jgogears/jgogears/NoKoRuleSet.java
trunk/jgogears/jgogears/NoKoRuleSetTest.java
trunk/jgogears/jgogears/RandomEngine.java
trunk/jgogears/jgogears/Rank.java
trunk/jgogears/jgogears/RuleSet.java
trunk/jgogears/jgogears/SGFGameTest.java
trunk/jgogears/jgogears/SGFGameTree.java
trunk/jgogears/jgogears/SGFNode.java
trunk/jgogears/jgogears/SGFNodeTest.java
trunk/jgogears/jgogears/SGFParser.java
trunk/jgogears/jgogears/SGFParserTest.java
trunk/jgogears/jgogears/SGFProperty.java
trunk/jgogears/jgogears/SGFPropertyTest.java
trunk/jgogears/jgogears/SGFSequence.java
trunk/jgogears/jgogears/SkeletonEngine.java
trunk/jgogears/jgogears/TwoGTP.java
trunk/jgogears/jgogears/TwoGTPRaw.java
trunk/jgogears/jgogears/TwoGTPTest.java
trunk/jgogears/jgogears/Vertex.java
trunk/jgogears/jgogears/Zobrist.java
trunk/jgogears/jgogears/ZobristTest.java
trunk/jgogears/jgogears/engine/Model.java
trunk/jgogears/jgogears/engine/ModelTest.java
trunk/jgogears/jgogears/engine/Node.java
trunk/jgogears/jgogears/engine/NodeIterator.java
trunk/jgogears/jgogears/engine/NodeIteratorTest.java
trunk/jgogears/jgogears/engine/NodeTest.java
trunk/jgogears/jgogears/engine/SufgoEngine.java
trunk/jgogears/jgogears/engine/SufogoEngineTest.java
trunk/jgogears/jgogears/engine/TreeIterator.java
trunk/jgogears/jgogears/engine/TreeIteratorTest.java
trunk/jgogears/jgogears/engine/VertexLineariser.java
trunk/jgogears/jgogears/engine/VertexLineariserTest.java
Log:
many updates. more tests of model and lineariser. formatting updates,
TODO updates. new commandline program. Now plays something that looks
like go
Modified: trunk/jgogears/doc/TODO
==============================================================================
--- trunk/jgogears/doc/TODO (original)
+++ trunk/jgogears/doc/TODO Tue Mar 4 22:17:01 2008
@@ -1,6 +1,12 @@
TODO
====
+Short Term
+* fix java compiler style warnings (javadoc etc)
+* trace lack of symmetry in testTrainedModelEmptyBoard
+* work on ASCIIToBoard -> BoardI round triping
+* update javacc generated files in svn (eclipse javacc plugin is
preventing this happening)
+
SGF Support
* parse tt in SGF files
* work out the differences between SGF 3 and 4
Modified: trunk/jgogears/jgogears/AllTests.java
==============================================================================
--- trunk/jgogears/jgogears/AllTests.java (original)
+++ trunk/jgogears/jgogears/AllTests.java Tue Mar 4 22:17:01 2008
@@ -8,12 +8,11 @@
* @author syeates
*/
public class AllTests {
-
+
/**
* Package-wide test collection.
*
* @return the test
- *
* @author syeates
*/
Modified: trunk/jgogears/jgogears/Board.java
==============================================================================
--- trunk/jgogears/jgogears/Board.java (original)
+++ trunk/jgogears/jgogears/Board.java Tue Mar 4 22:17:01 2008
@@ -1,8 +1,5 @@
package jgogears;
-
-
-
/**
* GoBoard represents the state of a Go board at a particular point in
time. It does NOT represent the number of
* prisoners, the number (or order) of previous moves or whose turn it
is too play.
@@ -19,7 +16,6 @@
/** The actual board, of size size. */
private short[][] board = null;
-
/**
* Default constructor.
@@ -29,9 +25,24 @@
}
/**
+ * create a new board based on the current board plus a move.
+ *
+ * @param board
+ * the move
+ * @param move
+ * the move
+ */
+ public Board(Board board, Move move) {
+ this.size = board.getSize();
+ this.init();
+ this.copydata(board, move);
+ }
+
+ /**
* Default constructor.
*
- * @param zobrist the zobrist
+ * @param zobrist
+ * the zobrist
*/
public Board(boolean zobrist) {
super(zobrist);
@@ -41,11 +52,10 @@
/**
* constructor of specially sized boards.
*
- * @param size the size
- * @param zobrist true if we're using zobrist hashes
+ * @param size
+ * the size
*/
- public Board(int size, boolean zobrist) {
- super(zobrist);
+ public Board(int size) {
this.size = (short) size;
this.init();
}
@@ -53,9 +63,13 @@
/**
* constructor of specially sized boards.
*
- * @param size the size
+ * @param size
+ * the size
+ * @param zobrist
+ * true if we're using zobrist hashes
*/
- public Board(int size) {
+ public Board(int size, boolean zobrist) {
+ super(zobrist);
this.size = (short) size;
this.init();
}
@@ -63,8 +77,10 @@
/**
* constructor of specially sized boards.
*
- * @param size the size
- * @param rule the rule
+ * @param size
+ * the size
+ * @param rule
+ * the rule
*/
public Board(int size, RuleSet rule) {
this.size = (short) size;
@@ -75,9 +91,12 @@
/**
* constructor of specially sized boards.
*
- * @param size the size
- * @param rule the rule
- * @param zobrist true if we're using zobrist hashes
+ * @param size
+ * the size
+ * @param rule
+ * the rule
+ * @param zobrist
+ * true if we're using zobrist hashes
*/
public Board(int size, RuleSet rule, boolean zobrist) {
super(zobrist);
@@ -85,34 +104,12 @@
this.ruleSet = rule;
this.init();
}
- /**
- * create a new board based on the current board plus a move.
- *
- * @param move the move
- *
- * @return the new board
- */
- public final Board newBoard( Move move) {
- return new Board(this,move);
- }
-
- /**
- * create a new board based on the current board plus a move.
- *
- * @param board the move
- * @param move the move
- *
- */
- public Board(Board board , Move move) {
- this.size = board.getSize();
- init();
- copydata(board,move);
- }
/**
* Default constructor.
*
- * @param rule the rule
+ * @param rule
+ * the rule
*/
public Board(RuleSet rule) {
this.ruleSet = rule;
@@ -122,7 +119,8 @@
/**
* Instantiates a new board.
*
- * @param size the size
+ * @param size
+ * the size
*/
public Board(short size) {
this.size = size;
@@ -132,8 +130,10 @@
/**
* constructor of specially sized boards.
*
- * @param size the size
- * @param rule the rule
+ * @param size
+ * the size
+ * @param rule
+ * the rule
*/
public Board(short size, RuleSet rule) {
this.size = size;
@@ -141,17 +141,15 @@
this.init();
}
-
@Override
public short getColour(int row, int column) {
// System.err.println("getColour() " + " " + row + " " + column
+ " " +
// size);
- if ((row < 0) || (column < 0) || (row >= this.size) || (column >= this.size))
+ if (row < 0 || column < 0 || row >= this.size || column >= this.size)
return VERTEX_OFF_BOARD;
return this.board[row][column];
}
-
/*
* (non-Javadoc)
*
@@ -172,24 +170,38 @@
this.board[i][j] = VERTEX_EMPTY;
}
+ /**
+ * create a new board based on the current board plus a move.
+ *
+ * @param move
+ * the move
+ * @return the new board
+ */
+ @Override
+ public final Board newBoard(Move move) {
+ return new Board(this, move);
+ }
/**
* Sets the colour of a vertex
*
- * @param row the row
- * @param column the column
- * @param colour the colour
- *
+ * @param row
+ * the row
+ * @param column
+ * the column
+ * @param colour
+ * the colour
*/
+ @Override
public void setColour(int row, int column, short colour) {
-// if (CHECK)
-// if ((row >= this.getSize()) || (row < 0))
-// throw new Error("Bad board size " + row + "/" + this.getSize() + " ");
-// if (CHECK)
-// if ((column >= this.getSize()) || (column < 0))
-// throw new Error("Bad board size or play off the edge of the
board (remember we're zero indexed) "
-// + column + "/" + this.getSize() + " ");
+ // if (CHECK)
+ // if ((row >= this.getSize()) || (row < 0))
+ // throw new Error("Bad board size " + row + "/" + this.getSize() + " ");
+ // if (CHECK)
+ // if ((column >= this.getSize()) || (column < 0))
+ // throw new Error("Bad board size or play off the edge of the board
(remember we're zero indexed) "
+ // + column + "/" + this.getSize() + " ");
this.board[row][column] = colour;
}
@@ -203,6 +215,5 @@
public String toString() {
return BoardToASCII.Transform(this);
}
-
}
Modified: trunk/jgogears/jgogears/BoardI.java
==============================================================================
--- trunk/jgogears/jgogears/BoardI.java (original)
+++ trunk/jgogears/jgogears/BoardI.java Tue Mar 4 22:17:01 2008
@@ -2,8 +2,6 @@
import java.util.*;
-
-
/**
* Abstract interface to a board. Knows about the size of the board,
which stones are where, and about colours. Knows
* nothing of the history of the board or whose turn it is to play.
@@ -14,36 +12,142 @@
/** The default board size. */
public static final short DEFAULT_BOARD_SIZE = 19;
-
+
/** The MAXIMUM value for a vertex colour. */
public static final short VERTEX_MAX = 4;
-
+
/** A vertex in ko. */
public static final short VERTEX_OFF_BOARD = 4;
-
+
/** A vertex in ko. */
public static final short VERTEX_KO = 3;
-
+
/** A vertex with a black stone. */
public static final short VERTEX_BLACK = 2;
-
+
/** A vertex with a white stone. */
public static final short VERTEX_WHITE = 1;
-
+
/** A vertex without a stone (and not in KO. */
public static final short VERTEX_EMPTY = 0;
-
+
/** The MINIMUM value for a vertex colour. */
public static final short VERTEX_MIN = 0;
-
+
/** The Constant DEFAULT_ZOBRIST. */
public final static boolean DEFAULT_ZOBRIST = true;
/**
- * parse the colour of a move.
+ * Colour string.
+ *
+ * @param colour
+ * the colour
+ * @return the colour as a string
+ */
+ public static String colourString(int colour) {
+ // find the colour of the move
+ String colourS = "";
+ switch (colour) {
+ case BoardI.VERTEX_WHITE:
+ colourS = "white";
+ break;
+ case BoardI.VERTEX_BLACK:
+ colourS = "black";
+ break;
+ case BoardI.VERTEX_KO:
+ colourS = "ko";
+ break;
+ case BoardI.VERTEX_EMPTY:
+ colourS = "empty";
+ break;
+ case BoardI.VERTEX_OFF_BOARD:
+ colourS = "off board";
+ break;
+ default:
+ throw new java.lang.InternalError();
+ }
+ return colourS;
+ }
+
+ /**
+ * create an empty board of the default class
+ *
+ * @return the new empty board
+ */
+ public static BoardI newBoard() {
+ return new FasterBoard(DEFAULT_BOARD_SIZE);
+ }
+
+ /**
+ * create an empty board of the default class
+ *
+ * @param zobrist
+ * are we using a zobrist hash?
+ * @return the new empty board
+ */
+ public static BoardI newBoard(boolean zobrist) {
+ return new FasterBoard(zobrist);
+ }
+
+ /**
+ * create an empty board of the default class
+ *
+ * @param size
+ * the size of the board
+ * @return the new empty board
+ */
+ public static BoardI newBoard(int size) {
+ return new FasterBoard((short) size);
+ }
+
+ /**
+ * create an empty board of the default class
+ *
+ * @param size
+ * the size of the board
+ * @param rule
+ * the ruleset to use
+ * @param zobrist
+ * are we using a zobrist hash?
+ * @return the new empty board
+ */
+ public static BoardI newBoard(int size, boolean zobrist) {
+ return new FasterBoard((short) size, zobrist);
+ }
+
+ /**
+ * create an empty board of the default class
*
- * @param colourString the colour string
+ * @param size
+ * the size of the board
+ * @param rule
+ * the ruleset to use
+ * @return the new empty board
+ */
+ public static BoardI newBoard(int size, RuleSet rule) {
+ return new FasterBoard((short) size, rule);
+ }
+
+ /**
+ * create an empty board of the default class
+ *
+ * @param size
+ * the size of the board
+ * @param rule
+ * the ruleset to use
+ * @param zobrist
+ * are we using a zobrist hash?
+ * @return the new empty board
+ */
+ public static BoardI newBoard(int size, RuleSet rule, boolean
zobrist) {
+ return new FasterBoard((short) size, rule, zobrist);
+ }
+
+ /**
+ * parse the colour of a move.
*
+ * @param colourString
+ * the colour string
* @return the colour as a short
*/
public static short parseColour(String colourString) {
@@ -64,6 +168,12 @@
/** The zobrist. */
protected Zobrist zobrist = null;
+ /** the size of the board. */
+ protected short size = 19;
+
+ /** the ruleset. */
+ protected RuleSet ruleSet = new NoKoRuleSet();
+
/**
* Instantiates a new board
*/
@@ -75,49 +185,153 @@
/**
* The Constructor.
*
- * @param zobrist the zobrist
+ * @param zobrist
+ * the zobrist
*/
public BoardI(boolean zobrist) {
this.zobrist = new Zobrist();
}
/**
- * get the colour of a vertex.
+ * create a new board based on the current board plus a move.
*
- * @param row the row
- * @param column the column
+ * @param move
+ * the move
+ */
+ protected void copydata(BoardI old, Move move) {
+ this.size = old.getSize();
+ if (this.size < 3 || this.size > 25)
+ throw new Error();
+ this.zobrist = old.getZobrist();
+ this.ruleSet = old.getRuleSet();
+
+ for (short i = 0; i < this.size; i++)
+ for (short j = 0; j < this.size; j++) {
+ short colour = old.getColour(i, j);
+ if (colour == VERTEX_KO)
+ this.setColour(i, j, VERTEX_EMPTY);
+ else
+ this.setColour(i, j, colour);
+ }
+ if (move == null)
+ return;
+ if (move.getResign()) {
+ return;
+ } else if (move.getPass()) {
+ // do nothing, since GoBoard doesn't know whose turn it is
+ } else {
+ // place the stone
+ if (move.getColumn() >= this.size || move.getRow() >= this.size)
+ throw new Error();
+ this.setColour(move.getRow(), move.getColumn(), move.getColour());
+ if (this.zobrist != null)
+ this.setZobrist(new Zobrist(this.zobrist, move.getRow(),
move.getColumn(), BoardI.VERTEX_EMPTY));
+
+ // take the captures
+ TreeSet<Vertex> captures = old.getRuleSet().captures(null, old, move);
+ if (captures.size() > 0) {
+ // System.err.println("captured" + captures);
+ Iterator<Vertex> i = captures.iterator();
+ while (i.hasNext()) {
+ Vertex v = i.next();
+ // System.err.println("captured" + v);
+ this.setColour(v.getRow(), v.getColumn(), BoardI.VERTEX_EMPTY);
+
+ if (this.zobrist != null)
+ this.setZobrist(new Zobrist(this.getZobrist(), v.getRow(),
v.getColumn(), BoardI.VERTEX_EMPTY));
+ }
+ }
+ // mark the kos
+ TreeSet<Vertex> kos = old.getRuleSet().leavesKo(null, old, move);
+ if (kos.size() > 0) {
+ // System.err.println("captured" + captures);
+ Iterator<Vertex> i = kos.iterator();
+ while (i.hasNext()) {
+ Vertex v = i.next();
+ // System.err.println("captured" + v);
+ this.setColour(v.getRow(), v.getColumn(), BoardI.VERTEX_KO);
+
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj.getClass() != this.getClass())
+ return super.equals(obj);
+ BoardI other = (BoardI) obj;
+ if (other == null)
+ throw new Error();
+ if (this.size != other.size)
+ return false;
+ if (this.getZobrist() != null && other.getZobrist() != null)
+ return this.getZobrist().equals(other.getZobrist());
+ for (int i = 0; i < this.size; i++)
+ for (int j = 0; j < this.size; j++)
+ if (this.getColour(i, j) != other.getColour(i, j))
+ return false;
+ return true;
+ }
+
+ /**
+ * Get a collection of all the legal moves
*
- * @return the colour
+ * @param rules
+ * the ruleset in use
+ * @param colour
+ * the colour of the move we want to play
+ * @return
*/
- public short getColour(Vertex v){
- return this.getColour(v.getRow(), v.getColumn());
+ public Collection<Move> getAllLegalMoves(RuleSet rules, short colour) {
+ return rules.getAllLegalMoves(null, this, colour);
}
/**
- * get the colour of a vertex.
+ * Get a collection of all the legal moves
*
- * @param row the row
- * @param column the column
+ * @param rules
+ * the ruleset in use
+ * @param colour
+ * the colour of the move we want to play
+ * @return
+ */
+
+ public Collection<Vertex> getAllLegalVertexes(RuleSet rules, short
colour) {
+ return rules.getAllLegalVertexes(null, this, colour);
+ }
+
+ /**
+ * get the colour of a vertex.
*
+ * @param row
+ * the row
+ * @param column
+ * the column
* @return the colour
*/
public abstract short getColour(int row, int column);
/**
- * set the colour of a vertex.
- *
- * @param row the row
- * @param column the column
- * @param colour the colour to set this to
+ * get the colour of a vertex.
*
+ * @param row
+ * the row
+ * @param column
+ * the column
+ * @return the colour
*/
- public abstract void setColour(int row, int column, short colour);
-
- public Collection<Move> getAllLegalMoves(RuleSet rules, short colour){
- return rules.getAllLegalMoves(null, this, colour);
+ public short getColour(Vertex v) {
+ return this.getColour(v.getRow(), v.getColumn());
}
- public Collection<Vertex> getAllLegalVertexes(RuleSet rules, short colour){
- return rules.getAllLegalVertexes(null, this, colour);
+
+ /**
+ * get the ruleSet
+ *
+ * @return the ruleSet
+ */
+ public final RuleSet getRuleSet() {
+ return this.ruleSet;
}
/**
@@ -125,13 +339,9 @@
*
* @return the size
*/
- public short getSize(){
- return size;
+ public short getSize() {
+ return this.size;
}
-
- /** the size of the board. */
- protected short size = 19;
-
/**
* Gets the zobrist.
@@ -142,107 +352,35 @@
return this.zobrist;
}
-
/**
- * Sets the zobrist.
+ * create a new board based on the current board plus a move.
*
- * @param zobrist the zobrist
+ * @param move
+ * the move
+ * @return the new board
*/
- protected void setZobrist(Zobrist zobrist) {
- this.zobrist = zobrist;
- }
-
- /** the ruleset. */
- protected RuleSet ruleSet = new NoKoRuleSet();
-
+ abstract public BoardI newBoard(Move move);
- @Override
- public boolean equals(Object obj) {
- if (obj.getClass() != this.getClass())
- return super.equals(obj);
- BoardI other = (BoardI) obj;
- if (other == null)
- throw new Error();
- if (this.size != other.size)
- return false;
- if (this.getZobrist() != null && other.getZobrist() != null)
- return this.getZobrist().equals(other.getZobrist());
- for (int i=0;i<size;i++)
- for (int j=0;j<size;j++)
- if (this.getColour(i, j) != other.getColour(i, j))
- return false;
- return true;
- }
-
/**
- * create a new board based on the current board plus a move.
- *
- * @param move the move
+ * set the colour of a vertex.
*
- * @return the new board
+ * @param row
+ * the row
+ * @param column
+ * the column
+ * @param colour
+ * the colour to set this to
*/
- abstract public BoardI newBoard( Move move);
- /**
- * create a new board based on the current board plus a move.
- *
- * @param move the move
- *
- */
- protected void copydata(BoardI old , Move move) {
- size = old.getSize();
- if (size <3 || size >25)
- throw new Error();
- zobrist = old.getZobrist();
- ruleSet = old.getRuleSet();
-
- for (short i = 0; i < size; i++)
- for (short j = 0; j < size; j++){
- short colour = old.getColour(i, j);
- if (colour == VERTEX_KO)
- this.setColour(i, j, VERTEX_EMPTY);
- else
- this.setColour(i, j, colour);
- }
- if (move == null)
- return;
- if (move.getResign()) {
- return;
- } else if (move.getPass()) {
- // do nothing, since GoBoard doesn't know whose turn it is
- } else {
- // place the stone
- if (move.getColumn() >= size || move.getRow() >= size)
- throw new Error();
- this.setColour(move.getRow(), move.getColumn(), move.getColour());
- if (zobrist != null)
- setZobrist(new Zobrist(this.zobrist, move.getRow(),
move.getColumn(), BoardI.VERTEX_EMPTY));
-
- // take the captures
- TreeSet<Vertex> captures = old.getRuleSet().captures(null, old, move);
- if (captures.size() > 0){
- //System.err.println("captured" + captures);
- Iterator<Vertex> i = captures.iterator();
- while (i.hasNext()) {
- Vertex v = i.next();
- //System.err.println("captured" + v);
- if (captures.size() == 1)
- this.setColour(v.getRow(), v.getColumn(), BoardI.VERTEX_KO);
- else
- this.setColour(v.getRow(), v.getColumn(), BoardI.VERTEX_EMPTY);
-
- if (this.zobrist != null)
- this.setZobrist(new Zobrist(this.getZobrist(), v.getRow(),
v.getColumn(), BoardI.VERTEX_EMPTY));
- }
- }
- }
- }
+ public abstract void setColour(int row, int column, short colour);
/**
- * get the ruleSet
- * @return the ruleSet
+ * Sets the zobrist.
+ *
+ * @param zobrist
+ * the zobrist
*/
- public final RuleSet getRuleSet() {
- return ruleSet;
+ protected void setZobrist(Zobrist zobrist) {
+ this.zobrist = zobrist;
}
}
Modified: trunk/jgogears/jgogears/BoardTest.java
==============================================================================
--- trunk/jgogears/jgogears/BoardTest.java (original)
+++ trunk/jgogears/jgogears/BoardTest.java Tue Mar 4 22:17:01 2008
@@ -11,7 +11,7 @@
* @author Stuart
*/
public class BoardTest extends TestCase {
-
+
/**
* Test all sizes.
*/
@@ -39,10 +39,11 @@
/**
* Test all vertexes n.
*
- * @param size the size
+ * @param size
+ * the size
*/
public void testAllVertexesN(int size) {
- BoardI board = new Board(size);
+ BoardI board = BoardI.newBoard(size);
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
@@ -52,7 +53,7 @@
for (int l = 0; l < size; l++) {
for (int m = 0; m < size; m++) {
- if ((l != i) && (m != j))
+ if (l != i && m != j)
assertTrue(board.getColour(l, m) == BoardI.VERTEX_EMPTY);
}
}
@@ -62,7 +63,7 @@
for (int l = 0; l < size; l++) {
for (int m = 0; m < size; m++) {
- if ((l != i) && (m != j))
+ if (l != i && m != j)
assertTrue(board.getColour(i, j) == BoardI.VERTEX_EMPTY);
}
}
@@ -72,7 +73,7 @@
for (int l = 0; l < size; l++) {
for (int m = 0; m < size; m++) {
- if ((l != i) && (m != j))
+ if (l != i && m != j)
assertTrue(board.getColour(l, m) == BoardI.VERTEX_EMPTY);
}
}
@@ -82,7 +83,7 @@
for (int l = 0; l < size; l++) {
for (int m = 0; m < size; m++) {
- if ((l != i) && (m != j))
+ if (l != i && m != j)
assertTrue(board.getColour(l, m) == BoardI.VERTEX_EMPTY);
}
}
@@ -92,7 +93,7 @@
for (int l = 0; l < size; l++) {
for (int m = 0; m < size; m++) {
- if ((l != i) && (m != j))
+ if (l != i && m != j)
assertTrue(board.getColour(l, m) == BoardI.VERTEX_EMPTY);
}
}
@@ -136,9 +137,52 @@
}
/**
+ * Test each undoable ii.
+ */
+ public void testEachUndoableII() {
+ for (int i = 0; i < Zobrist.MAX_BOARD_SIZE; i++)
+ for (int j = 0; j < Zobrist.MAX_BOARD_SIZE; j++)
+ for (int k = 0; k < Zobrist.MAX_COLOUR; k++) {
+
+ BoardI board1 = new Board(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));
+
+ assertFalse(board1.equals(board2));
+ assertFalse(board1.equals(board3));
+ assertTrue(board1.equals(board4));
+ assertTrue(board2.equals(board3));
+
+ }
+ }
+
+ /**
+ * Test each undoable ii.
+ */
+ public void testEachUndoableIII() {
+ for (int i = 0; i < Zobrist.MAX_BOARD_SIZE; i++)
+ for (int j = 0; j < Zobrist.MAX_BOARD_SIZE; j++)
+ for (int k = 0; k < Zobrist.MAX_COLOUR; k++) {
+
+ BoardI board1 = new Board(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));
+
+ assertFalse(board1.equals(board2));
+ assertFalse(board1.equals(board3));
+ assertTrue(board1.equals(board4));
+ assertTrue(board2.equals(board3));
+
+ }
+ }
+
+ /**
* Loads a ton of SGF files and tests the resulting boards
*
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
public void testLoadAllSGFfiles() throws IOException {
Stack<String> files = new Stack<String>();
@@ -189,51 +233,10 @@
}
/**
- * Test each undoable ii.
- */
- public void testEachUndoableII() {
- for (int i = 0; i < Zobrist.MAX_BOARD_SIZE; i++)
- for (int j = 0; j < Zobrist.MAX_BOARD_SIZE; j++)
- for (int k = 0; k < Zobrist.MAX_COLOUR; k++) {
-
- BoardI board1 = new Board(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));
-
- assertFalse(board1.equals(board2));
- assertFalse(board1.equals(board3));
- assertTrue(board1.equals(board4));
- assertTrue(board2.equals(board3));
-
- }
- }
-
- /**
- * Test each undoable ii.
- */
- public void testEachUndoableIII() {
- for (int i = 0; i < Zobrist.MAX_BOARD_SIZE; i++)
- for (int j = 0; j < Zobrist.MAX_BOARD_SIZE; j++)
- for (int k = 0; k < Zobrist.MAX_COLOUR; k++) {
-
- BoardI board1 = new Board(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));
-
- assertFalse(board1.equals(board2));
- assertFalse(board1.equals(board3));
- assertTrue(board1.equals(board4));
- assertTrue(board2.equals(board3));
-
- }
- }
-
- /**
* Test load simple gnugo.
*
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
public void testLoadSimpleGnugo() throws IOException {
Modified: trunk/jgogears/jgogears/BoardToASCII.java
==============================================================================
--- trunk/jgogears/jgogears/BoardToASCII.java (original)
+++ trunk/jgogears/jgogears/BoardToASCII.java Tue Mar 4 22:17:01 2008
@@ -41,14 +41,14 @@
*/
static boolean isEyeVertex(short row, short column, short size) {
if (size == 19) {
- if ((row == 4) || (row == 9) || (row == 16))
- if ((column == 4) || (column == 9) || (column == 16))
+ if (row == 4 || row == 9 || row == 16)
+ if (column == 4 || column == 9 || column == 16)
return true;
return false;
}
if (size == 7) {
- if ((row == 2) || (row == 4) )
- if ((column == 2) || (column == 4))
+ if (row == 2 || row == 4)
+ if (column == 2 || column == 4)
return true;
return false;
}
Modified: trunk/jgogears/jgogears/BoardToASCIITest.java
==============================================================================
--- trunk/jgogears/jgogears/BoardToASCIITest.java (original)
+++ trunk/jgogears/jgogears/BoardToASCIITest.java Tue Mar 4 22:17:01 2008
@@ -18,7 +18,7 @@
* Test empty.
*/
public void testEmpty() {
- BoardI board = new Board();
+ BoardI board = BoardI.newBoard();
String string = BoardToASCII.Transform(board);
assertNotNull(board);
assertNotNull(string);
@@ -36,7 +36,7 @@
* Test one.
*/
public void testOne() {
- BoardI board = new Board();
+ BoardI board = BoardI.newBoard();
board = board.newBoard(new Move("w b1"));
String string = BoardToASCII.Transform(board);
assertNotNull(board);
Modified: trunk/jgogears/jgogears/CachingKoRule.java
==============================================================================
--- trunk/jgogears/jgogears/CachingKoRule.java (original)
+++ trunk/jgogears/jgogears/CachingKoRule.java Tue Mar 4 22:17:01 2008
@@ -2,27 +2,29 @@
import java.util.TreeSet;
-
/**
* A RuleSet that caches the results to speed things up.
*
* @author syeates
*/
public class CachingKoRule extends RuleSet {
-
+
/** the inner ruleset. */
private final RuleSet rule;
/**
* The constructor, passing in the inner rule whose results are cached.
*
- * @param rule the inner rule whose results are cached
+ * @param rule
+ * the inner rule whose results are cached
*/
public CachingKoRule(RuleSet rule) {
this.rule = rule;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.RuleSet#captures(jgogears.Game, jgogears.BoardI, jgogears.Move)
*/
@Override
@@ -30,7 +32,9 @@
return this.rule.captures(game, Board, move);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.RuleSet#getDescription()
*/
@Override
@@ -38,7 +42,9 @@
return this.rule.getDescription() + "+ caching";
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.RuleSet#getLiberties(short, short, jgogears.BoardI)
*/
@Override
@@ -46,7 +52,9 @@
return this.rule.getLiberties(rowb, columnb, board);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.RuleSet#getName()
*/
@Override
@@ -54,7 +62,9 @@
return this.rule.getName() + "+ caching";
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.RuleSet#getString(short, short, jgogears.BoardI)
*/
@Override
@@ -62,7 +72,9 @@
return this.rule.getString(row, column, board);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.RuleSet#leavesKo(jgogears.Game, jgogears.BoardI, jgogears.Move)
*/
@Override
@@ -70,7 +82,9 @@
return this.rule.leavesKo(game, Board, move);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.RuleSet#moveIsLegal(jgogears.Game, jgogears.BoardI, jgogears.Move)
*/
@Override
Modified: trunk/jgogears/jgogears/CopyOfRank.java
==============================================================================
--- trunk/jgogears/jgogears/CopyOfRank.java (original)
+++ trunk/jgogears/jgogears/CopyOfRank.java Tue Mar 4 22:17:01 2008
@@ -1,6 +1,5 @@
package jgogears;
-
/**
* Class representing dan / kyu ranks. 20000kyu to 1kyu and 1dan to
99dan. Classes are represented internally as a
* double. Rank parsing and formatting are only supported for whole numbers.
@@ -12,22 +11,22 @@
/** The Constant SHODAN. */
public final static CopyOfRank SHODAN = new CopyOfRank("1d");
-
+
/** The Constant BEGINNER. */
public final static CopyOfRank BEGINNER = new CopyOfRank("25k");
-
+
/** The Constant ME. */
public final static CopyOfRank ME = new CopyOfRank("12k");
/**
* Convert.
*
- * @param r the r
- *
+ * @param r
+ * the r
* @return the int
*/
public static int convert(String r) {
- if ((r == null) || (r.length() < 2))
+ if (r == null || r.length() < 2)
throw new Error();
r = r.toLowerCase();
int offset = 0;
@@ -57,7 +56,8 @@
/**
* Instantiates a new copy of rank.
*
- * @param r the r
+ * @param r
+ * the r
*/
public CopyOfRank(double r) {
this.rank = r;
@@ -66,7 +66,8 @@
/**
* Instantiates a new copy of rank.
*
- * @param r the r
+ * @param r
+ * the r
*/
public CopyOfRank(String r) {
this.rank = convert(r);
@@ -84,13 +85,16 @@
/**
* Sets the rank.
*
- * @param rank the new rank
+ * @param rank
+ * the new rank
*/
public void setRank(double rank) {
this.rank = rank;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Object#toString()
*/
@Override
Modified: trunk/jgogears/jgogears/CopyOfRankToRating.java
==============================================================================
--- trunk/jgogears/jgogears/CopyOfRankToRating.java (original)
+++ trunk/jgogears/jgogears/CopyOfRankToRating.java Tue Mar 4 22:17:01 2008
@@ -9,8 +9,8 @@
/**
* Rank to rating.
*
- * @param S the s
- *
+ * @param S
+ * the s
* @return the double
*/
public static final double rankToRating(String S) {
Modified: trunk/jgogears/jgogears/CorpusBuilder.java
==============================================================================
--- trunk/jgogears/jgogears/CorpusBuilder.java (original)
+++ trunk/jgogears/jgogears/CorpusBuilder.java Tue Mar 4 22:17:01 2008
@@ -4,21 +4,19 @@
import java.util.*;
import java.util.zip.*;
-
/**
- * The Class CorpusBuilder.
- * troll through a directory hierarchy containing SGF files and
archives of scoff
- files. Each file is parsed as an SGF file and copied to a directory
if it meets
-the tests
+ * The Class CorpusBuilder. troll through a directory hierarchy
containing SGF files and archives of scoff files. Each
+ * file is parsed as an SGF file and copied to a directory if it meets
the tests
*/
public class CorpusBuilder {
/**
* The main method.
*
- * @param args the arguments
- *
- * @throws Exception the exception
+ * @param args
+ * the arguments
+ * @throws Exception
+ * the exception
*/
public static void main(String[] args) throws Exception {
CorpusBuilder builder = new CorpusBuilder();
@@ -30,9 +28,10 @@
/**
* Mainold.
*
- * @param args the args
- *
- * @throws Exception the exception
+ * @param args
+ * the args
+ * @throws Exception
+ * the exception
*/
public static void mainold(String[] args) throws Exception {
Stack<String> files = new Stack<String>();
@@ -67,11 +66,11 @@
/**
* Test for seki.
*
- * @param file the file
- *
+ * @param file
+ * the file
* @return true, if successful
- *
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
static public boolean testForSeki(File file) throws IOException {
@@ -80,7 +79,7 @@
System.err.println("failed to load \"" + file + "\"");
return false;
}
- if (!game.getScore().getScored() || (game.getSize() != 19))
+ if (!game.getScore().getScored() || game.getSize() != 19)
return false;
if (game.isBranched())
return false;
@@ -99,7 +98,7 @@
Date after = new Date();
System.err.println("\"" + file + "\" time = \"" + (after.getTime() -
before.getTime()) + "\" result = \""
+ game.getScore() + "\"");
- if ((stonesInSeki != null) && (stonesInSeki.size() != 0)) {
+ if (stonesInSeki != null && stonesInSeki.size() != 0) {
System.err.println("\"" + file + "\" stonesInSeki = \"" +
stonesInSeki + "\"");
return true;
} else {
@@ -110,11 +109,11 @@
/**
* Test for seki.
*
- * @param filename the filename
- *
+ * @param filename
+ * the filename
* @return true, if successful
- *
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
static public boolean testForSeki(String filename) throws IOException {
return testForSeki(new File(filename));
@@ -144,8 +143,6 @@
this.files.add(fs[i]);
} else if (file.getName().endsWith(".zip")) {
this.process(file);
- } else if (file.getName().endsWith(".zip")) {
-
}
}
}
@@ -153,7 +150,8 @@
/**
* Process.
*
- * @param file the file
+ * @param file
+ * the file
*/
void process(File file) {
@@ -188,8 +186,10 @@
* The Class SGFFilter.
*/
class SGFFilter implements FilenameFilter {
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
*/
public boolean accept(File dir, String name) {
@@ -201,8 +201,10 @@
* The Class ZIPFilter.
*/
class ZIPFilter implements FilenameFilter {
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
*/
public boolean accept(File dir, String name) {
Modified: trunk/jgogears/jgogears/FastBoard.java
==============================================================================
--- trunk/jgogears/jgogears/FastBoard.java (original)
+++ trunk/jgogears/jgogears/FastBoard.java Tue Mar 4 22:17:01 2008
@@ -1,7 +1,6 @@
package jgogears;
-import java.util.*;
-
+import java.util.BitSet;
/**
* A bit-wise board representation using a naive bit ordering.
@@ -9,54 +8,50 @@
* @author syeates
*/
public class FastBoard extends BoardI {
-
+
/** How many bits we're allocating per square on the board. */
final static short BITS_PER_VERTEX = 4;
-
+
/** The underlying BitSet. */
- private BitSet bits = new BitSet();
-
+ private final BitSet bits = new BitSet();
+
/**
* Constructor for default board size.
*/
public FastBoard() {
+ // nothing
}
+
/**
* Constructor for default board size.
- * @param zobrist true if we're using zobrist hashing
+ *
+ * @param zobrist
+ * true if we're using zobrist hashing
*/
public FastBoard(boolean zobrist) {
super(zobrist);
}
- /**
- * create a new board based on the current board plus a move.
- *
- * @param move the move
- *
- * @return the new board
- */
- public final FastBoard newBoard( Move move) {
- return new FastBoard(this,move);
- }
/**
* create a new board based on the current board plus a move.
*
- * @param board the move
- * @param move the move
- *
+ * @param board
+ * the move
+ * @param move
+ * the move
*/
- public FastBoard(FastBoard board , Move move) {
+ public FastBoard(FastBoard board, Move move) {
this.size = board.getSize();
- copydata(board,move);
+ this.copydata(board, move);
}
/**
* Constructor for a particular size board.
*
- * @param size size of the board
+ * @param size
+ * size of the board
*/
public FastBoard(int size) {
@@ -66,8 +61,10 @@
/**
* constructor of specially sized boards.
*
- * @param size the size of the board
- * @param rule the ruleset to use
+ * @param size
+ * the size of the board
+ * @param rule
+ * the ruleset to use
*/
public FastBoard(int size, RuleSet rule) {
this.size = (short) size;
@@ -77,7 +74,8 @@
/**
* Default constructor.
*
- * @param rule the rule
+ * @param rule
+ * the rule
*/
public FastBoard(RuleSet rule) {
this.ruleSet = rule;
@@ -86,7 +84,8 @@
/**
* Constructor for a particular size board.
*
- * @param size size of the board
+ * @param size
+ * size of the board
*/
public FastBoard(short size) {
@@ -96,8 +95,10 @@
/**
* constructor of specially sized boards.
*
- * @param size the size of the board
- * @param rule the ruleset to use
+ * @param size
+ * the size of the board
+ * @param rule
+ * the ruleset to use
*/
public FastBoard(short size, RuleSet rule) {
this.size = size;
@@ -107,15 +108,17 @@
/*
* @see jgogears.BoardInterface#
*/
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.BoardI#getColour(int, int)
*/
@Override
public short getColour(int row, int column) {
- if ((row < 0) || (column < 0) || (row >= this.size) || (column >= this.size))
+ if (row < 0 || column < 0 || row >= this.size || column >= this.size)
return VERTEX_OFF_BOARD;
- int offset = (row * BITS_PER_VERTEX * this.size) + (column * BITS_PER_VERTEX);
+ int offset = row * BITS_PER_VERTEX * this.size + column * BITS_PER_VERTEX;
if (this.bits.get(offset))
if (this.bits.get(offset + 1))
return VERTEX_WHITE;
@@ -128,6 +131,17 @@
}
+ /**
+ * create a new board based on the current board plus a move.
+ *
+ * @param move
+ * the move
+ * @return the new board
+ */
+ @Override
+ public final FastBoard newBoard(Move move) {
+ return new FastBoard(this, move);
+ }
/*
* @see jgogears.BoardInterface#
@@ -135,14 +149,16 @@
/**
* Sets the colour.
*
- * @param row the row
- * @param column the column
- * @param colour the colour
- *
-
+ * @param row
+ * the row
+ * @param column
+ * the column
+ * @param colour
+ * the colour
*/
- public void setColour(int row, int column, short colour) {
- int offset = (row * BITS_PER_VERTEX * this.size) + (column * BITS_PER_VERTEX);
+ @Override
+ public void setColour(int row, int column, short colour) {
+ int offset = row * BITS_PER_VERTEX * this.size + column * BITS_PER_VERTEX;
switch (colour) {
case VERTEX_EMPTY:
Modified: trunk/jgogears/jgogears/FastBoardTest.java
==============================================================================
--- trunk/jgogears/jgogears/FastBoardTest.java (original)
+++ trunk/jgogears/jgogears/FastBoardTest.java Tue Mar 4 22:17:01 2008
@@ -5,15 +5,17 @@
import junit.framework.TestCase;
+// TODO: Auto-generated Javadoc
/**
* The Class FastBoardTest.
*/
public class FastBoardTest extends TestCase {
/**
- * Test all vertexes on a board of size N
+ * Test all vertexes on a board of size N.
*
- * @param size the size
+ * @param size
+ * the size
*/
public void testAllVertexesN(int size) {
BoardI board = new FastBoard(size);
@@ -26,7 +28,7 @@
for (int l = 0; l < size; l++) {
for (int m = 0; m < size; m++) {
- if ((l != i) && (m != j)) {
+ if (l != i && m != j) {
assertTrue(board.getColour(l, m) == BoardI.VERTEX_EMPTY);
assertTrue(BoardI.VERTEX_EMPTY == BoardI.VERTEX_EMPTY);
assertTrue(board.getColour(l, m) == board.getColour(l, m));
@@ -44,7 +46,7 @@
for (int l = 0; l < size; l++) {
for (int m = 0; m < size; m++) {
- if ((l != i) && (m != j)) {
+ if (l != i && m != j) {
assertTrue(board.getColour(i, j) == BoardI.VERTEX_EMPTY);
}
}
@@ -55,7 +57,7 @@
for (int l = 0; l < size; l++) {
for (int m = 0; m < size; m++) {
- if ((l != i) && (m != j)) {
+ if (l != i && m != j) {
assertTrue(board.getColour(l, m) == BoardI.VERTEX_EMPTY);
}
}
@@ -66,7 +68,7 @@
for (int l = 0; l < size; l++) {
for (int m = 0; m < size; m++) {
- if ((l != i) && (m != j)) {
+ if (l != i && m != j) {
assertTrue(board.getColour(l, m) == BoardI.VERTEX_EMPTY);
}
}
@@ -77,7 +79,7 @@
for (int l = 0; l < size; l++) {
for (int m = 0; m < size; m++) {
- if ((l != i) && (m != j)) {
+ if (l != i && m != j) {
assertTrue(board.getColour(l, m) == BoardI.VERTEX_EMPTY);
}
}
@@ -89,7 +91,8 @@
/**
* Test load all SGF files.
*
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
public void testLoadAllSGFFiles() throws IOException {
Stack<String> files = new Stack<String>();
@@ -98,7 +101,7 @@
while (files.size() > 0) {
String filename = files.pop();
File file = new File(filename);
- //System.err.println("examining \"" + filename + "\"");
+ // System.err.println("examining \"" + filename + "\"");
if (file.exists()) {
if (!file.isDirectory()) {
// System.err.println("\"" + filename + "\" is not a
@@ -126,7 +129,7 @@
return;
} else {
- //System.err.println("\"" + filename + "\" is a directory");
+ // System.err.println("\"" + filename + "\" is a directory");
String[] children = file.list();
for (int i = 0; i < children.length; i++) {
// System.err.println("pushing \"" + children[i] +
@@ -142,7 +145,8 @@
/**
* Test load simple gnugo.
*
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
public void testLoadSimpleGnugo() throws IOException {
@@ -319,7 +323,7 @@
BoardI working = new FastBoard((short) 19);
assertNotNull(working);
working = working.newBoard(new Move("B q10"));
- //System.out.println(working);
+ // System.out.println(working);
}
}
Modified: trunk/jgogears/jgogears/FasterBoard.java
==============================================================================
--- trunk/jgogears/jgogears/FasterBoard.java (original)
+++ trunk/jgogears/jgogears/FasterBoard.java Tue Mar 4 22:17:01 2008
@@ -1,6 +1,6 @@
package jgogears;
-import java.util.*;
+import java.util.BitSet;
// TODO: Auto-generated Javadoc
/**
@@ -9,16 +9,16 @@
* @author syeates
*/
public class FasterBoard extends BoardI {
-
+
/** the bit number for empty. */
final static short OFFSET_EMPTY = 0;
-
+
/** the bit number for colour / ko. */
final static short OFFSET_COLOUR = 1;
-
+
/** verbose debugging info. */
private final boolean DEBUG = true;
-
+
/** the underlying bitset holding the data. */
private final BitSet bits = new BitSet();
@@ -26,53 +26,49 @@
* Create a new board.
*/
public FasterBoard() {
+ // nothing
}
+
/**
- * create a new board based on the current board plus a move.
- *
- * @param move the move
+ * Create a new board.
*
- * @return the new board
+ * @param zobrist
+ * true if using zorbist hashing
*/
- public final FasterBoard newBoard( Move move) {
- return new FasterBoard(this,move);
+ public FasterBoard(boolean zobrist) {
+ super(zobrist);
}
/**
* create a new board based on the current board plus a move.
*
- * @param board the move
- * @param move the move
- *
+ * @param board
+ * the move
+ * @param move
+ * the move
*/
- public FasterBoard(FasterBoard board , Move move) {
+ public FasterBoard(FasterBoard board, Move move) {
this.size = board.getSize();
- copydata(board,move);
+ this.copydata(board, move);
}
/**
* Create a new board.
*
- * @param size the size of the board
+ * @param size
+ * the size of the board
*/
public FasterBoard(int size) {
this.size = (short) size;
}
-
- /**
- * Create a new board.
- *
- * @param zobrist true if using zorbist hashing
- */
- public FasterBoard(boolean zobrist) {
- super(zobrist);
- }
/**
* Create a new board.
*
- * @param size the size of the board
- * @param rule the ruleset to use
+ * @param size
+ * the size of the board
+ * @param rule
+ * the ruleset to use
*/
public FasterBoard(int size, RuleSet rule) {
this.size = (short) size;
@@ -82,7 +78,8 @@
/**
* Create a new board.
*
- * @param rule the ruleset to use
+ * @param rule
+ * the ruleset to use
*/
public FasterBoard(RuleSet rule) {
this.ruleSet = rule;
@@ -91,7 +88,8 @@
/**
* Create a new board.
*
- * @param size the size of the board
+ * @param size
+ * the size of the board
*/
public FasterBoard(short size) {
@@ -101,22 +99,53 @@
/**
* Create a new board.
*
- * @param size the size of the board
- * @param rule the ruleset to use
+ * @param size
+ * the size of the board
+ * @param rule
+ * the ruleset to use
+ */
+ public FasterBoard(short size, boolean zobrist) {
+ super(zobrist);
+ this.size = size;
+ }
+
+ /**
+ * Create a new board.
+ *
+ * @param size
+ * the size of the board
+ * @param rule
+ * the ruleset to use
*/
public FasterBoard(short size, RuleSet rule) {
this.size = size;
this.ruleSet = rule;
}
- /* (non-Javadoc)
+ /**
+ * Create a new board.
+ *
+ * @param size
+ * the size of the board
+ * @param rule
+ * the ruleset to use
+ */
+ public FasterBoard(short size, RuleSet rule, boolean zobrist) {
+ super(zobrist);
+ this.size = size;
+ this.ruleSet = rule;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.BoardI#getColour(int, int)
*/
@Override
public short getColour(int row, int column) {
- if ((row < 0) || (row >= this.size))
+ if (row < 0 || row >= this.size)
return VERTEX_OFF_BOARD;
- if ((column < 0) || (column >= this.size))
+ if (column < 0 || column >= this.size)
return VERTEX_OFF_BOARD;
boolean empty = this.bits.get(this.getEmptyOffSet(row, column));
@@ -136,25 +165,27 @@
/**
* Gets the colour off set.
*
- * @param row the row
- * @param column the column
- *
+ * @param row
+ * the row
+ * @param column
+ * the column
* @return the colour offset
*/
int getColourOffSet(int row, int column) {
- return OFFSET_COLOUR * this.size * this.size + (row * this.size) + (column);
+ return OFFSET_COLOUR * this.size * this.size + row * this.size + column;
}
/**
* Gets the empty off set.
*
- * @param row the row
- * @param column the column
- *
+ * @param row
+ * the row
+ * @param column
+ * the column
* @return the empty offset
*/
int getEmptyOffSet(int row, int column) {
- return OFFSET_EMPTY * this.size * this.size + (row * this.size) + (column);
+ return OFFSET_EMPTY * this.size * this.size + row * this.size + column;
}
/*
@@ -167,17 +198,31 @@
return this.size;
}
+ /**
+ * create a new board based on the current board plus a move.
+ *
+ * @param move
+ * the move
+ * @return the new board
+ */
+ @Override
+ public final FasterBoard newBoard(Move move) {
+ return new FasterBoard(this, move);
+ }
/**
* Sets the colour.
*
- * @param row the row
- * @param column the column
- * @param colour the colour
- *
+ * @param row
+ * the row
+ * @param column
+ * the column
+ * @param colour
+ * the colour
*/
- public void setColour(int row, int column, short colour) {
- if ((row < 0) || (column < 0) || (row >= this.size) || (column >=
this.size)) {
+ @Override
+ public void setColour(int row, int column, short colour) {
+ if (row < 0 || column < 0 || row >= this.size || column >=
this.size) {
if (this.DEBUG)
System.err.println("attempt to set a colour off-board");
throw new Error();
@@ -206,6 +251,6 @@
throw new Error();
}
-}
+ }
}
Modified: trunk/jgogears/jgogears/FasterBoardTest.java
==============================================================================
--- trunk/jgogears/jgogears/FasterBoardTest.java (original)
+++ trunk/jgogears/jgogears/FasterBoardTest.java Tue Mar 4 22:17:01 2008
@@ -5,6 +5,7 @@
import junit.framework.TestCase;
+// TODO: Auto-generated Javadoc
/**
* The Class FasterBoardTest.
*/
@@ -37,7 +38,8 @@
/**
* Test all vertexes n.
*
- * @param size the size
+ * @param size
+ * the size
*/
public void testAllVertexesN(int size) {
BoardI board = new FasterBoard(size);
@@ -51,7 +53,7 @@
for (int l = 0; l < size; l++) {
for (int m = 0; m < size; m++) {
- if ((l != i) && (m != j)) {
+ if (l != i && m != j) {
assertTrue("" + size + "," + i + "," + j + "," + l + "," + m
+ "," + board.getColour(l, m)
+ "," + BoardI.VERTEX_EMPTY, board.getColour(l, m) == BoardI.VERTEX_EMPTY);
@@ -68,7 +70,7 @@
for (int l = 0; l < size; l++) {
for (int m = 0; m < size; m++) {
- if ((l != i) && (m != j)) {
+ if (l != i && m != j) {
assertTrue("" + size + "," + i + "," + j + "," + l + "," + m
+ "," + board.getColour(l, m)
+ ",", board.getColour(i, j) == BoardI.VERTEX_EMPTY);
}
@@ -80,7 +82,7 @@
for (int l = 0; l < size; l++) {
for (int m = 0; m < size; m++) {
- if ((l != i) && (m != j)) {
+ if (l != i && m != j) {
assertTrue("" + size + "," + i + "," + j + "," + l + "," + m
+ "," + board.getColour(l, m)
+ ",", board.getColour(l, m) == BoardI.VERTEX_EMPTY);
}
@@ -92,7 +94,7 @@
for (int l = 0; l < size; l++) {
for (int m = 0; m < size; m++) {
- if ((l != i) && (m != j)) {
+ if (l != i && m != j) {
assertTrue("" + size + "," + i + "," + j + "," + l + "," + m
+ "," + board.getColour(l, m)
+ ",", board.getColour(l, m) == BoardI.VERTEX_EMPTY);
}
@@ -104,7 +106,7 @@
for (int l = 0; l < size; l++) {
for (int m = 0; m < size; m++) {
- if ((l != i) && (m != j)) {
+ if (l != i && m != j) {
assertTrue("" + size + "," + i + "," + j + "," + l + "," + m
+ "," + board.getColour(l, m)
+ ",", board.getColour(l, m) == BoardI.VERTEX_EMPTY);
}
@@ -117,7 +119,8 @@
/**
* Test load all sg ffiles.
*
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
public void testLoadAllSGFfiles() throws IOException {
Stack<String> files = new Stack<String>();
@@ -171,7 +174,8 @@
/**
* Test load simple gnugo.
*
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
public void testLoadSimpleGnugo() throws IOException {
Modified: trunk/jgogears/jgogears/GTPConstants.java
==============================================================================
--- trunk/jgogears/jgogears/GTPConstants.java (original)
+++ trunk/jgogears/jgogears/GTPConstants.java Tue Mar 4 22:17:01 2008
@@ -8,67 +8,67 @@
/** The Constant BOARDSIZE. */
final static public String BOARDSIZE = "boardsize";
-
+
/** The Constant CLEARBAORD. */
final static public String CLEARBAORD = "clear_board";
-
+
/** The Constant FINALSCORE. */
final static public String FINALSCORE = "final_score";
-
+
/** The Constant GENMOVE. */
final static public String GENMOVE = "genmove";
-
+
/** The Constant KNOWNCOMMAND. */
final static public String KNOWNCOMMAND = "known_command";
-
+
/** The Constant LISTCOMMANDS. */
final static public String LISTCOMMANDS = "list_commands";
-
+
/** The Constant LOADSGF. */
final static public String LOADSGF = "loadsgf";
-
+
/** The Constant NAME. */
final static public String NAME = "name";
-
+
/** The Constant PLAY. */
final static public String PLAY = "play";
-
+
/** The Constant PROTOCOLVERSION. */
final static public String PROTOCOLVERSION = "protocol_version";
-
+
/** The Constant QUIT. */
final static public String QUIT = "quit";
-
+
/** The Constant REGGENMOVE. */
final static public String REGGENMOVE = "reg_genmove";
-
+
/** The Constant UNDO. */
final static public String UNDO = "undo";
-
+
/** The Constant VERSION. */
final static public String VERSION = "version";
-
+
/** The Constant SHOWBOARD. */
final static public String SHOWBOARD = "showboard";
-
+
/** The Constant FIXEDHANDICAP. */
final static public String FIXEDHANDICAP = "fixed_handicap";
-
+
/** The Constant PLACEFREEHANDHANDICAP. */
final static public String PLACEFREEHANDHANDICAP = "place_free_handicap";
-
+
/** The Constant SETFREEHANDICAP. */
final static public String SETFREEHANDICAP = "set_free_handicap";
-
+
/** The Constant KOMI. */
final static public String KOMI = "komi";
-
+
/** The Constant TIMESETTINGS. */
final static public String TIMESETTINGS = "time_settings";
-
+
/** The Constant TIMELEFT. */
final static public String TIMELEFT = "time_left";
-
+
/** The Constant FINALSTATUSLIST. */
final static public String FINALSTATUSLIST = "final_status_list";
Modified: trunk/jgogears/jgogears/GTPController.java
==============================================================================
--- trunk/jgogears/jgogears/GTPController.java (original)
+++ trunk/jgogears/jgogears/GTPController.java Tue Mar 4 22:17:01 2008
@@ -11,9 +11,10 @@
/**
* The main method.
*
- * @param args the args
- *
- * @throws IOException Signals that an I/O exception has occurred.
+ * @param args
+ * the args
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
public static void main(String[] args) throws IOException {
new GTPController().run();
@@ -29,7 +30,8 @@
/**
* Consume result.
*
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
void consumeResult() throws java.io.IOException {
while (this.reader.ready()) {
@@ -42,8 +44,8 @@
* Run.
*
* @return true, if successful
- *
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
boolean run() throws java.io.IOException {
PipedWriter farwriter = new PipedWriter();
@@ -70,8 +72,8 @@
* Setup.
*
* @return true, if successful
- *
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
boolean setup() throws java.io.IOException {
this.writer.write("boardsize 19\n\n");
Modified: trunk/jgogears/jgogears/GTPEngine.java
==============================================================================
--- trunk/jgogears/jgogears/GTPEngine.java (original)
+++ trunk/jgogears/jgogears/GTPEngine.java Tue Mar 4 22:17:01 2008
@@ -12,22 +12,23 @@
/** The reader. */
BufferedReader reader = null;
-
+
/** The writer. */
Writer writer = null;
-
+
/** The state. */
GTPState state = new GTPState();
-
+
/** The engine. */
GTPInterface engine = null;
/**
* compares two strings and returns true is the shorter is the first
substring of the second.
*
- * @param a the first string
- * @param b the second string
- *
+ * @param a
+ * the first string
+ * @param b
+ * the second string
* @return true if they match
*/
boolean compare(String a, String b) {
@@ -45,11 +46,11 @@
/**
* Processes single command.
*
- * @param command the command to process
- *
+ * @param command
+ * the command to process
* @return true on success
- *
- * @throws Exception the exception
+ * @throws Exception
+ * the exception
*/
boolean processCommand(String command) throws Exception {
command = command.toLowerCase();
@@ -121,7 +122,9 @@
return false;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Runnable#run()
*/
public void run() {
@@ -136,7 +139,8 @@
/**
* Stuff.
*
- * @throws Exception the exception
+ * @throws Exception
+ * the exception
*/
void stuff() throws Exception {
boolean quit = false;
Modified: trunk/jgogears/jgogears/GTPError.java
==============================================================================
--- trunk/jgogears/jgogears/GTPError.java (original)
+++ trunk/jgogears/jgogears/GTPError.java Tue Mar 4 22:17:01 2008
@@ -18,7 +18,8 @@
/**
* Instantiates a new gTP error.
*
- * @param arg0 the arg0
+ * @param arg0
+ * the arg0
*/
public GTPError(String arg0) {
super(arg0);
Modified: trunk/jgogears/jgogears/GTPHandicaps.java
==============================================================================
--- trunk/jgogears/jgogears/GTPHandicaps.java (original)
+++ trunk/jgogears/jgogears/GTPHandicaps.java Tue Mar 4 22:17:01 2008
@@ -1,19 +1,16 @@
package jgogears;
-
/**
- * The Class GTPHandicaps.
- *
- * TODO implement handicaps for all sizes of board between 5 and 25
+ * The Class GTPHandicaps. TODO implement handicaps for all sizes of
board between 5 and 25
*/
class GTPHandicaps {
/** The Constant ALL. */
final static public Move[] ALL = { new Move("B d4"), new Move("B
q16"), new Move("B d16"), new Move("B q4"),
- new Move("B d10"), new Move("B q10"), new Move("B k4"), new Move("B k10"),
- new Move("B g13"), new Move("B n7"), new Move("B g7"), new Move("B n13"),
- new Move("B c17"), new Move("B r3"), new Move("B c3"), new Move("B r17"),
- new Move("B g16"), new Move("B n4"), new Move("B q14"), new Move("B d7"),
+ new Move("B d10"), new Move("B q10"), new Move("B k4"), new Move("B
k10"), new Move("B g13"),
+ new Move("B n7"), new Move("B g7"), new Move("B n13"), new Move("B
c17"), new Move("B r3"),
+ new Move("B c3"), new Move("B r17"), new Move("B g16"), new Move("B
n4"), new Move("B q14"),
+ new Move("B d7"),
};
@@ -42,16 +39,15 @@
/** The Constant THREE. */
final static public Move[] THREE = { new Move("B d4"), new Move("B
q16"), new Move("B d16"), };
-
+
/** The Constant TWO. */
final static public Move[] TWO = { new Move("B D4"), new Move("B
Q16"), };
-
/**
* Fixed handicap.
*
- * @param handicap the handicap
- *
+ * @param handicap
+ * the handicap
* @return the move[]
*/
public static final Move[] fixedHandicap(int handicap) {
@@ -81,13 +77,13 @@
/**
* Free handicap.
*
- * @param handicap the handicap
- *
+ * @param handicap
+ * the handicap
* @return the move[]
*/
public static final Move[] freeHandicap(int handicap) {
Move[] result = new Move[handicap];
- for (int i = 0; (i < handicap) && (i < ALL.length); i++) {
+ for (int i = 0; i < handicap && i < ALL.length; i++) {
result[i] = ALL[i];
}
return result;
Modified: trunk/jgogears/jgogears/GTPInterface.java
==============================================================================
--- trunk/jgogears/jgogears/GTPInterface.java (original)
+++ trunk/jgogears/jgogears/GTPInterface.java Tue Mar 4 22:17:01 2008
@@ -1,28 +1,30 @@
package jgogears;
-
// TODO: Auto-generated Javadoc
/**
- * A GTP interface for which a computer-go player need not keep any
state. All necessary state is passed to the player each time the player
is called.
+ * A GTP interface for which a computer-go player need not keep any
state. All necessary state is passed to the player
+ * each time the player is called.
*
* @author syeates
*/
public interface GTPInterface {
-
+
/**
* Clear board.
*
- * @param state the state
+ * @param state
+ * the state
*/
void clearBoard(GTPState state);
/**
* Final status list.
*
- * @param status the status
- * @param state the state
- *
+ * @param status
+ * the status
+ * @param state
+ * the state
* @return the move[]
*/
Move[] finalStatusList(String status, GTPState state);
@@ -30,9 +32,10 @@
/**
* Fixed handicap.
*
- * @param handicap the handicap
- * @param state the state
- *
+ * @param handicap
+ * the handicap
+ * @param state
+ * the state
* @return the move[]
*/
Move[] fixedHandicap(int handicap, GTPState state);
@@ -40,9 +43,10 @@
/**
* Gen move.
*
- * @param colour the colour
- * @param state the state
- *
+ * @param colour
+ * the colour
+ * @param state
+ * the state
* @return the move
*/
Move genMove(short colour, GTPState state);
@@ -64,8 +68,8 @@
/**
* Gets the final score.
*
- * @param state the state
- *
+ * @param state
+ * the state
* @return the final score
*/
GTPScore getFinalScore(GTPState state);
@@ -73,8 +77,8 @@
/**
* Gets the known command.
*
- * @param command the command
- *
+ * @param command
+ * the command
* @return the known command
*/
boolean getKnownCommand(String command);
@@ -96,18 +100,22 @@
/**
* Loadsgf.
*
- * @param filename the filename
- * @param moveNumber the move number
- * @param state the state
+ * @param filename
+ * the filename
+ * @param moveNumber
+ * the move number
+ * @param state
+ * the state
*/
void loadsgf(String filename, int moveNumber, GTPState state);
/**
* Place free handicap.
*
- * @param handicap the handicap
- * @param state the state
- *
+ * @param handicap
+ * the handicap
+ * @param state
+ * the state
* @return the move[]
*/
Move[] placeFreeHandicap(int handicap, GTPState state);
@@ -115,16 +123,20 @@
/**
* Place free handicap.
*
- * @param stones the stones
- * @param state the state
+ * @param stones
+ * the stones
+ * @param state
+ * the state
*/
void placeFreeHandicap(jgogears.Move[] stones, GTPState state);
/**
* Play.
*
- * @param move the move
- * @param state the state
+ * @param move
+ * the move
+ * @param state
+ * the state
*/
void play(Move move, GTPState state);
@@ -138,9 +150,10 @@
/**
* Reg gen move.
*
- * @param colour the colour
- * @param state the state
- *
+ * @param colour
+ * the colour
+ * @param state
+ * the state
* @return the move
*/
Move regGenMove(int colour, GTPState state);
@@ -148,44 +161,56 @@
/**
* Sets the board size.
*
- * @param size the size
- * @param state the state
+ * @param size
+ * the size
+ * @param state
+ * the state
*/
void setBoardSize(short size, GTPState state);
/**
* Sets the komi.
*
- * @param komi the komi
- * @param state the state
+ * @param komi
+ * the komi
+ * @param state
+ * the state
*/
void setKomi(double komi, GTPState state);
/**
* Sets the time left.
*
- * @param colour the colour
- * @param byoYomiTime the byo yomi time
- * @param byoYomiStones the byo yomi stones
- * @param state the state
+ * @param colour
+ * the colour
+ * @param byoYomiTime
+ * the byo yomi time
+ * @param byoYomiStones
+ * the byo yomi stones
+ * @param state
+ * the state
*/
void setTimeLeft(int colour, double byoYomiTime, double
byoYomiStones, GTPState state);
/**
* Sets the time settings.
*
- * @param mainTime the main time
- * @param byoYomiTime the byo yomi time
- * @param byoYomiStones the byo yomi stones
- * @param state the state
+ * @param mainTime
+ * the main time
+ * @param byoYomiTime
+ * the byo yomi time
+ * @param byoYomiStones
+ * the byo yomi stones
+ * @param state
+ * the state
*/
void setTimeSettings(double mainTime, double byoYomiTime, double
byoYomiStones, GTPState state);
/**
* Show board.
*
- * @param state the state
- *
+ * @param state
+ * the state
* @return the board i
*/
BoardI showBoard(GTPState state);
@@ -193,8 +218,8 @@
/**
* Undo.
*
- * @param state the state
- *
+ * @param state
+ * the state
* @return true, if successful
*/
boolean undo(GTPState state);
Modified: trunk/jgogears/jgogears/GTPInterfaceRaw.java
==============================================================================
--- trunk/jgogears/jgogears/GTPInterfaceRaw.java (original)
+++ trunk/jgogears/jgogears/GTPInterfaceRaw.java Tue Mar 4 22:17:01 2008
@@ -7,7 +7,7 @@
* The Interface GTPInterfaceRaw.
*/
public interface GTPInterfaceRaw {
-
+
/**
* Clear board.
*
@@ -18,8 +18,8 @@
/**
* Final status list.
*
- * @param status the status
- *
+ * @param status
+ * the status
* @return the tree set< vertex>
*/
TreeSet<Vertex> finalStatusList(String status);
@@ -27,8 +27,8 @@
/**
* Fixed handicap.
*
- * @param handicap the handicap
- *
+ * @param handicap
+ * the handicap
* @return the tree set< vertex>
*/
TreeSet<Vertex> fixedHandicap(short handicap);
@@ -36,8 +36,8 @@
/**
* Gen move.
*
- * @param colour the colour
- *
+ * @param colour
+ * the colour
* @return the move
*/
Move genMove(short colour);
@@ -66,8 +66,8 @@
/**
* Gets the known command.
*
- * @param command the command
- *
+ * @param command
+ * the command
* @return the known command
*/
boolean getKnownCommand(String command);
@@ -89,9 +89,10 @@
/**
* Loadsgf.
*
- * @param filename the filename
- * @param moveNumber the move number
- *
+ * @param filename
+ * the filename
+ * @param moveNumber
+ * the move number
* @return true, if successful
*/
boolean loadsgf(String filename, int moveNumber);
@@ -99,8 +100,8 @@
/**
* Place free handicap.
*
- * @param handicap the handicap
- *
+ * @param handicap
+ * the handicap
* @return the tree set< vertex>
*/
TreeSet<Vertex> placeFreeHandicap(short handicap);
@@ -108,8 +109,8 @@
/**
* Place free handicap.
*
- * @param stones the stones
- *
+ * @param stones
+ * the stones
* @return true, if successful
*/
boolean placeFreeHandicap(TreeSet<Vertex> stones);
@@ -117,8 +118,8 @@
/**
* Play.
*
- * @param move the move
- *
+ * @param move
+ * the move
* @return true, if successful
*/
boolean play(Move move);
@@ -133,8 +134,8 @@
/**
* Reg gen move.
*
- * @param colour the colour
- *
+ * @param colour
+ * the colour
* @return the move
*/
Move regGenMove(short colour);
@@ -142,8 +143,8 @@
/**
* Sets the board size.
*
- * @param size the size
- *
+ * @param size
+ * the size
* @return true, if successful
*/
boolean setBoardSize(short size);
@@ -151,8 +152,8 @@
/**
* Sets the komi.
*
- * @param komi the komi
- *
+ * @param komi
+ * the komi
* @return true, if successful
*/
boolean setKomi(double komi);
@@ -160,10 +161,12 @@
/**
* Sets the time left.
*
- * @param colour the colour
- * @param byoYomiTime the byo yomi time
- * @param byoYomiStones the byo yomi stones
- *
+ * @param colour
+ * the colour
+ * @param byoYomiTime
+ * the byo yomi time
+ * @param byoYomiStones
+ * the byo yomi stones
* @return true, if successful
*/
boolean setTimeLeft(short colour, double byoYomiTime, double byoYomiStones);
@@ -171,10 +174,12 @@
/**
* Sets the time settings.
*
- * @param mainTime the main time
- * @param byoYomiTime the byo yomi time
- * @param byoYomiStones the byo yomi stones
- *
+ * @param mainTime
+ * the main time
+ * @param byoYomiTime
+ * the byo yomi time
+ * @param byoYomiStones
+ * the byo yomi stones
* @return true, if successful
*/
boolean setTimeSettings(double mainTime, double byoYomiTime, double byoYomiStones);
Modified: trunk/jgogears/jgogears/GTPParserUtils.java
==============================================================================
--- trunk/jgogears/jgogears/GTPParserUtils.java (original)
+++ trunk/jgogears/jgogears/GTPParserUtils.java Tue Mar 4 22:17:01 2008
@@ -9,13 +9,13 @@
* @author syeates
*/
public class GTPParserUtils {
-
+
/**
* Takes a string returned from the GTP protocol and returns either
an Error describing the error in the string or a
* null if this is not an error.
*
- * @param s the s
- *
+ * @param s
+ * the s
* @return the error represented by this string
*/
static public Error getError(String s) {
@@ -27,7 +27,7 @@
return getError(s.substring(1));
if (s.charAt(0) == '?') {
int i;
- for (i = 1; (s.length() > i) && Character.isDigit(s.charAt(i)); i++)
+ for (i = 1; s.length() > i && Character.isDigit(s.charAt(i)); i++)
;
return new GTPError(s.substring(i));
}
@@ -37,19 +37,19 @@
/**
* Parses the vertex list.
*
- * @param s the s
- *
+ * @param s
+ * the s
* @return the tree set< vertex>
*/
static TreeSet<Vertex> parseVertexList(String s) {
s = stripIntro(s);
TreeSet<Vertex> vert = new TreeSet<Vertex>();
- if ((s != null) && (s.length() != 0)) {
+ if (s != null && s.length() != 0) {
do {
// System.err.println("parseVertexList(\"" + s + "\")");
Vertex v = null;
- while ((s.indexOf(' ') == 1) || (s.indexOf(' ') == 0)) {
+ while (s.indexOf(' ') == 1 || s.indexOf(' ') == 0) {
s = s.substring(1);
}
if (s.indexOf(' ') != -1) {
@@ -72,8 +72,8 @@
/**
* Strip intro.
*
- * @param s the s
- *
+ * @param s
+ * the s
* @return the string
*/
static String stripIntro(String s) {
@@ -82,19 +82,19 @@
if (s.length() == 0)
return s;
// strip leading whitespace
- while ((s.length() != 0) && (s.charAt(0) == ' ')) {
+ while (s.length() != 0 && s.charAt(0) == ' ') {
s = s.substring(1);
}
// strip the equal sign
- while ((s.length() != 0) && (s.charAt(0) == '=')) {
+ while (s.length() != 0 && s.charAt(0) == '=') {
s = s.substring(1);
}
// strip the number
- while ((s.length() != 0) && Character.isDigit(s.charAt(0))) {
+ while (s.length() != 0 && Character.isDigit(s.charAt(0))) {
s = s.substring(1);
}
// strip leading whitespace
- while ((s.length() != 0) && (s.length() != 0) && (s.charAt(0)
== ' ')) {
+ while (s.length() != 0 && s.length() != 0 && s.charAt(0) == ' ') {
s = s.substring(1);
}
if (s.length() == 0)
Modified: trunk/jgogears/jgogears/GTPParserUtilsTest.java
==============================================================================
--- trunk/jgogears/jgogears/GTPParserUtilsTest.java (original)
+++ trunk/jgogears/jgogears/GTPParserUtilsTest.java Tue Mar 4 22:17:01 2008
@@ -4,19 +4,21 @@
import junit.framework.TestCase;
-
+// TODO: Auto-generated Javadoc
/**
* The Class GTPParserUtilsTest.
*/
public class GTPParserUtilsTest extends TestCase {
- /** Are we being verbose? */
+ /** Are we being verbose?. */
boolean DEBUG = false;
/** The engine. */
GnuGoEngine engine = null;
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see junit.framework.TestCase#setUp()
*/
@Override
@@ -26,7 +28,9 @@
this.engine.initialise();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see junit.framework.TestCase#tearDown()
*/
@Override
@@ -37,7 +41,7 @@
}
/**
- * Test loadsgf.
+ * TODO ressurect this after showboard is working.
*/
public final void testLoadsgf() {
try {
@@ -46,10 +50,10 @@
assertTrue(b);
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:");
- assertNotNull(board);
- System.err.println(board);
+ // BoardI board = this.engine.showBoard();
+ // System.err.println("testLoadsgf:: the following board should
have moves on it:");
+ assertNotNull(this.engine);
+ // System.err.println(board);
this.engine.quit();
} catch (Throwable t) {
System.err.println(t);
@@ -60,7 +64,9 @@
/**
* Test parse gnu go board.
- * @throws IOException if the underlying engine can't be created or
communicated with
+ *
+ * @throws IOException
+ * if the underlying engine can't be created or
communicated with
*/
public void testParseGnuGoBoard() throws IOException {
this.testParseGnuGoBoard((short) 7);
@@ -70,15 +76,15 @@
this.testParseGnuGoBoard((short) 15);
this.testParseGnuGoBoard((short) 17);
this.testParseGnuGoBoard((short) 19);
- // testParseGnuGoBoard((short)21);
- // testParseGnuGoBoard((short)23);
- // testParseGnuGoBoard((short)25);
}
/**
* Test parse gnu go board.
*
- * @param i the i
+ * @param i
+ * the i
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
public void testParseGnuGoBoard(short i) throws IOException {
try {
@@ -90,15 +96,14 @@
this.engine.quit();
} catch (GTPError e) {
System.err.println("testParseGnuGoBoard(" + i + ") failed");
- //System.err.println(e);
- //e.printStackTrace();
+ // System.err.println(e);
+ // e.printStackTrace();
fail();
}
}
/**
- *
- * This is currently failing because I don't have good code to parse
the ASCII board back into a BoardI
+ * 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/GTPScore.java
==============================================================================
--- trunk/jgogears/jgogears/GTPScore.java (original)
+++ trunk/jgogears/jgogears/GTPScore.java Tue Mar 4 22:17:01 2008
@@ -16,31 +16,31 @@
/** The white win. */
private boolean whiteWin;
-
+
/** The neither win. */
private boolean neitherWin = false;
-
+
/** The scored. */
private boolean scored = false;
-
+
/** The margin. */
private double margin = Double.MIN_VALUE;
-
+
/** The resign. */
private boolean resign = false;
-
+
/** The time. */
private boolean time = false;
-
+
/** The forfeit. */
private boolean forfeit = false;
-
+
/** The _void. */
private boolean _void = false;
-
+
/** The unknown. */
private boolean unknown = false;
-
+
/** The value. */
private String value;
@@ -50,13 +50,16 @@
/**
* Instantiates a new gTP score.
*
- * @param s the s
+ * @param s
+ * the s
*/
public GTPScore(String s) {
this.init(s);
};
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
@@ -157,8 +160,8 @@
/**
* Inits the.
*
- * @param s the s
- *
+ * @param s
+ * the s
* @return true, if successful
*/
public boolean init(String s) {
@@ -166,7 +169,7 @@
if (s.length() == 0) {
System.err.println("cannot initialise a score from a zero length string");
throw new Error();
- //return false;
+ // return false;
}
try {
this.value = s;
@@ -177,7 +180,7 @@
} else if (s.contains("b+r")) {
this.whiteWin = false;
this.resign = true;
- } else if ((s.compareTo("0") == 0) || (s.compareTo("draw") == 0)) {
+ } else if (s.compareTo("0") == 0 || s.compareTo("draw") == 0) {
this.whiteWin = false;
this.neitherWin = true;
this.margin = 0.0;
@@ -243,7 +246,9 @@
return true;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Object#toString()
*/
@Override
Modified: trunk/jgogears/jgogears/GTPState.java
==============================================================================
--- trunk/jgogears/jgogears/GTPState.java (original)
+++ trunk/jgogears/jgogears/GTPState.java Tue Mar 4 22:17:01 2008
@@ -12,33 +12,36 @@
/** The boardsize. */
protected short boardsize = BoardI.DEFAULT_BOARD_SIZE;
-
+
/** The board. */
protected BoardI board = null;
-
+
/** The white captured count. */
protected int whiteCapturedCount = Integer.MIN_VALUE;
-
+
/** The black captured count. */
protected int blackCapturedCount = Integer.MIN_VALUE;
-
+
/** The komi. */
protected double komi = Double.MIN_VALUE;
-
+
/** The main time. */
protected double mainTime = Double.MIN_VALUE;
-
+
/** The byo yomi time. */
protected double byoYomiTime = Double.MIN_VALUE;
-
+
/** The byo yomi stones. */
protected double byoYomiStones = Double.MIN_VALUE;
-
+
/** The played moves. */
protected java.util.Vector<Move> playedMoves = new java.util.Vector<Move>();
-
- public GTPState(){
- this.board = new Board(boardsize);
+
+ /**
+ * Create a new GTPState
+ */
+ public GTPState() {
+ this.board = BoardI.newBoard(this.boardsize);
}
/**
@@ -53,7 +56,7 @@
throw new Error("Illegal GTPState state");
if (this.blackCapturedCount < 0)
throw new Error("Illegal GTPState state");
- if ((this.komi < 10000) && (this.komi > 10000))
+ if (this.komi < 10000 && this.komi > 10000)
throw new Error("Illegal GTPState state");
if (this.mainTime < 0)
throw new Error("Illegal GTPState state");
@@ -72,7 +75,7 @@
// TODO is this sufficient?
this.whiteCapturedCount = 0;
this.blackCapturedCount = 0;
- this.board = new Board((short) this.getBoardsize());
+ this.board = BoardI.newBoard((short) this.getBoardsize());
this.playedMoves = new java.util.Vector<Move>();
}
@@ -160,7 +163,8 @@
/**
* Play move.
*
- * @param move the move
+ * @param move
+ * the move
*/
public void playMove(Move move) {
this.playedMoves.add(move);
@@ -168,12 +172,12 @@
return;
if (move.getResign())
return;
- TreeSet<Vertex> captures = RuleSet.DEFAULT.captures(null, board, move);
- //TODO count the captures
+ TreeSet<Vertex> captures = RuleSet.DEFAULT.captures(null,
this.board, move);
+ // TODO count the captures
Iterator<Vertex> each = captures.iterator();
- while(each.hasNext()){
+ while (each.hasNext()) {
Vertex vert = each.next();
- switch (this.board.getColour(vert)){
+ switch (this.board.getColour(vert)) {
case BoardI.VERTEX_BLACK:
this.whiteCapturedCount++;
break;
@@ -183,7 +187,7 @@
default:
throw new Error("capture neither black or white");
}
-
+
}
this.board = this.board.newBoard(move);
}
@@ -191,7 +195,8 @@
/**
* Sets the black captured count.
*
- * @param blackCapturedCount the new black captured count
+ * @param blackCapturedCount
+ * the new black captured count
*/
public void setBlackCapturedCount(int blackCapturedCount) {
this.blackCapturedCount = blackCapturedCount;
@@ -200,26 +205,29 @@
/**
* Sets the board.
*
- * @param board the new board
+ * @param board
+ * the new board
*/
- public void setBoard(Board board) {
+ public void setBoard(BoardI board) {
this.board = board;
}
/**
* Sets the boardsize.
*
- * @param boardsize the new boardsize
+ * @param boardsize
+ * the new boardsize
*/
public void setBoardsize(short boardsize) {
this.boardsize = boardsize;
- this.board = new Board(boardsize);
+ this.board = BoardI.newBoard(boardsize);
}
/**
* Sets the byo yomi stones.
*
- * @param byoTomiStones the new byo yomi stones
+ * @param byoTomiStones
+ * the new byo yomi stones
*/
public void setByoYomiStones(double byoTomiStones) {
this.byoYomiStones = byoTomiStones;
@@ -228,7 +236,8 @@
/**
* Sets the byo yomi time.
*
- * @param byoYomiTime the new byo yomi time
+ * @param byoYomiTime
+ * the new byo yomi time
*/
public void setByoYomiTime(double byoYomiTime) {
this.byoYomiTime = byoYomiTime;
@@ -237,7 +246,8 @@
/**
* Sets the komi.
*
- * @param komi the new komi
+ * @param komi
+ * the new komi
*/
public void setKomi(double komia) {
this.komi = komia;
@@ -246,7 +256,8 @@
/**
* Sets the main time.
*
- * @param mainTime the new main time
+ * @param mainTime
+ * the new main time
*/
public void setMainTime(double mainTimea) {
this.mainTime = mainTimea;
@@ -255,7 +266,8 @@
/**
* Sets the white captured count.
*
- * @param whiteCapturedCount the new white captured count
+ * @param whiteCapturedCount
+ * the new white captured count
*/
public void setWhiteCapturedCount(int whiteCapturedCount) {
this.whiteCapturedCount = whiteCapturedCount;
Modified: trunk/jgogears/jgogears/Game.java
==============================================================================
--- trunk/jgogears/jgogears/Game.java (original)
+++ trunk/jgogears/jgogears/Game.java Tue Mar 4 22:17:01 2008
@@ -3,7 +3,6 @@
import java.io.*;
import java.util.*;
-
/**
* External representation of a game of go. This is currently very
heavily influenced by SGF, it needs to be
* generalised.
@@ -11,15 +10,15 @@
* @author syeates
*/
public final class Game {
-
+
/**
* Load an SGF file into memory.
*
- * @param file the file to load
- *
+ * @param file
+ * the file to load
* @return the game
- *
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
public static Game loadFromFile(File file) throws IOException {
@@ -34,11 +33,11 @@
/**
* Load an SGF file into memory.
*
- * @param filename the filename to load
- *
+ * @param filename
+ * the filename to load
* @return the game
- *
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
public static Game loadFromFilename(String filename) throws
IOException {
@@ -47,46 +46,46 @@
/** The size. */
protected short size = 0;
-
+
/** The black player. */
private String blackPlayer = "";
-
+
/** The white player. */
private String whitePlayer = "";
-
+
/** The komi. */
private short komi = 0;
-
+
/** The handicap. */
private short handicap = 0;
-
+
/** The score. */
private GTPScore score = null;
/** The comment count. */
private int commentCount = 0;
-
+
/** The branched. */
private boolean branched = false;
-
+
/** The black rank. */
private Rank blackRank = new Rank();
-
+
/** The white rank. */
private Rank whiteRank = new Rank();
-
+
/** The ruleset. */
private String ruleset = "";
-
+
/** The date. */
private String date = "";
-
+
/** The maintime. */
private String maintime = "";
-
+
/** The extra time. */
private String extraTime = "";
-
+
/** The PC. */
private String PC = "";
@@ -100,87 +99,109 @@
* default constractor.
*/
public Game() {
+ // nothing
}
/**
* default constractor.
*
- * @param size the size
+ * @param size
+ * the size
*/
public Game(int size) {
this.size = (short) size;
}
/**
- * get the size.
+ * build a game from a gametree.
*
- * @return the size
+ * @param gameTree
+ * the game tree
*/
- public final short getSize() {
- return size;
+ public Game(SGFGameTree gameTree) {
+ gameTree.init(this);
+ // System.err.println("\"" + this.blackPlayer + "\" (" + this.blackRank
+ // + ") vs" + "\"" +
+ // this.blackPlayer + "\" (" + this.blackRank + ") " + this.size
+ "x" +
+ // this.size + " h=" +
+ // this.handicap + " s=\"" + this.score+ "\" b=" + this.branched + " r="
+ // + this.ruleset + " date=\"" + this.date +"\" t=\"" +
this.maintime +
+ // "\" e=\"" + this.extraTime +"\" PC=\"" + this.PC +"\"");
}
/**
- * set the size.
+ * get the blackPlayer.
*
- * @param size the size to set
+ * @return the blackPlayer
*/
- public final void setSize(short size) {
- this.size = size;
+ public final String getBlackPlayer() {
+ return this.blackPlayer;
}
/**
- * get the blackPlayer.
+ * get the blackRank.
*
- * @return the blackPlayer
+ * @return the blackRank
*/
- public final String getBlackPlayer() {
- return blackPlayer;
+ public final Rank getBlackRank() {
+ return this.blackRank;
}
/**
- * set the blackPlayer.
+ * get the boardlist.
*
- * @param blackPlayer the blackPlayer to set
+ * @return the boardlist
*/
- public final void setBlackPlayer(String blackPlayer) {
- this.blackPlayer = blackPlayer;
+ public final LinkedList<BoardI> getBoardlist() {
+ return this.boardlist;
}
/**
- * get the whitePlayer.
+ * Get an iterator of all the boards in the game.
*
- * @return the whitePlayer
+ * @return an iterator
*/
- public final String getWhitePlayer() {
- return whitePlayer;
+ public Iterator<BoardI> getBoards() {
+ if (this.boardlist != null) {
+
+ Iterator<Move> moves = this.getMoves();
+ this.boardlist = new LinkedList<BoardI>();
+ BoardI board = BoardI.newBoard(this.size);
+ this.boardlist.add(board);
+ while (moves.hasNext()) {
+ Move move = moves.next();
+ board = board.newBoard(move);
+ this.boardlist.add(board);
+ }
+ }
+ return this.boardlist.iterator();
}
/**
- * set the whitePlayer.
+ * get the commentCount.
*
- * @param whitePlayer the whitePlayer to set
+ * @return the commentCount
*/
- public final void setWhitePlayer(String whitePlayer) {
- this.whitePlayer = whitePlayer;
+ public final int getCommentCount() {
+ return this.commentCount;
}
/**
- * get the komi.
+ * get the date.
*
- * @return the komi
+ * @return the date
*/
- public final short getKomi() {
- return komi;
+ public final String getDate() {
+ return this.date;
}
/**
- * set the komi.
+ * get the extraTime.
*
- * @param komi the komi to set
+ * @return the extraTime
*/
- public final void setKomi(short komi) {
- this.komi = komi;
+ public final String getExtraTime() {
+ return this.extraTime;
}
/**
@@ -189,88 +210,88 @@
* @return the handicap
*/
public final short getHandicap() {
- return handicap;
+ return this.handicap;
}
/**
- * set the handicap.
+ * get the komi.
*
- * @param handicap the handicap to set
+ * @return the komi
*/
- public final void setHandicap(short handicap) {
- this.handicap = handicap;
+ public final short getKomi() {
+ return this.komi;
}
/**
- * get the score.
+ * get the maintime.
*
- * @return the score
+ * @return the maintime
*/
- public final GTPScore getScore() {
- return score;
+ public final String getMaintime() {
+ return this.maintime;
}
/**
- * set the score.
+ * get the movelist.
*
- * @param score the score to set
+ * @return the movelist
*/
- public final void setScore(GTPScore score) {
- this.score = score;
+ public final LinkedList<Move> getMovelist() {
+ return this.movelist;
}
/**
- * get the commentCount.
+ * get the movelist.
*
- * @return the commentCount
+ * @return the movelist
*/
- public final int getCommentCount() {
- return commentCount;
+ public final Iterator<Move> getMoves() {
+ return this.movelist.iterator();
}
/**
- * set the commentCount.
+ * get the pC.
*
- * @param commentCount the commentCount to set
+ * @return the pC
*/
- public final void setCommentCount(int commentCount) {
- this.commentCount = commentCount;
+ public final String getPC() {
+ return this.PC;
}
/**
- * get the branched.
+ * get the ruleset.
*
- * @return the branched
+ * @return the ruleset
*/
- public final boolean isBranched() {
- return branched;
+ public final String getRuleset() {
+ return this.ruleset;
}
/**
- * set the branched.
+ * get the score.
*
- * @param branched the branched to set
+ * @return the score
*/
- public final void setBranched(boolean branched) {
- this.branched = branched;
+ public final GTPScore getScore() {
+ return this.score;
}
/**
- * get the blackRank.
+ * get the size.
*
- * @return the blackRank
+ * @return the size
*/
- public final Rank getBlackRank() {
- return blackRank;
+ public final short getSize() {
+ return this.size;
}
/**
- * set the blackRank.
+ * get the whitePlayer.
*
- * @param blackRank the blackRank to set
+ * @return the whitePlayer
*/
- public final void setBlackRank(Rank blackRank) {
- this.blackRank = blackRank;
+ public final String getWhitePlayer() {
+ return this.whitePlayer;
}
/**
@@ -279,192 +300,186 @@
* @return the whiteRank
*/
public final Rank getWhiteRank() {
- return whiteRank;
+ return this.whiteRank;
}
/**
- * set the whiteRank.
+ * get the branched.
*
- * @param whiteRank the whiteRank to set
+ * @return the branched
*/
- public final void setWhiteRank(Rank whiteRank) {
- this.whiteRank = whiteRank;
+ public final boolean isBranched() {
+ return this.branched;
}
/**
- * get the ruleset.
+ * set the blackPlayer.
*
- * @return the ruleset
+ * @param blackPlayer
+ * the blackPlayer to set
*/
- public final String getRuleset() {
- return ruleset;
+ public final void setBlackPlayer(String blackPlayer) {
+ this.blackPlayer = blackPlayer;
}
/**
- * set the ruleset.
+ * set the blackRank.
*
- * @param ruleset the ruleset to set
+ * @param blackRank
+ * the blackRank to set
*/
- public final void setRuleset(String ruleset) {
- this.ruleset = ruleset;
+ public final void setBlackRank(Rank blackRank) {
+ this.blackRank = blackRank;
}
/**
- * get the date.
+ * set the boardlist.
*
- * @return the date
+ * @param boardlist
+ * the boardlist to set
*/
- public final String getDate() {
- return date;
+ public final void setBoardlist(LinkedList<BoardI> boardlist) {
+ this.boardlist = boardlist;
}
/**
- * set the date.
+ * set the branched.
*
- * @param date the date to set
+ * @param branched
+ * the branched to set
*/
- public final void setDate(String date) {
- this.date = date;
+ public final void setBranched(boolean branched) {
+ this.branched = branched;
}
/**
- * get the maintime.
+ * set the commentCount.
*
- * @return the maintime
+ * @param commentCount
+ * the commentCount to set
*/
- public final String getMaintime() {
- return maintime;
+ public final void setCommentCount(int commentCount) {
+ this.commentCount = commentCount;
}
/**
- * set the maintime.
+ * set the date.
*
- * @param maintime the maintime to set
+ * @param date
+ * the date to set
*/
- public final void setMaintime(String maintime) {
- this.maintime = maintime;
+ public final void setDate(String date) {
+ this.date = date;
}
/**
- * get the extraTime.
+ * set the extraTime.
*
- * @return the extraTime
+ * @param extraTime
+ * the extraTime to set
*/
- public final String getExtraTime() {
- return extraTime;
+ public final void setExtraTime(String extraTime) {
+ this.extraTime = extraTime;
}
/**
- * set the extraTime.
+ * set the handicap.
*
- * @param extraTime the extraTime to set
+ * @param handicap
+ * the handicap to set
*/
- public final void setExtraTime(String extraTime) {
- this.extraTime = extraTime;
+ public final void setHandicap(short handicap) {
+ this.handicap = handicap;
}
/**
- * get the pC.
+ * set the komi.
*
- * @return the pC
+ * @param komi
+ * the komi to set
*/
- public final String getPC() {
- return PC;
+ public final void setKomi(short komi) {
+ this.komi = komi;
}
/**
- * set the pC.
+ * set the maintime.
*
- * @param pc the pC to set
+ * @param maintime
+ * the maintime to set
*/
- public final void setPC(String pc) {
- PC = pc;
+ public final void setMaintime(String maintime) {
+ this.maintime = maintime;
}
/**
- * get the movelist.
+ * set the movelist.
*
- * @return the movelist
+ * @param movelist
+ * the movelist to set
*/
- public final LinkedList<Move> getMovelist() {
- return movelist;
+ public final void setMovelist(LinkedList<Move> movelist) {
+ this.movelist = movelist;
}
-
+
/**
- * get the movelist.
+ * set the pC.
*
- * @return the movelist
+ * @param pc
+ * the pC to set
*/
- public final Iterator<Move> getMoves() {
- return movelist.iterator();
+ public final void setPC(String pc) {
+ this.PC = pc;
}
/**
- * set the movelist.
+ * set the ruleset.
*
- * @param movelist the movelist to set
+ * @param ruleset
+ * the ruleset to set
*/
- public final void setMovelist(LinkedList<Move> movelist) {
- this.movelist = movelist;
+ public final void setRuleset(String ruleset) {
+ this.ruleset = ruleset;
}
/**
- * get the boardlist.
+ * set the score.
*
- * @return the boardlist
+ * @param score
+ * the score to set
*/
- public final LinkedList<BoardI> getBoardlist() {
- return boardlist;
+ public final void setScore(GTPScore score) {
+ this.score = score;
}
-
/**
- * set the boardlist.
+ * set the size.
*
- * @param boardlist the boardlist to set
+ * @param size
+ * the size to set
*/
- public final void setBoardlist(LinkedList<BoardI> boardlist) {
- this.boardlist = boardlist;
+ public final void setSize(short size) {
+ this.size = size;
}
/**
- * build a game from a gametree.
+ * set the whitePlayer.
*
- * @param gameTree the game tree
+ * @param whitePlayer
+ * the whitePlayer to set
*/
- public Game(SGFGameTree gameTree) {
- gameTree.init(this);
- // System.err.println("\"" + this.blackPlayer + "\" (" + this.blackRank
- // + ") vs" + "\"" +
- // this.blackPlayer + "\" (" + this.blackRank + ") " + this.size
+ "x" +
- // this.size + " h=" +
- // this.handicap + " s=\"" + this.score+ "\" b=" + this.branched + " r="
- // + this.ruleset + " date=\"" + this.date +"\" t=\"" +
this.maintime +
- // "\" e=\"" + this.extraTime +"\" PC=\"" + this.PC +"\"");
+ public final void setWhitePlayer(String whitePlayer) {
+ this.whitePlayer = whitePlayer;
}
-
/**
- * Get an iterator of all the boards in the game.
+ * set the whiteRank.
*
- * @return an iterator
+ * @param whiteRank
+ * the whiteRank to set
*/
- public Iterator<BoardI> getBoards() {
- if (this.boardlist != null) {
-
- Iterator<Move> moves = this.getMoves();
- this.boardlist = new LinkedList<BoardI>();
- BoardI board = new Board(this.size);
- this.boardlist.add(board);
- while (moves.hasNext()) {
- Move move = moves.next();
- board = board.newBoard(move);
- this.boardlist.add(board);
- }
- }
- return this.boardlist.iterator();
+ public final void setWhiteRank(Rank whiteRank) {
+ this.whiteRank = whiteRank;
}
-
-
}
Modified: trunk/jgogears/jgogears/GlobalTests.java
==============================================================================
--- trunk/jgogears/jgogears/GlobalTests.java (original)
+++ trunk/jgogears/jgogears/GlobalTests.java Tue Mar 4 22:17:01 2008
@@ -12,12 +12,11 @@
*/
public class GlobalTests {
-
+
/**
* test collection.
*
* @return the test
- *
* @author syeates
*/
Modified: trunk/jgogears/jgogears/GnuGoEngine.java
==============================================================================
--- trunk/jgogears/jgogears/GnuGoEngine.java (original)
+++ trunk/jgogears/jgogears/GnuGoEngine.java Tue Mar 4 22:17:01 2008
@@ -13,7 +13,7 @@
/** The Constant SMALL_PAUSE. */
public static final int SMALL_PAUSE = 3;
-
+
/** The Constant LARGE_PAUSE. */
public static final int LARGE_PAUSE = 33;
@@ -40,36 +40,41 @@
/** The process. */
private Process process = null;
-
+
/** The DEBUG. */
public boolean DEBUG = false;
-
+
private short size = BoardI.DEFAULT_BOARD_SIZE;
/**
* Instantiates a new gnu go engine.
*
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
public GnuGoEngine() throws IOException {
this.initialise();
}
+
/**
* Instantiates a new gnu go engine.
*
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
- public GnuGoEngine(short size) throws IOException {
- this.size = size;
+ public GnuGoEngine(int size) throws IOException {
+ this.size = (short) size;
this.initialise();
}
+
/**
* Instantiates a new gnu go engine.
*
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
- public GnuGoEngine(int size) throws IOException {
- this.size = (short)size;
+ public GnuGoEngine(short size) throws IOException {
+ this.size = size;
this.initialise();
}
@@ -87,7 +92,9 @@
}
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterfaceRaw#clearBoard()
*/
public boolean clearBoard() {
@@ -101,29 +108,33 @@
return false;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterfaceRaw#finalStatusList(java.lang.String)
*/
public TreeSet<Vertex> finalStatusList(String status) {
this.write(GTPConstants.FINALSTATUSLIST + " " + status + "\n\n");
String s = this.read();
TreeSet<Vertex> v = GTPParserUtils.parseVertexList(s);
- if (this.DEBUG){
- System.err.println("finalStatusList" +status);
- System.err.println("finalStatusList" +s);
- System.err.println("finalStatusList" +v);
+ if (this.DEBUG) {
+ System.err.println("finalStatusList" + status);
+ System.err.println("finalStatusList" + s);
+ System.err.println("finalStatusList" + v);
}
return v;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterfaceRaw#fixedHandicap(short)
*/
public TreeSet<Vertex> fixedHandicap(short handicap) {
this.write(GTPConstants.FIXEDHANDICAP + " " + handicap + "\n\n");
String s = this.read();
TreeSet<Vertex> v = GTPParserUtils.parseVertexList(s);
- if (this.DEBUG){
+ if (this.DEBUG) {
System.err.println("fixedHandicap" + handicap);
System.err.println("fixedHandicap" + s);
System.err.println("fixedHandicap" + v);
@@ -131,15 +142,17 @@
return v;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterfaceRaw#genMove(short)
*/
public Move genMove(short colour) {
- this.write(GTPConstants.GENMOVE + " " + Move.colourString(colour) + "\n\n");
+ this.write(GTPConstants.GENMOVE + " " + BoardI.colourString(colour) + "\n\n");
String s = this.read();
// GoMove move = GoMove.createVertex(s.substring(2));
Move move = new Move(s, colour);
- if (DEBUG)
+ if (this.DEBUG)
System.err.println("genMove:" + colour + " " + move);
return move;
}
@@ -153,7 +166,9 @@
return this.args;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterfaceRaw#getEngineName()
*/
public String getEngineName() {
@@ -161,7 +176,9 @@
return this.read();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterfaceRaw#getEngineVersion()
*/
public String getEngineVersion() {
@@ -178,7 +195,9 @@
return this.errReader;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterfaceRaw#getFinalScore()
*/
public GTPScore getFinalScore() {
@@ -188,7 +207,9 @@
return new GTPScore(result);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterfaceRaw#getKnownCommand(java.lang.String)
*/
public boolean getKnownCommand(String command) {
@@ -196,7 +217,9 @@
throw new Error();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterfaceRaw#getListCommands()
*/
public TreeSet<String> getListCommands() {
@@ -213,7 +236,9 @@
return this.process;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterfaceRaw#getProtocolVersion()
*/
public int getProtocolVersion() {
@@ -232,6 +257,15 @@
}
/**
+ * get the size
+ *
+ * @return the size
+ */
+ public final short getSize() {
+ return this.size;
+ }
+
+ /**
* Gets the writer.
*
* @return the writer
@@ -244,8 +278,8 @@
* Initialise.
*
* @return true, if successful
- *
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
public synchronized boolean initialise() throws IOException {
if (this.initialised)
@@ -272,7 +306,7 @@
this.errReader = new java.io.BufferedReader(new InputStreamReader(this.process.getErrorStream()));
this.writer = new OutputStreamWriter(this.process.getOutputStream());
this.initialised = true;
-
+
this.setBoardSize(this.getSize());
this.check();
@@ -285,7 +319,9 @@
}
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterfaceRaw#loadsgf(java.lang.String, int)
*/
public boolean loadsgf(String filename, int moveNumber) {
@@ -303,7 +339,9 @@
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterfaceRaw#placeFreeHandicap(short)
*/
public TreeSet<Vertex> placeFreeHandicap(short handicap) {
@@ -318,7 +356,9 @@
return v;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterfaceRaw#placeFreeHandicap(java.util.TreeSet)
*/
public boolean placeFreeHandicap(TreeSet<Vertex> stones) {
@@ -333,7 +373,9 @@
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterfaceRaw#play(jgogears.Move)
*/
public boolean play(Move move) {
@@ -389,9 +431,9 @@
try {
Thread.sleep(SMALL_PAUSE);
} catch (Throwable t) {
- // do nothing
+ // do nothing
}
- while ((s != null) && (s.compareTo("") == 0)) {
+ while (s != null && s.compareTo("") == 0) {
s = this.reader.readLine();
}
if (s == null)
@@ -406,11 +448,10 @@
t.printStackTrace();
System.err.println(t);
throw t;
+ } catch (IOException t) {
+ t.printStackTrace();
+ System.err.println(t);
}
- catch (IOException t) {
- t.printStackTrace();
- System.err.println(t);
- }
return result;
}
@@ -439,7 +480,9 @@
return s;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterfaceRaw#regGenMove(short)
*/
public Move regGenMove(short colour) {
@@ -449,13 +492,16 @@
/**
* Sets the args.
*
- * @param args the new args
+ * @param args
+ * the new args
*/
public void setArgs(String args) {
this.args = args;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterfaceRaw#setBoardSize(short)
*/
public boolean setBoardSize(short size) {
@@ -466,19 +512,22 @@
System.err.println("clearBoard:" + s);
if (null == e)
return true;
- return false;
+ return false;
}
/**
* Sets the errReader.
*
- * @param errReader the new errReader
+ * @param errReader
+ * the new errReader
*/
public void setErrReader(BufferedReader errReader) {
this.errReader = errReader;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterfaceRaw#setKomi(double)
*/
public boolean setKomi(double komi) {
@@ -496,7 +545,8 @@
/**
* Sets the process.
*
- * @param process the new process
+ * @param process
+ * the new process
*/
public void setProcess(Process process) {
this.process = process;
@@ -505,18 +555,31 @@
/**
* Sets the reader.
*
- * @param reader the new reader
+ * @param reader
+ * the new reader
*/
public void setReader(BufferedReader reader) {
this.reader = reader;
}
- /* (non-Javadoc)
+ /**
+ * set the size
+ *
+ * @param size
+ * the size to set
+ */
+ public final void setSize(short size) {
+ this.size = size;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterfaceRaw#setTimeLeft(short, double, double)
*/
public boolean setTimeLeft(short colour, double byoYomiTime, double
byoYomiStones) {
- this.write(GTPConstants.TIMELEFT + " " + Move.colourString(colour)
+ " " + ((int) byoYomiTime) + " "
- + ((int) byoYomiStones) + "\n\n");
+ this.write(GTPConstants.TIMELEFT + " " + BoardI.colourString(colour)
+ " " + (int) byoYomiTime + " "
+ + (int) byoYomiStones + "\n\n");
String s = this.read();
Error e = GTPParserUtils.getError(s);
if (null == e)
@@ -527,12 +590,14 @@
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterfaceRaw#setTimeSettings(double, double, double)
*/
public boolean setTimeSettings(double mainTime, double byoYomiTime,
double byoYomiStones) {
- this.write(GTPConstants.TIMESETTINGS + " " + ((int) mainTime) + " "
+ ((int) byoYomiTime) + " "
- + ((int) byoYomiStones) + "\n\n");
+ this.write(GTPConstants.TIMESETTINGS + " " + (int) mainTime + " " +
(int) byoYomiTime + " "
+ + (int) byoYomiStones + "\n\n");
String s = this.read();
Error e = GTPParserUtils.getError(s);
if (null == e)
@@ -546,13 +611,16 @@
/**
* Sets the writer.
*
- * @param writer the new writer
+ * @param writer
+ * the new writer
*/
public void setWriter(Writer writer) {
this.writer = writer;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterfaceRaw#showBoard()
*/
public BoardI showBoard() {
@@ -564,7 +632,9 @@
return null;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterfaceRaw#undo()
*/
public boolean undo() {
@@ -580,7 +650,8 @@
/**
* Write.
*
- * @param s the s
+ * @param s
+ * the s
*/
protected synchronized void write(String s) {
try {
@@ -594,22 +665,6 @@
t.printStackTrace();
System.err.println(t);
}
- }
-
- /**
- * get the size
- * @return the size
- */
- public final short getSize() {
- return size;
- }
-
- /**
- * set the size
- * @param size the size to set
- */
- public final void setSize(short size) {
- this.size = size;
}
}
Modified: trunk/jgogears/jgogears/GnuGoEngineTest2.java
==============================================================================
--- trunk/jgogears/jgogears/GnuGoEngineTest2.java (original)
+++ trunk/jgogears/jgogears/GnuGoEngineTest2.java Tue Mar 4 22:17:01 2008
@@ -7,6 +7,7 @@
// TODO: Auto-generated Javadoc
/**
+ * The Class GnuGoEngineTest2.
*
* @author syeates
*/
@@ -18,7 +19,9 @@
/** The engine. */
GnuGoEngine engine = null;
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see junit.framework.TestCase#setUp()
*/
@Override
@@ -28,7 +31,9 @@
this.engine.initialise();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see junit.framework.TestCase#tearDown()
*/
@Override
@@ -41,7 +46,8 @@
/**
* Test clear board.
*
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
public final void testClearBoard() throws IOException {
this.engine.initialise();
@@ -432,7 +438,7 @@
}
/**
- * This is currently failing because I don't have good code to parse
the ASCII board back into a BoardI
+ * 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/GnuGoSeki.java
==============================================================================
--- trunk/jgogears/jgogears/GnuGoSeki.java (original)
+++ trunk/jgogears/jgogears/GnuGoSeki.java Tue Mar 4 22:17:01 2008
@@ -12,9 +12,10 @@
/**
* The main method.
*
- * @param args the args
- *
- * @throws Exception the exception
+ * @param args
+ * the args
+ * @throws Exception
+ * the exception
*/
public static void main(String[] args) throws Exception {
Stack<String> files = new Stack<String>();
@@ -49,11 +50,11 @@
/**
* Test for seki.
*
- * @param file the file
- *
+ * @param file
+ * the file
* @return true, if successful
- *
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
static public boolean testForSeki(File file) throws IOException {
@@ -62,7 +63,7 @@
System.err.println("failed to load \"" + file + "\"");
return false;
}
- if (!game.getScore().getScored() || (game.getSize() != 19))
+ if (!game.getScore().getScored() || game.getSize() != 19)
return false;
if (game.isBranched())
return false;
@@ -81,7 +82,7 @@
Date after = new Date();
System.err.println("\"" + file + "\" time = \"" + (after.getTime() -
before.getTime()) + "\" result = \""
+ game.getScore() + "\"");
- if ((stonesInSeki != null) && (stonesInSeki.size() != 0)) {
+ if (stonesInSeki != null && stonesInSeki.size() != 0) {
System.err.println("\"" + file + "\" stonesInSeki = \"" +
stonesInSeki + "\"");
return true;
} else {
@@ -92,11 +93,11 @@
/**
* Test for seki.
*
- * @param filename the filename
- *
+ * @param filename
+ * the filename
* @return true, if successful
- *
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
static public boolean testForSeki(String filename) throws IOException {
return testForSeki(new File(filename));
Modified: trunk/jgogears/jgogears/Move.java
==============================================================================
--- trunk/jgogears/jgogears/Move.java (original)
+++ trunk/jgogears/jgogears/Move.java Tue Mar 4 22:17:01 2008
@@ -10,39 +10,10 @@
public final class Move {
/**
- * Colour string.
- *
- * @param colour the colour
- *
- * @return the colour as a string
- */
- public static String colourString(int colour) {
- // find the colour of the move
- String colourS = "";
- switch (colour) {
- case BoardI.VERTEX_WHITE:
- colourS = "white";
- break;
- case BoardI.VERTEX_BLACK:
- colourS = "black";
- break;
- case BoardI.VERTEX_KO:
- colourS = "k";
- break;
- case BoardI.VERTEX_EMPTY:
- colourS = "";
- break;
- default:
- throw new java.lang.InternalError();
- }
- return colourS;
- }
-
- /**
* Create a handicap stone from a string.
*
- * @param s the s
- *
+ * @param s
+ * the s
* @return the stone as a move
*/
public static Move createHandicapStone(String s) {
@@ -70,14 +41,18 @@
* create an empty GoMove.
*/
public Move() {
+ // nothing
}
/**
* create a GoMove.
*
- * @param row the row of the move
- * @param column the column of the move
- * @param colour the colour of the move
+ * @param row
+ * the row of the move
+ * @param column
+ * the column of the move
+ * @param colour
+ * the colour of the move
*/
public Move(int row, int column, int colour) {
this.row = (short) row;
@@ -88,9 +63,12 @@
/**
* create a GoMove.
*
- * @param row the row of the move
- * @param column the column of the move
- * @param colour the colour of the move
+ * @param row
+ * the row of the move
+ * @param column
+ * the column of the move
+ * @param colour
+ * the colour of the move
*/
public Move(short row, short column, int colour) {
this.row = row;
@@ -101,9 +79,12 @@
/**
* create a GoMove.
*
- * @param row the row of the move
- * @param column the column of the move
- * @param colour the colour of the move
+ * @param row
+ * the row of the move
+ * @param column
+ * the column of the move
+ * @param colour
+ * the colour of the move
*/
public Move(short row, short column, short colour) {
this.row = row;
@@ -114,9 +95,10 @@
/**
* create a GoMove from a GTP move string.
*
- * @param move the string to parse
- *
- * @throws IllegalArgumentException the illegal argument exception
+ * @param move
+ * the string to parse
+ * @throws IllegalArgumentException
+ * the illegal argument exception
*/
public Move(String move) throws IllegalArgumentException {
// System.err.println("GoMove::GoMove(\"" + move + "\"");
@@ -139,13 +121,16 @@
this.setColumn(v.getColumn());
}
}
+
/**
* create a GoMove from a move string minus the mvoe colour
*
- * @param move the string to parse
- * @param colour the colour of the move
- *
- * @throws IllegalArgumentException the illegal argument exception
+ * @param move
+ * the string to parse
+ * @param colour
+ * the colour of the move
+ * @throws IllegalArgumentException
+ * the illegal argument exception
*/
public Move(String move, short colour) throws
IllegalArgumentException {
// System.err.println("GoMove::GoMove(\"" + move + "\"");
@@ -177,8 +162,8 @@
* get the row of this column.
*
* @return the column
- *
- * @throws Error if this is a pass move
+ * @throws Error
+ * if this is a pass move
*/
public short getColumn() {
if (this.resign)
@@ -223,8 +208,8 @@
* get the row of this column.
*
* @return the column
- *
- * @throws Error if this is a pass move
+ * @throws Error
+ * if this is a pass move
*/
public short getRow() {
if (this.resign)
@@ -237,8 +222,8 @@
/**
* Number to character.
*
- * @param s an alphabetic label from a traditional goban
- *
+ * @param s
+ * an alphabetic label from a traditional goban
* @return the corresponding (zero-indexed) integer
*/
protected String numberToCharacter(short s) {
@@ -328,8 +313,8 @@
/**
* Sets the colour.
*
- * @param colour the colour to set
- *
+ * @param colour
+ * the colour to set
* @return the move
*/
public Move setColour(short colour) {
@@ -340,8 +325,8 @@
/**
* Sets the column.
*
- * @param column the column to set
- *
+ * @param column
+ * the column to set
* @return the move
*/
public Move setColumn(short column) {
@@ -352,8 +337,8 @@
/**
* Sets the pass.
*
- * @param pass the pass to set
- *
+ * @param pass
+ * the pass to set
* @return the move
*/
public Move setPass(boolean pass) {
@@ -364,8 +349,8 @@
/**
* Sets the resign.
*
- * @param resign the resign to set
- *
+ * @param resign
+ * the resign to set
* @return the move
*/
public Move setResign(boolean resign) {
@@ -376,8 +361,8 @@
/**
* Sets the row.
*
- * @param row the row to set
- *
+ * @param row
+ * the row to set
* @return the move
*/
public Move setRow(short row) {
@@ -385,7 +370,9 @@
return this;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Object#toString()
*/
@Override
@@ -401,7 +388,7 @@
public String toStringGTP() {
// find the colour of the move
- String colourS = colourString(this.colour);
+ String colourS = BoardI.colourString(this.colour);
// calculate the position
String vertexS = this.toVertexString();
Modified: trunk/jgogears/jgogears/MoveTest.java
==============================================================================
--- trunk/jgogears/jgogears/MoveTest.java (original)
+++ trunk/jgogears/jgogears/MoveTest.java Tue Mar 4 22:17:01 2008
@@ -15,7 +15,8 @@
/**
* Test bad.
*
- * @throws ParseException the parse exception
+ * @throws ParseException
+ * the parse exception
*/
public void testBad() throws ParseException {
try {
@@ -58,7 +59,8 @@
/**
* Test gtp constructor.
*
- * @throws ParseException the parse exception
+ * @throws ParseException
+ * the parse exception
*/
public void testGTPConstructor() throws ParseException {
assertTrue(new Move("w ReSiGn").getResign() == true);
@@ -99,7 +101,8 @@
/**
* Test string conversions.
*
- * @throws ParseException the parse exception
+ * @throws ParseException
+ * the parse exception
*/
public void testStringConversions() throws ParseException {
for (int i = 0; i < 25; i++) {
@@ -124,7 +127,8 @@
/**
* Test to string.
*
- * @throws ParseException the parse exception
+ * @throws ParseException
+ * the parse exception
*/
public void testToString() throws ParseException {
System.err.println(new Move(0, 0, BoardI.VERTEX_WHITE));
Modified: trunk/jgogears/jgogears/NoKoRuleSet.java
==============================================================================
--- trunk/jgogears/jgogears/NoKoRuleSet.java (original)
+++ trunk/jgogears/jgogears/NoKoRuleSet.java Tue Mar 4 22:17:01 2008
@@ -15,7 +15,7 @@
/** The Constant DEBUG. */
final static boolean DEBUG = false;
-
+
/** The Constant EMPTY. */
final static TreeSet<Vertex> EMPTY = new TreeSet<Vertex>();
@@ -40,7 +40,7 @@
TreeSet<Vertex> captures = new TreeSet<Vertex>();
// there can only be captures when placing a stone
- if ((colour != BoardI.VERTEX_BLACK) || (colour !=
BoardI.VERTEX_WHITE)) {
+ if (colour != BoardI.VERTEX_BLACK || colour != BoardI.VERTEX_WHITE) {
captures.addAll(this.captureshelper(board, move, row + 1, column));
captures.addAll(this.captureshelper(board, move, row - 1, column));
captures.addAll(this.captureshelper(board, move, row, column + 1));
@@ -52,25 +52,28 @@
/**
* Captureshelper.
*
- * @param board the board
- * @param move the move
- * @param row the row
- * @param column the column
- *
+ * @param board
+ * the board
+ * @param move
+ * the move
+ * @param row
+ * the row
+ * @param column
+ * the column
* @return the tree set< vertex>
*/
public TreeSet<Vertex> captureshelper(BoardI board, Move move, int
row, int column) {
- if (DEBUG && (EMPTY.size() != 0))
+ if (DEBUG && EMPTY.size() != 0)
throw new Error("EMPTY not empty");
short colour = move.getColour();
- short acolour = (short) board.getColour(row, column);
- if ((acolour == BoardI.VERTEX_EMPTY) || (acolour ==
BoardI.VERTEX_KO)) {
+ short acolour = board.getColour(row, column);
+ if (acolour == BoardI.VERTEX_EMPTY || acolour == BoardI.VERTEX_KO) {
if (DEBUG)
System.err.println("captures == empty");
return EMPTY;
}
- if (((colour == BoardI.VERTEX_BLACK) && (acolour == BoardI.VERTEX_WHITE))
- || ((colour == BoardI.VERTEX_WHITE) && (acolour ==
BoardI.VERTEX_BLACK))) {
+ if (colour == BoardI.VERTEX_BLACK && acolour == BoardI.VERTEX_WHITE |
| colour == BoardI.VERTEX_WHITE
+ && acolour == BoardI.VERTEX_BLACK) {
int libs = this.countLiberties(row, column, board);
if (libs == 1) {
TreeSet<Vertex> string = this.getString(row, column, board);
@@ -97,14 +100,15 @@
return "A ko rule which doesn't recognise any form of Ko whatsoever
and allows unbounded loops and repetition.";
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.RuleSet#getLiberties(short, short, jgogears.BoardI)
*/
@Override
public TreeSet<Vertex> getLiberties(short rowb, short columnb, BoardI
board) {
- if ((board.getColour(rowb, columnb) == BoardI.VERTEX_EMPTY)
- || (board.getColour(rowb, columnb) == BoardI.VERTEX_KO)
- || (board.getColour(rowb, columnb) == BoardI.VERTEX_OFF_BOARD)) {
+ if (board.getColour(rowb, columnb) == BoardI.VERTEX_EMPTY ||
board.getColour(rowb, columnb) == BoardI.VERTEX_KO
+ || board.getColour(rowb, columnb) == BoardI.VERTEX_OFF_BOARD) {
throw new Error("empty sqaures don't have liberties");
}
@@ -116,23 +120,23 @@
Vertex current = i.next();
short row = current.getRow();
short column = current.getColumn();
- if ((board.getColour(row, column + 1) == BoardI.VERTEX_EMPTY)
- || (board.getColour(row, column + 1) == BoardI.VERTEX_KO)) {
+ if (board.getColour(row, column + 1) == BoardI.VERTEX_EMPTY
+ || board.getColour(row, column + 1) == BoardI.VERTEX_KO) {
Vertex adjacent = new Vertex(row, column + 1);
liberties.add(adjacent);
}
- if ((board.getColour(row, column - 1) == BoardI.VERTEX_EMPTY)
- || (board.getColour(row, column - 1) == BoardI.VERTEX_KO)) {
+ if (board.getColour(row, column - 1) == BoardI.VERTEX_EMPTY
+ || board.getColour(row, column - 1) == BoardI.VERTEX_KO) {
Vertex adjacent = new Vertex(row, column - 1);
liberties.add(adjacent);
}
- if ((board.getColour(row + 1, column) == BoardI.VERTEX_EMPTY)
- || (board.getColour(row + 1, column) == BoardI.VERTEX_KO)) {
+ if (board.getColour(row + 1, column) == BoardI.VERTEX_EMPTY
+ || board.getColour(row + 1, column) == BoardI.VERTEX_KO) {
Vertex adjacent = new Vertex(row + 1, column);
liberties.add(adjacent);
}
- if ((board.getColour(row - 1, column) == BoardI.VERTEX_EMPTY)
- || (board.getColour(row - 1, column) == BoardI.VERTEX_KO)) {
+ if (board.getColour(row - 1, column) == BoardI.VERTEX_EMPTY
+ || board.getColour(row - 1, column) == BoardI.VERTEX_KO) {
Vertex adjacent = new Vertex(row - 1, column);
liberties.add(adjacent);
}
@@ -150,7 +154,9 @@
return "No Ko";
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.RuleSet#getString(int, int, jgogears.BoardI)
*/
@Override
@@ -158,13 +164,15 @@
return this.getString((short) rowb, (short) columnb, board);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.RuleSet#getString(short, short, jgogears.BoardI)
*/
@Override
public TreeSet<Vertex> getString(short rowb, short columnb, BoardI
board) {
TreeSet<Vertex> string = new TreeSet<Vertex>();
- short colour = (short) board.getColour(rowb, columnb);
+ short colour = board.getColour(rowb, columnb);
if (colour == BoardI.VERTEX_OFF_BOARD)
return string;
@@ -226,11 +234,14 @@
/**
* Helper for moveIsLegal.
*
- * @param row the row of the position that is a potential liberty
- * @param column the column of the position that is a potential liberty
- * @param colour the colour of the stone we want to use these
liberties for
- * @param board the board
- *
+ * @param row
+ * the row of the position that is a potential liberty
+ * @param column
+ * the column of the position that is a potential liberty
+ * @param colour
+ * the colour of the stone we want to use these liberties for
+ * @param board
+ * the board
* @return the number of liberties through this position
*/
TreeSet<Vertex> legelsfrompos(int row, int column, short colour,
BoardI board) {
@@ -240,22 +251,25 @@
/**
* Helper for moveIsLegal.
*
- * @param row the row of the position that is a potential liberty
- * @param column the column of the position that is a potential liberty
- * @param colour the colour of the stone we want to use these
liberties for
- * @param board the board
- *
+ * @param row
+ * the row of the position that is a potential liberty
+ * @param column
+ * the column of the position that is a potential liberty
+ * @param colour
+ * the colour of the stone we want to use these liberties for
+ * @param board
+ * the board
* @return the number of liberties through this position
*/
TreeSet<Vertex> legelsfrompos(short row, short column, short colour,
BoardI board) {
TreeSet<Vertex> liberties = new TreeSet<Vertex>();
- short acolour = (short) board.getColour(row, column);
+ short acolour = board.getColour(row, column);
if (acolour == colour) {
liberties.addAll(this.getLiberties(row, column, board));
if (DEBUG)
System.err.println("position == same");
}
- if ((acolour == BoardI.VERTEX_EMPTY) || (acolour == BoardI.VERTEX_EMPTY))
+ if (acolour == BoardI.VERTEX_EMPTY || acolour == BoardI.VERTEX_EMPTY)
liberties.add(new Vertex(row, column));
return liberties;
}
@@ -283,11 +297,12 @@
short colour = move.getColour();
if (board.getColour(row, column) != BoardI.VERTEX_EMPTY) {
- if (DEBUG)System.err.println("illegal move, not empty");
+ if (DEBUG)
+ System.err.println("illegal move, not empty");
return false;
}
- if ((colour != BoardI.VERTEX_BLACK) && (colour != BoardI.VERTEX_WHITE))
+ if (colour != BoardI.VERTEX_BLACK && colour != BoardI.VERTEX_WHITE)
throw new Error();
TreeSet<Vertex> liberties = new TreeSet<Vertex>();
@@ -297,8 +312,8 @@
liberties.addAll(this.legelsfrompos(row, column - 1, colour, board));
liberties.addAll(this.captures(game, board, move));
-
- liberties.remove(new Vertex(row,column));
+
+ liberties.remove(new Vertex(row, column));
if (liberties.size() > 0)
return true;
Modified: trunk/jgogears/jgogears/NoKoRuleSetTest.java
==============================================================================
--- trunk/jgogears/jgogears/NoKoRuleSetTest.java (original)
+++ trunk/jgogears/jgogears/NoKoRuleSetTest.java Tue Mar 4 22:17:01 2008
@@ -6,7 +6,7 @@
import jgogears.engine.Model;
import junit.framework.TestCase;
-
+// TODO: Auto-generated Javadoc
/**
* The Class NoKoRuleSetTest.
*/
@@ -16,176 +16,195 @@
static final boolean DEBUG = true;
/**
- * Test center plays.
+ * Test capture complex.
*/
- public void testCenterPlays() {
+ public void testCaptureComplex() {
NoKoRuleSet rule = new NoKoRuleSet();
short size = 7;
- BoardI board = new Board(size);
- Move move = new Move(0, 1, BoardI.VERTEX_BLACK);
+ BoardI board = BoardI.newBoard(size);
+
+ Move move = null;
+
+ move = new Move(4, 3, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
- move = new Move(1, 0, BoardI.VERTEX_BLACK);
+ move = new Move(2, 3, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
- move = new Move(1, 2, BoardI.VERTEX_BLACK);
+ move = new Move(3, 4, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
- move = new Move(2, 1, BoardI.VERTEX_BLACK);
+ move = new Move(2, 4, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
-
- // System.err.println(board);
- move = new Move(1, 1, BoardI.VERTEX_WHITE);
- assertFalse(rule.moveIsLegal(null, board, move));
-
- }
-
- /**
- * Test center plays ii.
- */
- public void testCenterPlaysII() {
-
- NoKoRuleSet rule = new NoKoRuleSet();
- short size = 7;
- BoardI board = new Board(size);
- Move move = new Move(1, 2, BoardI.VERTEX_BLACK);
+ move = new Move(4, 4, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
- move = new Move(2, 1, BoardI.VERTEX_BLACK);
+ move = new Move(2, 2, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
- move = new Move(2, 3, BoardI.VERTEX_BLACK);
+ move = new Move(4, 2, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
- move = new Move(3, 2, BoardI.VERTEX_BLACK);
+
+ move = new Move(3, 3, BoardI.VERTEX_WHITE);
+ board = board.newBoard(move);
+ move = new Move(3, 2, BoardI.VERTEX_WHITE);
board = board.newBoard(move);
- // System.err.println(board);
- move = new Move(2, 2, BoardI.VERTEX_WHITE);
- assertFalse(rule.moveIsLegal(null, board, move));
+ if (DEBUG)
+ System.err.println(board);
+ move = new Move(3, 1, BoardI.VERTEX_BLACK);
+ assertTrue(rule.captures(null, board, move).size() == 2);
}
/**
- * Test center plays iii.
+ * Test capture complex ii.
*/
- public void testCenterPlaysIII() {
+ public void testCaptureComplexII() {
NoKoRuleSet rule = new NoKoRuleSet();
short size = 7;
- BoardI board = new Board(size);
- Move move = new Move(0, 1, BoardI.VERTEX_BLACK);
+ BoardI board = BoardI.newBoard(size);
+
+ Move move = null;
+
+ move = new Move(4, 3, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
- move = new Move(1, 0,BoardI.VERTEX_BLACK);
+ move = new Move(2, 3, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
- move = new Move(1, 2, BoardI.VERTEX_BLACK);
+ move = new Move(3, 4, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
- move = new Move(1, 1, BoardI.VERTEX_WHITE);
- // System.err.println(board);
- assertTrue(rule.moveIsLegal(null, board, move));
+ move = new Move(2, 4, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+ move = new Move(4, 4, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+ move = new Move(2, 2, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+ move = new Move(3, 1, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
- move = new Move(2, 1, BoardI.VERTEX_BLACK);
- assertTrue(move + "\n "
+BoardToASCII.Transform(board) ,rule.moveIsLegal(null, board, move));
- assertTrue(move + "\n "
+BoardToASCII.Transform(board) ,rule.captures(null, board, move).size()
== 1);
+ move = new Move(3, 3, BoardI.VERTEX_WHITE);
+ board = board.newBoard(move);
+ move = new Move(3, 2, BoardI.VERTEX_WHITE);
+ board = board.newBoard(move);
+ move = new Move(5, 2, BoardI.VERTEX_WHITE);
+ board = board.newBoard(move);
+ move = new Move(4, 1, BoardI.VERTEX_WHITE);
board = board.newBoard(move);
- move = new Move(1, 1, BoardI.VERTEX_WHITE);
- assertFalse(move + "\n "
+BoardToASCII.Transform(board) ,rule.moveIsLegal(null, board, move));
- board = board.newBoard(new Move().setPass(true));
- move = new Move(1, 1, BoardI.VERTEX_BLACK);
- assertTrue(move + "\n "
+BoardToASCII.Transform(board) ,rule.moveIsLegal(null, board, move));
+ if (DEBUG)
+ System.err.println(board);
+ move = new Move(3, 2, BoardI.VERTEX_BLACK);
- // System.err.println(board);
+ assertTrue(rule.captures(null, board, move).size() == 2);
}
/**
- * Test center plays iiii.
+ * Test capture complex iii.
*/
- public void testCenterPlaysIIII() {
+ public void testCaptureComplexIII() {
NoKoRuleSet rule = new NoKoRuleSet();
short size = 7;
- BoardI board = new Board(size);
+ BoardI board = BoardI.newBoard(size);
- Move move = new Move(3, 3, BoardI.VERTEX_BLACK);
- assertTrue(rule.moveIsLegal(null, board, move));
- assertTrue(rule.captures(null, board, move).size() == 0);
- board = board.newBoard(move);
- assertTrue("" + rule.countLiberties(3, 3, board),
rule.countLiberties(3, 3, board) == 4);
-
- move = new Move(2, 3, BoardI.VERTEX_BLACK);
- assertTrue(rule.moveIsLegal(null, board, move));
- assertTrue(rule.captures(null, board, move).size() == 0);
- board = board.newBoard(move);
- assertTrue("" + rule.countLiberties(2, 3, board),
rule.countLiberties(3, 3, board) == 6);
+ Move move = null;
move = new Move(4, 3, BoardI.VERTEX_BLACK);
- assertTrue(rule.moveIsLegal(null, board, move));
- assertTrue(rule.captures(null, board, move).size() == 0);
board = board.newBoard(move);
- assertTrue("" + rule.countLiberties(4, 3, board),
rule.countLiberties(3, 3, board) == 8);
-
- move = new Move(3, 2, BoardI.VERTEX_BLACK);
- assertTrue(rule.moveIsLegal(null, board, move));
- assertTrue(rule.captures(null, board, move).size() == 0);
+ move = new Move(2, 3, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
- assertTrue("" + rule.countLiberties(3, 2, board),
rule.countLiberties(3, 3, board) == 8);
-
move = new Move(3, 4, BoardI.VERTEX_BLACK);
- assertTrue(rule.moveIsLegal(null, board, move));
- assertTrue(rule.captures(null, board, move).size() == 0);
board = board.newBoard(move);
- assertTrue("" + rule.countLiberties(3, 4, board),
rule.countLiberties(3, 3, board) == 8);
+ move = new Move(2, 4, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+ move = new Move(4, 4, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+ move = new Move(2, 2, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+ move = new Move(3, 1, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+ move = new Move(4, 0, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+ move = new Move(5, 3, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+ move = new Move(6, 2, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
- }
+ move = new Move(3, 3, BoardI.VERTEX_WHITE);
+ board = board.newBoard(move);
+ move = new Move(3, 2, BoardI.VERTEX_WHITE);
+ board = board.newBoard(move);
+ move = new Move(5, 2, BoardI.VERTEX_WHITE);
+ board = board.newBoard(move);
+ move = new Move(4, 1, BoardI.VERTEX_WHITE);
+ board = board.newBoard(move);
- public void testNoCenterPlay() {
+ if (DEBUG)
+ System.err.println(board);
+ move = new Move(4, 2, BoardI.VERTEX_BLACK);
- NoKoRuleSet rule = new NoKoRuleSet();
- short size = 7;
- BoardI board = new Board(size);
+ assertTrue(rule.captures(null, board, move).size() == 2);
+ move = new Move(4, 2, BoardI.VERTEX_WHITE);
+ board = board.newBoard(move);
+ if (DEBUG)
+ System.err.println(board);
+ move = new Move(5, 1, BoardI.VERTEX_BLACK);
+ assertTrue(rule.captures(null, board, move).size() + " ",
rule.captures(null, board, move).size() == 5);
+ board = board.newBoard(move);
+ if (DEBUG)
+ System.err.println(board);
- Move move = null;
-
- move = new Move(4, 3, BoardI.VERTEX_BLACK);
+ move = new Move(3, 3, BoardI.VERTEX_WHITE);
board = board.newBoard(move);
- move = new Move(2, 3, BoardI.VERTEX_BLACK);
+ move = new Move(5, 2, BoardI.VERTEX_WHITE);
board = board.newBoard(move);
- move = new Move(3, 2, BoardI.VERTEX_BLACK);
+ move = new Move(4, 1, BoardI.VERTEX_WHITE);
board = board.newBoard(move);
- move = new Move(3, 4, BoardI.VERTEX_BLACK);
+ move = new Move(3, 2, BoardI.VERTEX_WHITE);
board = board.newBoard(move);
+ if (DEBUG)
+ System.err.println(board);
- move = new Move(2, 3, BoardI.VERTEX_WHITE);
- }
+ move = new Move(4, 2, BoardI.VERTEX_WHITE);
+ assertFalse(rule.moveIsLegal(null, board, move));
+ }
+
+ /**
+ * Test capture i.
+ */
public void testCaptureI() {
NoKoRuleSet rule = new NoKoRuleSet();
short size = 7;
- BoardI board = new Board(size);
+ BoardI board = BoardI.newBoard(size);
+
+ Move move = null;
- Move move = null;
-
move = new Move(4, 3, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
move = new Move(2, 3, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
move = new Move(3, 4, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
-
+
move = new Move(3, 3, BoardI.VERTEX_WHITE);
board = board.newBoard(move);
- if (DEBUG)
+ if (DEBUG)
System.err.println(board);
move = new Move(3, 2, BoardI.VERTEX_BLACK);
assertTrue(rule.captures(null, board, move).size() == 1);
- }
+ }
+
+ /**
+ * Test capture ii.
+ */
public void testCaptureII() {
NoKoRuleSet rule = new NoKoRuleSet();
short size = 7;
- BoardI board = new Board(size);
+ BoardI board = BoardI.newBoard(size);
+
+ Move move = null;
- Move move = null;
-
move = new Move(4, 3, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
move = new Move(2, 3, BoardI.VERTEX_BLACK);
@@ -197,15 +216,19 @@
move = new Move(3, 4, BoardI.VERTEX_BLACK);
assertTrue(rule.captures(null, board, move).size() == 1);
- }
+ }
+
+ /**
+ * Test capture iii.
+ */
public void testCaptureIII() {
NoKoRuleSet rule = new NoKoRuleSet();
short size = 7;
- BoardI board = new Board(size);
+ BoardI board = BoardI.newBoard(size);
+
+ Move move = null;
- Move move = null;
-
move = new Move(4, 3, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
move = new Move(3, 4, BoardI.VERTEX_BLACK);
@@ -217,15 +240,19 @@
move = new Move(2, 3, BoardI.VERTEX_BLACK);
assertTrue(rule.captures(null, board, move).size() == 1);
- }
+ }
+
+ /**
+ * Test capture iiii.
+ */
public void testCaptureIIII() {
NoKoRuleSet rule = new NoKoRuleSet();
short size = 7;
- BoardI board = new Board(size);
+ BoardI board = BoardI.newBoard(size);
+
+ Move move = null;
- Move move = null;
-
move = new Move(3, 4, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
move = new Move(2, 3, BoardI.VERTEX_BLACK);
@@ -237,7 +264,127 @@
move = new Move(4, 3, BoardI.VERTEX_BLACK);
assertTrue(rule.captures(null, board, move).size() == 1);
- }
+ }
+
+ /**
+ * Test center plays.
+ */
+ public void testCenterPlays() {
+
+ NoKoRuleSet rule = new NoKoRuleSet();
+ short size = 7;
+ BoardI board = BoardI.newBoard(size);
+ Move move = new Move(0, 1, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+ move = new Move(1, 0, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+ move = new Move(1, 2, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+ move = new Move(2, 1, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+
+ // System.err.println(board);
+ move = new Move(1, 1, BoardI.VERTEX_WHITE);
+ assertFalse(rule.moveIsLegal(null, board, move));
+
+ }
+
+ /**
+ * Test center plays ii.
+ */
+ public void testCenterPlaysII() {
+
+ NoKoRuleSet rule = new NoKoRuleSet();
+ short size = 7;
+ BoardI board = BoardI.newBoard(size);
+ Move move = new Move(1, 2, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+ move = new Move(2, 1, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+ move = new Move(2, 3, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+ move = new Move(3, 2, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+
+ // System.err.println(board);
+ move = new Move(2, 2, BoardI.VERTEX_WHITE);
+ assertFalse(rule.moveIsLegal(null, board, move));
+
+ }
+
+ /**
+ * Test center plays iii.
+ */
+ public void testCenterPlaysIII() {
+
+ NoKoRuleSet rule = new NoKoRuleSet();
+ short size = 7;
+ BoardI board = BoardI.newBoard(size);
+ Move move = new Move(0, 1, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+ move = new Move(1, 0, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+ move = new Move(1, 2, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+ move = new Move(1, 1, BoardI.VERTEX_WHITE);
+ // System.err.println(board);
+ assertTrue(rule.moveIsLegal(null, board, move));
+ board = board.newBoard(move);
+
+ move = new Move(2, 1, BoardI.VERTEX_BLACK);
+ assertTrue(move + "\n " + BoardToASCII.Transform(board),
rule.moveIsLegal(null, board, move));
+ assertTrue(move + "\n " + BoardToASCII.Transform(board),
rule.captures(null, board, move).size() == 1);
+ board = board.newBoard(move);
+
+ move = new Move(1, 1, BoardI.VERTEX_WHITE);
+ assertFalse(move + "\n " + BoardToASCII.Transform(board),
rule.moveIsLegal(null, board, move));
+ board = board.newBoard(new Move().setPass(true));
+ move = new Move(1, 1, BoardI.VERTEX_BLACK);
+ assertTrue(move + "\n " + BoardToASCII.Transform(board),
rule.moveIsLegal(null, board, move));
+
+ // System.err.println(board);
+ }
+
+ /**
+ * Test center plays iiii.
+ */
+ public void testCenterPlaysIIII() {
+
+ NoKoRuleSet rule = new NoKoRuleSet();
+ short size = 7;
+ BoardI board = BoardI.newBoard(size);
+
+ Move move = new Move(3, 3, BoardI.VERTEX_BLACK);
+ assertTrue(rule.moveIsLegal(null, board, move));
+ assertTrue(rule.captures(null, board, move).size() == 0);
+ board = board.newBoard(move);
+ assertTrue("" + rule.countLiberties(3, 3, board),
rule.countLiberties(3, 3, board) == 4);
+
+ move = new Move(2, 3, BoardI.VERTEX_BLACK);
+ assertTrue(rule.moveIsLegal(null, board, move));
+ assertTrue(rule.captures(null, board, move).size() == 0);
+ board = board.newBoard(move);
+ assertTrue("" + rule.countLiberties(2, 3, board),
rule.countLiberties(3, 3, board) == 6);
+
+ move = new Move(4, 3, BoardI.VERTEX_BLACK);
+ assertTrue(rule.moveIsLegal(null, board, move));
+ assertTrue(rule.captures(null, board, move).size() == 0);
+ board = board.newBoard(move);
+ assertTrue("" + rule.countLiberties(4, 3, board),
rule.countLiberties(3, 3, board) == 8);
+
+ move = new Move(3, 2, BoardI.VERTEX_BLACK);
+ assertTrue(rule.moveIsLegal(null, board, move));
+ assertTrue(rule.captures(null, board, move).size() == 0);
+ board = board.newBoard(move);
+ assertTrue("" + rule.countLiberties(3, 2, board),
rule.countLiberties(3, 3, board) == 8);
+
+ move = new Move(3, 4, BoardI.VERTEX_BLACK);
+ assertTrue(rule.moveIsLegal(null, board, move));
+ assertTrue(rule.captures(null, board, move).size() == 0);
+ board = board.newBoard(move);
+ assertTrue("" + rule.countLiberties(3, 4, board),
rule.countLiberties(3, 3, board) == 8);
+
+ }
/**
* Test corner plays.
@@ -249,7 +396,7 @@
NoKoRuleSet rule = new NoKoRuleSet();
short size = 7;
Game game = new Game(19);
- BoardI board = new Board(size);
+ BoardI board = BoardI.newBoard(size);
Move move = new Move(0, 1, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
move = new Move(1, 1, BoardI.VERTEX_BLACK);
@@ -291,9 +438,67 @@
// System.err.println(board);
move = new Move(0, 0, BoardI.VERTEX_WHITE);
- assertTrue(move + "\n "
+BoardToASCII.Transform(board) ,rule.moveIsLegal(game, board, move));
- assertTrue(move + "\n "
+BoardToASCII.Transform(board) ,rule.captures(game, board, move).size()
== 3);
+ assertTrue(move + "\n " + BoardToASCII.Transform(board),
rule.moveIsLegal(game, board, move));
+ assertTrue(move + "\n " + BoardToASCII.Transform(board),
rule.captures(game, board, move).size() == 3);
+ board = board.newBoard(move);
+ }
+
+ /**
+ * Test handcrafted tiny i.
+ */
+ public void testHandcraftedTinyI() {
+
+ NoKoRuleSet rule = new NoKoRuleSet();
+ short size = 19;
+ BoardI board = BoardI.newBoard(size);
+
+ Move move = null;
+
+ move = new Move(0, 0, BoardI.VERTEX_WHITE);
+ board = board.newBoard(move);
+ move = new Move(0, 1, BoardI.VERTEX_BLACK);
+ assertTrue(rule.captures(null, board, move).size() == 0);
+ assertTrue(rule.leavesKo(null, board, move).size() + "",
rule.leavesKo(null, board, move).size() == 0);
+ board = board.newBoard(move);
+ if (DEBUG)
+ System.err.println(board);
+
+ move = new Move(1, 0, BoardI.VERTEX_BLACK);
+ assertTrue(rule.captures(null, board, move).size() == 1);
+ assertTrue(rule.leavesKo(null, board, move).size() == 0);
board = board.newBoard(move);
+ if (DEBUG)
+ System.err.println(board);
+
+ }
+
+ /**
+ * Test handcrafted tiny ii.
+ */
+ public void testHandcraftedTinyII() {
+
+ NoKoRuleSet rule = new NoKoRuleSet();
+ short size = 19;
+ BoardI board = BoardI.newBoard(size);
+
+ Move move = null;
+
+ move = new Move(0, 0, BoardI.VERTEX_WHITE);
+ board = board.newBoard(move);
+ move = new Move(0, 1, BoardI.VERTEX_BLACK);
+ assertTrue(rule.captures(null, board, move).size() == 0);
+ assertTrue(rule.leavesKo(null, board, move).size() + "",
rule.leavesKo(null, board, move).size() == 0);
+ board = board.newBoard(move);
+ if (DEBUG)
+ System.err.println(board);
+
+ move = new Move(0, 2, BoardI.VERTEX_BLACK);
+ assertTrue(rule.captures(null, board, move).size() == 0);
+ assertTrue(rule.leavesKo(null, board, move).size() == 0);
+ board = board.newBoard(move);
+
+ if (DEBUG)
+ System.err.println(board);
}
/**
@@ -315,7 +520,7 @@
for (short k = 0; k < size; k++)
for (short l = 0; l < size; l++) {
- BoardI board = new Board(size);
+ BoardI board = BoardI.newBoard(size);
assertNotNull(board);
Move move = new Move(k, l, BoardI.VERTEX_BLACK);
assertNotNull(move);
@@ -334,13 +539,13 @@
assertNotNull(liberties);
short count = rule.countLiberties(k, l, board);
assertNotNull(count == liberties.size());
- if ((k == 0) || (k == size - 1))
- if ((l == 0) || (l == size - 1)) {
+ if (k == 0 || k == size - 1)
+ if (l == 0 || l == size - 1) {
assertTrue(liberties.size() == 2);
} else {
assertTrue(liberties.size() == 3);
}
- else if ((l == 0) || (l == size - 1)) {
+ else if (l == 0 || l == size - 1) {
assertTrue(liberties.size() == 3);
} else {
assertTrue(liberties.size() == 4);
@@ -356,7 +561,7 @@
NoKoRuleSet rule = new NoKoRuleSet();
short size = 7;
- BoardI board = new Board(size);
+ BoardI board = BoardI.newBoard(size);
assertNotNull(board);
Move move = new Move(3, 1, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
@@ -390,7 +595,7 @@
NoKoRuleSet rule = new NoKoRuleSet();
short size = 7;
- BoardI board = new Board(size);
+ BoardI board = BoardI.newBoard(size);
assertNotNull(board);
Move move = new Move(1, 0, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
@@ -416,7 +621,8 @@
/**
* Test load all sg ffiles.
*
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
public void testLoadAllSGFfiles() throws IOException {
Stack<String> files = new Stack<String>();
@@ -429,7 +635,7 @@
assertNotNull(model);
RuleSet rule = new NoKoRuleSet();
- while ((files.size() > 0) && (filecount < 10)) {
+ while (files.size() > 0 && filecount < 10) {
String filename = files.pop();
File file = new File(filename);
if (file.exists()) {
@@ -439,14 +645,14 @@
filecount++;
Game game = Game.loadFromFile(file);
- BoardI board = new Board(game.getSize());
+ BoardI board = BoardI.newBoard(game.getSize());
System.err.println(filename);
Iterator<Move> i = game.getMovelist().iterator();
while (i.hasNext()) {
Move move = i.next();
if (!rule.moveIsLegal(game, board, move)) {
- assertTrue(move + "\n " +BoardToASCII.Transform(board) ,false);
+ assertTrue(move + "\n " + BoardToASCII.Transform(board), false);
}
board = board.newBoard(move);
}
@@ -461,6 +667,28 @@
}
/**
+ * Test no center play.
+ */
+ public void testNoCenterPlay() {
+
+ short size = 7;
+ BoardI board = BoardI.newBoard(size);
+
+ Move move = null;
+
+ move = new Move(4, 3, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+ move = new Move(2, 3, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+ move = new Move(3, 2, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+ move = new Move(3, 4, BoardI.VERTEX_BLACK);
+ board = board.newBoard(move);
+
+ move = new Move(2, 3, BoardI.VERTEX_WHITE);
+ }
+
+ /**
* Test string almost empty board.
*/
public void testStringAlmostEmptyBoard() {
@@ -471,7 +699,7 @@
for (short j = 0; j < size; j++)
for (short k = 0; k < size; k++)
for (short l = 0; l < size; l++) {
- BoardI board = new Board(size);
+ BoardI board = BoardI.newBoard(size);
assertNotNull(board);
Move move = new Move(k, l, BoardI.VERTEX_BLACK);
assertNotNull(move);
@@ -485,7 +713,7 @@
TreeSet<Vertex> string = rule.getString(i, j, board);
assertNotNull(string);
- if ((i != k) || (j != l))
+ if (i != k || j != l)
assertTrue("" + i + " / " + j + " / " + k + " / " + l + " / " +
string.size() + " / "
+ (size * size - 1) + " (" + string + ")", string.size() ==
size * size - 1);
else
@@ -501,7 +729,7 @@
public void testStringEmptyBoard() {
NoKoRuleSet rule = new NoKoRuleSet();
short size = 7;
- Board board = new Board(size);
+ BoardI board = BoardI.newBoard(size);
for (short i = 0; i < size; i++)
for (short j = 0; j < size; j++) {
@@ -518,7 +746,7 @@
public void testStringOffBoard() {
NoKoRuleSet rule = new NoKoRuleSet();
short size = 7;
- Board board = new Board(size);
+ BoardI board = BoardI.newBoard(size);
TreeSet<Vertex> string = rule.getString((short) -1, (short) -1, board);
assertNotNull(string);
@@ -542,7 +770,7 @@
NoKoRuleSet rule = new NoKoRuleSet();
short size = 7;
- BoardI board = new Board(size);
+ BoardI board = BoardI.newBoard(size);
assertNotNull(board);
Move move = new Move(1, 1, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
@@ -565,7 +793,7 @@
NoKoRuleSet rule = new NoKoRuleSet();
short size = 7;
- BoardI board = new Board(size);
+ BoardI board = BoardI.newBoard(size);
assertNotNull(board);
Move move = new Move(1, 1, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
@@ -588,7 +816,7 @@
NoKoRuleSet rule = new NoKoRuleSet();
short size = 7;
- BoardI board = new Board(size);
+ BoardI board = BoardI.newBoard(size);
assertNotNull(board);
Move move = new Move(1, 1, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
@@ -611,7 +839,7 @@
NoKoRuleSet rule = new NoKoRuleSet();
short size = 7;
- BoardI board = new Board(size);
+ BoardI board = BoardI.newBoard(size);
assertNotNull(board);
Move move = new Move(1, 0, BoardI.VERTEX_BLACK);
board = board.newBoard(move);
@@ -638,149 +866,5 @@
assertTrue(string.size() == size * (size - 2));
}
-
- public void testCaptureComplex() {
-
- NoKoRuleSet rule = new NoKoRuleSet();
- short size = 7;
- BoardI board = new Board(size);
-
- Move move = null;
-
- move = new Move(4, 3, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
- move = new Move(2, 3, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
- move = new Move(3, 4, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
- move = new Move(2, 4, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
- move = new Move(4, 4, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
- move = new Move(2, 2, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
- move = new Move(4, 2, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
-
- move = new Move(3, 3, BoardI.VERTEX_WHITE);
- board = board.newBoard(move);
- move = new Move(3, 2, BoardI.VERTEX_WHITE);
- board = board.newBoard(move);
-
- if (DEBUG)
- System.err.println(board);
- move = new Move(3, 1, BoardI.VERTEX_BLACK);
-
- assertTrue(rule.captures(null, board, move).size() == 2);
- }
-
- public void testCaptureComplexII() {
-
- NoKoRuleSet rule = new NoKoRuleSet();
- short size = 7;
- BoardI board = new Board(size);
-
- Move move = null;
-
- move = new Move(4, 3, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
- move = new Move(2, 3, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
- move = new Move(3, 4, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
- move = new Move(2, 4, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
- move = new Move(4, 4, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
- move = new Move(2, 2, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
- move = new Move(3, 1, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
-
- move = new Move(3, 3, BoardI.VERTEX_WHITE);
- board = board.newBoard(move);
- move = new Move(3, 2, BoardI.VERTEX_WHITE);
- board = board.newBoard(move);
- move = new Move(5, 2, BoardI.VERTEX_WHITE);
- board = board.newBoard(move);
- move = new Move(4, 1, BoardI.VERTEX_WHITE);
- board = board.newBoard(move);
-
- if (DEBUG)
- System.err.println(board);
- move = new Move(3, 2, BoardI.VERTEX_BLACK);
-
- assertTrue(rule.captures(null, board, move).size() == 2);
- }
- public void testCaptureComplexIII() {
-
- NoKoRuleSet rule = new NoKoRuleSet();
- short size = 7;
- BoardI board = new Board(size);
-
- Move move = null;
-
- move = new Move(4, 3, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
- move = new Move(2, 3, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
- move = new Move(3, 4, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
- move = new Move(2, 4, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
- move = new Move(4, 4, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
- move = new Move(2, 2, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
- move = new Move(3, 1, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
- move = new Move(4, 0, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
- move = new Move(5, 3, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
- move = new Move(6, 2, BoardI.VERTEX_BLACK);
- board = board.newBoard(move);
-
- move = new Move(3, 3, BoardI.VERTEX_WHITE);
- board = board.newBoard(move);
- move = new Move(3, 2, BoardI.VERTEX_WHITE);
- board = board.newBoard(move);
- move = new Move(5, 2, BoardI.VERTEX_WHITE);
- board = board.newBoard(move);
- move = new Move(4, 1, BoardI.VERTEX_WHITE);
- board = board.newBoard(move);
-
- if (DEBUG)
- System.err.println(board);
- move = new Move(4, 2, BoardI.VERTEX_BLACK);
-
- assertTrue(rule.captures(null, board, move).size() == 2);
- move = new Move(4, 2, BoardI.VERTEX_WHITE);
- board = board.newBoard(move);
- if (DEBUG)
- System.err.println(board);
- move = new Move(5, 1, BoardI.VERTEX_BLACK);
- assertTrue(rule.captures(null, board, move).size() + " ",
rule.captures(null, board, move).size() == 5);
- board = board.newBoard(move);
- if (DEBUG)
- System.err.println(board);
-
- move = new Move(3, 3, BoardI.VERTEX_WHITE);
- board = board.newBoard(move);
- move = new Move(5, 2, BoardI.VERTEX_WHITE);
- board = board.newBoard(move);
- move = new Move(4, 1, BoardI.VERTEX_WHITE);
- board = board.newBoard(move);
- move = new Move(3, 2, BoardI.VERTEX_WHITE);
- board = board.newBoard(move);
- if (DEBUG)
- System.err.println(board);
-
- move = new Move(4, 2, BoardI.VERTEX_WHITE);
- assertFalse(rule.moveIsLegal(null, board, move));
-
-
-
- }
}
Modified: trunk/jgogears/jgogears/RandomEngine.java
==============================================================================
--- trunk/jgogears/jgogears/RandomEngine.java (original)
+++ trunk/jgogears/jgogears/RandomEngine.java Tue Mar 4 22:17:01 2008
@@ -11,7 +11,9 @@
/** The random. */
public Random random = new Random(0);
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterface#finalStatusList(java.lang.String, jgogears.GTPState)
*/
public Move[] finalStatusList(String status, GTPState state) {
@@ -20,21 +22,27 @@
return null;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterface#getEngineName()
*/
public String getEngineName() {
return "Mii / Barrotts Reef";
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterface#getEngineVersion()
*/
public String getEngineVersion() {
return "00.001" + new Date();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterface#getFinalScore(jgogears.GTPState)
*/
public GTPScore getFinalScore(GTPState state) {
@@ -42,7 +50,9 @@
return new GTPScore("?");
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterface#regGenMove(int, jgogears.GTPState)
*/
public Move regGenMove(int colour, GTPState state) {
@@ -59,8 +69,8 @@
/**
* Score.
*
- * @param state the state
- *
+ * @param state
+ * the state
* @return the gTP score
*/
public GTPScore score(GTPState state) {
Modified: trunk/jgogears/jgogears/Rank.java
==============================================================================
--- trunk/jgogears/jgogears/Rank.java (original)
+++ trunk/jgogears/jgogears/Rank.java Tue Mar 4 22:17:01 2008
@@ -12,38 +12,38 @@
/** The Constant SHODAN. */
public final static Rank SHODAN = new Rank("1d");
-
+
/** The Constant BEGINNER. */
public final static Rank BEGINNER = new Rank("25k");
-
+
/** The Constant ME. */
public final static Rank ME = new Rank("12k");
/** The Constant TESTING. */
final static boolean TESTING = false;
-
+
/** The Constant MAX_RANK. */
final static double MAX_RANK = 80;
-
+
/** The Constant MIN_RANK. */
final static double MIN_RANK = 130;
/** The Constant MAX_RATING. */
final static double MAX_RATING = 1;
-
+
/** The Constant MIN_RATING. */
final static double MIN_RATING = 0;
/**
* Check rank.
*
- * @param ranking the ranking
- *
+ * @param ranking
+ * the ranking
* @return true, if successful
*/
static boolean checkRank(double ranking) {
if (TESTING)
- if ((ranking > MAX_RATING) || (ranking < MIN_RATING))
+ if (ranking > MAX_RATING || ranking < MIN_RATING)
throw new Error("bad ranking " + ranking);
return true;
}
@@ -51,13 +51,13 @@
/**
* Check rating.
*
- * @param rating the rating
- *
+ * @param rating
+ * the rating
* @return true, if successful
*/
static boolean checkRating(double rating) {
if (TESTING)
- if ((rating > MAX_RATING) || (rating < MIN_RATING))
+ if (rating > MAX_RATING || rating < MIN_RATING)
throw new Error("bad rating " + rating);
return true;
}
@@ -65,12 +65,12 @@
/**
* Convert.
*
- * @param r the r
- *
+ * @param r
+ * the r
* @return the int
*/
public static int convert(String r) {
- if ((r == null) || (r.length() < 2))
+ if (r == null || r.length() < 2)
return (int) BEGINNER.getRank();
r = r.toLowerCase();
int offset = 0;
@@ -110,7 +110,8 @@
/**
* Instantiates a new rank.
*
- * @param r the r
+ * @param r
+ * the r
*/
public Rank(double r) {
if (TESTING)
@@ -123,7 +124,8 @@
/**
* Instantiates a new rank.
*
- * @param r the r
+ * @param r
+ * the r
*/
public Rank(String r) {
this.rank = convert(r);
@@ -161,13 +163,16 @@
/**
* Sets the rank.
*
- * @param rank the new rank
+ * @param rank
+ * the new rank
*/
public void setRank(double rank) {
this.rank = rank;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Object#toString()
*/
@Override
Modified: trunk/jgogears/jgogears/RuleSet.java
==============================================================================
--- trunk/jgogears/jgogears/RuleSet.java (original)
+++ trunk/jgogears/jgogears/RuleSet.java Tue Mar 4 22:17:01 2008
@@ -12,16 +12,20 @@
* @author Stuart
*/
public abstract class RuleSet {
-
+ /**
+ * The default ruleset
+ */
static public final RuleSet DEFAULT = new NoKoRuleSet();
-
+
/**
* Captures.
*
- * @param game the game
- * @param move the move
- * @param board the board
- *
+ * @param game
+ * the game
+ * @param move
+ * the move
+ * @param board
+ * the board
* @return the tree set< vertex>
*/
public abstract TreeSet<Vertex> captures(Game game, BoardI board,
Move move);
@@ -29,10 +33,12 @@
/**
* Count liberties.
*
- * @param rowb the rowb
- * @param columnb the columnb
- * @param board the board
- *
+ * @param rowb
+ * the rowb
+ * @param columnb
+ * the columnb
+ * @param board
+ * the board
* @return the short
*/
public short countLiberties(int rowb, int columnb, BoardI board) {
@@ -42,15 +48,50 @@
/**
* Count liberties.
*
- * @param rowb the rowb
- * @param columnb the columnb
- * @param board the board
- *
+ * @param rowb
+ * the rowb
+ * @param columnb
+ * the columnb
+ * @param board
+ * the board
* @return the short
*/
public short countLiberties(short rowb, short columnb, BoardI board) {
return (short) this.getLiberties(rowb, columnb, board).size();
}
+ /**
+ * Get all the legal moves
+ * @param game the game being played
+ * @param board the current state of the baord
+ * @param colour the colour being played
+ * @return the collection of moves
+ */
+
+ public Collection<Move> getAllLegalMoves(Game game, BoardI board,
short colour) {
+ Stack<Move> moves = new Stack<Move>();
+ for (int i = 0; i < board.getSize(); i++)
+ for (int j = 0; j < board.getSize(); j++) {
+ Move move = new Move(i, j, colour);
+ if (this.moveIsLegal(null, board, move))
+ moves.push(move);
+ }
+ return moves;
+ }
+/**
+ * Get all the legal moves
+ * @param game the game being played
+ * @param board the current state of the baord
+ * @param colour the colour being played
+ * @return the collection of vertexes
+ */
+ public Collection<Vertex> getAllLegalVertexes(Game game, BoardI
board, short colour) {
+ Stack<Vertex> moves = new Stack<Vertex>();
+ for (int i = 0; i < board.getSize(); i++)
+ for (int j = 0; j < board.getSize(); j++)
+ if (this.moveIsLegal(null, board, new Move(i, j, colour)))
+ moves.push(new Vertex(i, j));
+ return moves;
+ }
/**
* Get a description of this Ko rule.
@@ -62,10 +103,12 @@
/**
* Gets the liberties.
*
- * @param rowb the rowb
- * @param columnb the columnb
- * @param board the board
- *
+ * @param rowb
+ * the rowb
+ * @param columnb
+ * the columnb
+ * @param board
+ * the board
* @return the liberties
*/
public TreeSet<Vertex> getLiberties(int rowb, int columnb, BoardI
board) {
@@ -75,10 +118,12 @@
/**
* Gets the liberties.
*
- * @param rowb the rowb
- * @param columnb the columnb
- * @param board the board
- *
+ * @param rowb
+ * the rowb
+ * @param columnb
+ * the columnb
+ * @param board
+ * the board
* @return the liberties
*/
abstract public TreeSet<Vertex> getLiberties(short rowb, short
columnb, BoardI board);
@@ -93,10 +138,12 @@
/**
* Gets the string.
*
- * @param row the row
- * @param column the column
- * @param board the board
- *
+ * @param row
+ * the row
+ * @param column
+ * the column
+ * @param board
+ * the board
* @return the string
*/
TreeSet<Vertex> getString(int row, int column, BoardI board) {
@@ -106,10 +153,12 @@
/**
* Helper function to get a string containing this position.
*
- * @param row the row
- * @param column the column
- * @param board the board
- *
+ * @param row
+ * the row
+ * @param column
+ * the column
+ * @param board
+ * the board
* @return the string
*/
abstract public TreeSet<Vertex> getString(short row, short column,
BoardI board);
@@ -117,10 +166,12 @@
/**
* Leaves ko.
*
- * @param game the game
- * @param move the move
- * @param board the board
- *
+ * @param game
+ * the game
+ * @param move
+ * the move
+ * @param board
+ * the board
* @return the tree set< vertex>
*/
public abstract TreeSet<Vertex> leavesKo(Game game, BoardI board,
Move move);
@@ -128,35 +179,14 @@
/**
* Is this move legal, given this board in this game?.
*
- * @param game the game
- * @param move the move
- * @param board the board
- *
+ * @param game
+ * the game
+ * @param move
+ * the move
+ * @param board
+ * the board
* @return true, if move is legal
*/
public abstract boolean moveIsLegal(Game game, BoardI board, Move move);
-
-
- public Collection<Move> getAllLegalMoves(Game game, BoardI board,
short colour){
- Stack<Move> moves = new Stack<Move>();
- for (int i=0;i<board.getSize();i++)
- for (int j=0;j<board.getSize();j++){
- Move move = new Move(i,j,colour);
- if (this.moveIsLegal(null, board, move))
- moves.push(move);
- }
- return moves;
- }
-
-
- public Collection<Vertex> getAllLegalVertexes(Game game, BoardI
board, short colour){
- Stack<Vertex> moves = new Stack<Vertex>();
- for (int i=0;i<board.getSize();i++)
- for (int j=0;j<board.getSize();j++)
- if (this.moveIsLegal(null, board, new Move(i,j,colour)))
- moves.push(new Vertex(i,j));
- return moves;
- }
-
}
Modified: trunk/jgogears/jgogears/SGFGameTest.java
==============================================================================
--- trunk/jgogears/jgogears/SGFGameTest.java (original)
+++ trunk/jgogears/jgogears/SGFGameTest.java Tue Mar 4 22:17:01 2008
@@ -18,7 +18,8 @@
/**
* Test is verbose.
*
- * @throws ParseException the parse exception
+ * @throws ParseException
+ * the parse exception
*/
public void testIsVerbose() throws ParseException {
@@ -44,7 +45,8 @@
/**
* Test load.
*
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
public void testLoad() throws IOException {
try {
Modified: trunk/jgogears/jgogears/SGFGameTree.java
==============================================================================
--- trunk/jgogears/jgogears/SGFGameTree.java (original)
+++ trunk/jgogears/jgogears/SGFGameTree.java Tue Mar 4 22:17:01 2008
@@ -13,8 +13,8 @@
/**
* Load an SGF tree from a file
*
- * @param file the file
- *
+ * @param file
+ * the file
* @return the game
*/
public static Game loadFromFile(File file) {
@@ -49,7 +49,8 @@
/**
* Inits the.
*
- * @param game the game
+ * @param game
+ * the game
*/
protected void init(Game game) {
if (game == null)
@@ -74,8 +75,8 @@
Iterator<SGFProperty> iterator = node.properties.iterator();
while (iterator.hasNext()) {
SGFProperty prop = iterator.next();
- if ((prop.getIdentifier().compareToIgnoreCase("B") == 0)
- || (prop.getIdentifier().compareToIgnoreCase("W") == 0))
+ if (prop.getIdentifier().compareToIgnoreCase("B") == 0
+ || prop.getIdentifier().compareToIgnoreCase("W") == 0)
movec++;
if (prop.getIdentifier().compareToIgnoreCase("C") == 0)
game.setCommentCount(game.getCommentCount() + 1);
@@ -92,7 +93,7 @@
if (prop.getIdentifier().compareToIgnoreCase("FF") == 0) {
String s = prop.firstStripped();
int value = Integer.parseInt(s);
- if ((value != 4) && (value != 3))
+ if (value != 4 && value != 3)
throw new Error("wrong version of SGF, we only handle versions 3
and 4");
continue;
}
@@ -127,13 +128,13 @@
if (prop.getIdentifier().compareToIgnoreCase("BR") == 0) {
String s = prop.firstStripped();
// TODO
- //game.getBlackRank(s)
+ // game.getBlackRank(s)
continue;
}
if (prop.getIdentifier().compareToIgnoreCase("WR") == 0) {
String s = prop.firstStripped();
- //TODO
- //game.setWhiteRank(s);
+ // TODO
+ // game.setWhiteRank(s);
continue;
}
if (prop.getIdentifier().compareToIgnoreCase("DT") == 0) {
@@ -164,7 +165,9 @@
}
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Object#toString()
*/
@Override
Modified: trunk/jgogears/jgogears/SGFNode.java
==============================================================================
--- trunk/jgogears/jgogears/SGFNode.java (original)
+++ trunk/jgogears/jgogears/SGFNode.java Tue Mar 4 22:17:01 2008
@@ -2,7 +2,6 @@
import java.util.*;
-
/**
* The Class SGFNode.
*/
@@ -11,8 +10,8 @@
/**
* Column from move string.
*
- * @param move the move
- *
+ * @param move
+ * the move
* @return the column of the move
*/
public static short columnFromMoveString(String move) {
@@ -77,8 +76,8 @@
/**
* Extract the row (second value) from tokens in the range of:
[a1]:[t19] missing the i.
*
- * @param move the move
- *
+ * @param move
+ * the move
* @return the column
*/
public static short columnFromMoveStringWRONG(String move) {
@@ -163,8 +162,8 @@
/**
* Row from move string.
*
- * @param move the move
- *
+ * @param move
+ * the move
* @return the row of the move
*/
public static short rowFromMoveString(String move) {
@@ -263,8 +262,8 @@
/**
* Gets the move.
*
- * @param prop the prop
- *
+ * @param prop
+ * the prop
* @return the move
*/
public Move getMove(SGFProperty prop) {
@@ -287,7 +286,7 @@
move.setRow(rowFromMoveString(value.toLowerCase()));
move.setColumn(columnFromMoveString(value.toLowerCase()));
// check for [tt] pass
- if ((move.getRow() == 19) && (move.getColumn() == 19)) {
+ if (move.getRow() == 19 && move.getColumn() == 19) {
Move newmove = new Move();
newmove.setPass(true);
newmove.setColour(move.getColour());
@@ -299,7 +298,9 @@
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Object#toString()
*/
@Override
Modified: trunk/jgogears/jgogears/SGFNodeTest.java
==============================================================================
--- trunk/jgogears/jgogears/SGFNodeTest.java (original)
+++ trunk/jgogears/jgogears/SGFNodeTest.java Tue Mar 4 22:17:01 2008
@@ -2,6 +2,7 @@
import junit.framework.TestCase;
+// TODO: Auto-generated Javadoc
/**
* The Class SGFNodeTest.
*/
Modified: trunk/jgogears/jgogears/SGFParser.java
==============================================================================
--- trunk/jgogears/jgogears/SGFParser.java (original)
+++ trunk/jgogears/jgogears/SGFParser.java Tue Mar 4 22:17:01 2008
@@ -1,8 +1,8 @@
package jgogears;
import java.io.StringReader;
-import jgogears.SGF.ParseException;
+import jgogears.SGF.ParseException;
/**
* Front end to the SGF parser. Also holds the SGF examples from the
SGF standard
@@ -26,20 +26,21 @@
/** Example from the SGF standard. Note that examples do not conserve
white space */
public static String EXAMPLETWO
= "(;FF[4]GM[1]SZ[19];B[aa];W[bb](;B[cc];W[dd];B[ad];W[bd]) (;B[hh];W[hg]))";
-
+
/** Example from the SGF standard. Note that examples do not conserve
white space */
public static String EXAMPLETHREE
= "(;FF[4]GM[1]SZ[19];B[aa];W[bb](;B[cc]N[Var A];W[dd];B[ad];W[bd])
(;B[hh]N[Var B];W[hg]) (;B[gg]N[Var C];W[gh];B[hh];W[hg];B[kk]))";
-
+
/** Example from the SGF standard. Note that examples do not conserve
white space */
public static String EXAMPLEFOUR
= "(;FF[4]GM[1]SZ[19];B[aa];W[bb](;B[cc];W[dd](;B[ad];W[bd])
(;B[ee];W[ff])) (;B[hh];W[hg]))";
-
+
/** Example from the SGF standard. Note that examples do not conserve
white space */
public static String EXAMPLEFIVE
= "(;FF[4]GM[1]SZ[19];B[aa];W[bb](;B[cc]N[Var
A];W[dd];B[ad];W[bd])(;B[hh]N[Var B];W[hg]) (;B[gg]N[Var C];W[gh];B[hh]
(;W[hg]N[Var A];B[kk]) (;W[kl]N[Var B])))";
/**
* The main method.
*
- * @param args the args
+ * @param args
+ * the args
*/
public static void main(String[] args) {
String example = SGFParser.EXAMPLEFIVE;
Modified: trunk/jgogears/jgogears/SGFParserTest.java
==============================================================================
--- trunk/jgogears/jgogears/SGFParserTest.java (original)
+++ trunk/jgogears/jgogears/SGFParserTest.java Tue Mar 4 22:17:01 2008
@@ -5,7 +5,7 @@
import jgogears.SGF.ParseException;
import junit.framework.TestCase;
-
+// TODO: Auto-generated Javadoc
/**
* The Class SGFParserTest.
*/
@@ -20,7 +20,8 @@
/**
* Test a.
*
- * @throws ParseException the parse exception
+ * @throws ParseException
+ * the parse exception
*/
public void testA() throws ParseException {
String example = SGFParser.EXAMPLEA;
@@ -32,7 +33,8 @@
/**
* Test bad repeat.
*
- * @throws ParseException the parse exception
+ * @throws ParseException
+ * the parse exception
*/
public void testBADRepeat() throws ParseException {
String examples[] = BADEXAMPLES;
@@ -76,7 +78,8 @@
/**
* Test five.
*
- * @throws ParseException the parse exception
+ * @throws ParseException
+ * the parse exception
*/
public void testFive() throws ParseException {
String example = SGFParser.EXAMPLEFIVE;
@@ -95,7 +98,8 @@
/**
* Test four.
*
- * @throws ParseException the parse exception
+ * @throws ParseException
+ * the parse exception
*/
public void testFour() throws ParseException {
String example = SGFParser.EXAMPLEFOUR;
@@ -114,7 +118,8 @@
/**
* Test one.
*
- * @throws ParseException the parse exception
+ * @throws ParseException
+ * the parse exception
*/
public void testOne() throws ParseException {
String example = SGFParser.EXAMPLEONE;
@@ -133,7 +138,8 @@
/**
* Test repeat.
*
- * @throws ParseException the parse exception
+ * @throws ParseException
+ * the parse exception
*/
public void testRepeat() throws ParseException {
String examples[] = { SGFParser.EXAMPLEA, SGFParser.EXAMPLEONE,
SGFParser.EXAMPLETWO, SGFParser.EXAMPLETHREE,
@@ -169,7 +175,8 @@
/**
* Test three.
*
- * @throws ParseException the parse exception
+ * @throws ParseException
+ * the parse exception
*/
public void testThree() throws ParseException {
String example = SGFParser.EXAMPLETHREE;
@@ -188,7 +195,8 @@
/**
* Test two.
*
- * @throws ParseException the parse exception
+ * @throws ParseException
+ * the parse exception
*/
public void testTwo() throws ParseException {
String example = SGFParser.EXAMPLETWO;
Modified: trunk/jgogears/jgogears/SGFProperty.java
==============================================================================
--- trunk/jgogears/jgogears/SGFProperty.java (original)
+++ trunk/jgogears/jgogears/SGFProperty.java Tue Mar 4 22:17:01 2008
@@ -2,17 +2,16 @@
import java.util.*;
-
/**
* An SGFProperty is a string identifier and a sequence of string
values. Common the sequence contains exactly one item.
*/
public class SGFProperty {
-
+
/**
* String all square brackets from a string. DOES NOT LEAVE escaped
squre bracekets!
*
- * @param s the s
- *
+ * @param s
+ * the s
* @return the new string
*/
protected static String stripSquareBrackets(String s) {
@@ -30,7 +29,7 @@
/**
* get the first value
*
- * @return the first value
+ * @return the first value
*/
public String first() {
return this.getValues().firstElement();
@@ -39,7 +38,7 @@
/**
* get the first value (stripped)
*
- * @return the first value (stripped)
+ * @return the first value (stripped)
*/
public String firstStripped() {
return stripSquareBrackets(this.first());
@@ -66,7 +65,8 @@
/**
* Sets the identifier.
*
- * @param propIdent the identifier
+ * @param propIdent
+ * the identifier
*/
public void setIdentifier(String propIdent) {
if (this.identifier != null)
@@ -77,7 +77,8 @@
/**
* Sets the values.
*
- * @param propvalues the values to set
+ * @param propvalues
+ * the values to set
*/
public void setValues(Vector<String> propvalues) {
if (this.values != null)
@@ -94,7 +95,9 @@
return stripSquareBrackets(this.toString());
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Object#toString()
*/
@Override
Modified: trunk/jgogears/jgogears/SGFPropertyTest.java
==============================================================================
--- trunk/jgogears/jgogears/SGFPropertyTest.java (original)
+++ trunk/jgogears/jgogears/SGFPropertyTest.java Tue Mar 4 22:17:01 2008
@@ -1,20 +1,18 @@
package jgogears;
-
-
import junit.framework.TestCase;
-
+// TODO: Auto-generated Javadoc
/**
* The Class SGFPropertyTest.
*/
public class SGFPropertyTest extends TestCase {
-
/**
* Test strip.
*
- * @throws Exception the exception
+ * @throws Exception
+ * the exception
*/
public void testStrip() throws Exception {
String a1 = "[19]";
Modified: trunk/jgogears/jgogears/SGFSequence.java
==============================================================================
--- trunk/jgogears/jgogears/SGFSequence.java (original)
+++ trunk/jgogears/jgogears/SGFSequence.java Tue Mar 4 22:17:01 2008
@@ -2,13 +2,14 @@
import java.util.*;
-
/**
* The Class SGFSequence.
*/
public class SGFSequence extends Vector<SGFNode> {
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.util.Vector#toString()
*/
@Override
Modified: trunk/jgogears/jgogears/SkeletonEngine.java
==============================================================================
--- trunk/jgogears/jgogears/SkeletonEngine.java (original)
+++ trunk/jgogears/jgogears/SkeletonEngine.java Tue Mar 4 22:17:01 2008
@@ -1,10 +1,7 @@
package jgogears;
-
/**
- * A skeleton GTP player
- * TODO complete this implementation
- * TODO add tests
+ * A skeleton GTP player TODO complete this implementation TODO add tests
*
* @author syeates
*/
@@ -17,7 +14,9 @@
super();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterface#clearBoard(jgogears.GTPState)
*/
public void clearBoard(GTPState state) {
@@ -25,7 +24,9 @@
state.clearBoard();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterface#fixedHandicap(int, jgogears.GTPState)
*/
public Move[] fixedHandicap(int handicap, GTPState state) {
@@ -36,7 +37,9 @@
return stones;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterface#genMove(short, jgogears.GTPState)
*/
public Move genMove(short colour, GTPState state) {
@@ -45,7 +48,9 @@
return result;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterface#getKnownCommand(java.lang.String)
*/
public boolean getKnownCommand(String command) {
@@ -53,7 +58,9 @@
return false;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterface#getListCommands()
*/
public String[] getListCommands() {
@@ -61,14 +68,18 @@
return null;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterface#getProtocolVersion()
*/
public int getProtocolVersion() {
return 2;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterface#loadsgf(java.lang.String, int, jgogears.GTPState)
*/
public void loadsgf(String filename, int moveNumber, GTPState state) {
@@ -76,7 +87,9 @@
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterface#placeFreeHandicap(int, jgogears.GTPState)
*/
public Move[] placeFreeHandicap(int handicap, GTPState state) {
@@ -87,7 +100,9 @@
return stones;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterface#placeFreeHandicap(jgogears.Move[], jgogears.GTPState)
*/
public void placeFreeHandicap(Move[] stones, GTPState state) {
@@ -96,21 +111,27 @@
}
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterface#play(jgogears.Move, jgogears.GTPState)
*/
public void play(Move move, GTPState state) {
state.playMove(move);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterface#quit()
*/
public boolean quit() {
return true;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterface#setBoardSize(short, jgogears.GTPState)
*/
public void setBoardSize(short size, GTPState state) {
@@ -118,14 +139,18 @@
state.setBoardsize(size);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterface#setKomi(double, jgogears.GTPState)
*/
public void setKomi(double komi, GTPState state) {
state.setKomi(komi);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterface#setTimeLeft(int, double, double, jgogears.GTPState)
*/
public void setTimeLeft(int colour, double byoYomiTime, double
byoYomiStones, GTPState state) {
@@ -133,7 +158,9 @@
state.setByoYomiTime(byoYomiTime);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterface#setTimeSettings(double, double, double, jgogears.GTPState)
*/
public void setTimeSettings(double mainTime, double byoYomiTime,
double byoYomiStones, GTPState state) {
@@ -143,14 +170,18 @@
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterface#showBoard(jgogears.GTPState)
*/
public BoardI showBoard(GTPState state) {
return state.getBoard();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see jgogears.GTPInterface#undo(jgogears.GTPState)
*/
public boolean undo(GTPState state) {
@@ -161,7 +192,7 @@
newState.komi = state.komi;
newState.boardsize = state.boardsize;
newState.mainTime = state.mainTime;
- newState.board = new Board(newState.boardsize);
+ newState.board = BoardI.newBoard(newState.boardsize);
// TODO generate new board
Modified: trunk/jgogears/jgogears/TwoGTP.java
==============================================================================
--- trunk/jgogears/jgogears/TwoGTP.java (original)
+++ trunk/jgogears/jgogears/TwoGTP.java Tue Mar 4 22:17:01 2008
@@ -1,116 +1,138 @@
package jgogears;
-import java.io.IOException;
/**
- * An incomplete clone of the TwoGTP program included in the GnuGo
distribution. It runs a go game between a pair of GTP-capiable players
- *
- * TODO finish this implementation
+ * An incomplete clone of the TwoGTP program included in the GnuGo
distribution. It runs a go game between a pair of
+ * GTP-capiable players TODO finish this implementation
*
* @author syeates
*/
public class TwoGTP {
-
-/** The black player. */
+ public static final boolean DEBUG = false;
+
+ /** The black player. */
private GTPInterface black = null;
-/** The white player. */
+ /** The white player. */
private GTPInterface white = null;
-
- private GTPState state = new GTPState();
-
- public static final boolean DEBUG = true;
-
+
+ private final GTPState state = new GTPState();
+
+ private int passes = 0;
+
+ private boolean blackNext = true;
+
/**
- * Run the game. Assumes that the black and white players have
already been set up.
+ * get the black
*
- * @return true, if play out game
+ * @return the black
*/
+ public final GTPInterface getBlack() {
+ return this.black;
+ }
- public GTPState playOutGame() {
- int passes = 0;
- boolean blackNext = true;
- if (black == null)
+ /**
+ * get the currentBoard
+ *
+ * @return the currentBoard
+ */
+ public final BoardI getCurrentBoard() {
+ return this.state.getBoard();
+ }
+
+ /**
+ * get the white
+ *
+ * @return the white
+ */
+ public final GTPInterface getWhite() {
+ return this.white;
+ }
+
+ /**
+ * play a single move in the game
+ *
+ * @return the state after the move
+ */
+ public GTPState move() {
+ if (this.black == null)
throw new Error();
- if (white == null)
+ if (this.white == null)
throw new Error();
-
-
- while (passes < 4) {
- Move move = null;
- if (blackNext) {
- move = this.black.genMove(BoardI.VERTEX_BLACK, this.state);
- assert (move != null);
- if (move.getPass())
- passes++;
- else
- passes = 0;
- blackNext = false;
- } else {
- move = this.white.genMove(BoardI.VERTEX_WHITE, this.state);
- assert (move != null);
- if (move.getPass())
- passes++;
- else
- passes = 0;
- blackNext = true;
- }
- if (DEBUG)
- System.err.println("TwoGTP: played " + move);
+ 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 (DEBUG)
+ System.err.println("TwoGTP: playing " + move);
this.state.playMove(move);
if (DEBUG)
System.err.println("TwoGTP: played " + move);
if (DEBUG)
- System.err.println(state.getBoard());
- }
- if (DEBUG)
- System.err.println(this.black.getFinalScore(state));
- if (DEBUG)
- System.err.println(this.white.getFinalScore(state));
+ System.err.println(this.state.getBoard());
+
+ return this.state;
- return state;
}
/**
- * get the black
- * @return the black
+ * Run the game. Assumes that the black and white players have
already been set up.
+ *
+ * @return true, if play out game
*/
- public final GTPInterface getBlack() {
- return black;
+
+ public GTPState playOutGame() {
+
+ if (this.black == null)
+ throw new Error();
+ if (this.white == null)
+ throw new Error();
+
+ while (this.passes < 4)
+ this.move();
+
+ if (DEBUG)
+ System.err.println(this.black.getFinalScore(this.state));
+ if (DEBUG)
+ System.err.println(this.white.getFinalScore(this.state));
+
+ return this.state;
}
/**
* set the black
- * @param black the black to set
+ *
+ * @param black
+ * the black to set
*/
public final void setBlack(GTPInterface black) {
this.black = black;
}
/**
- * get the white
- * @return the white
- */
- public final GTPInterface getWhite() {
- return white;
- }
-
- /**
* set the white
- * @param white the white to set
+ *
+ * @param white
+ * the white to set
*/
public final void setWhite(GTPInterface white) {
this.white = white;
- }
-
- /**
- * get the currentBoard
- * @return the currentBoard
- */
- public final BoardI getCurrentBoard() {
- return this.state.getBoard();
}
}
Modified: trunk/jgogears/jgogears/TwoGTPRaw.java
==============================================================================
--- trunk/jgogears/jgogears/TwoGTPRaw.java (original)
+++ trunk/jgogears/jgogears/TwoGTPRaw.java Tue Mar 4 22:17:01 2008
@@ -3,21 +3,21 @@
import java.io.IOException;
/**
- * An incomplete clone of the TwoGTP program included in the GnuGo
distribution. It runs a go game between a pair of GTP-capiable players
- *
- * TODO finish this implementation
+ * An incomplete clone of the TwoGTP program included in the GnuGo
distribution. It runs a go game between a pair of
+ * GTP-capiable players TODO finish this implementation
*
* @author syeates
*/
public class TwoGTPRaw {
-
+
/**
* Play two GTP-compatible players against each other.
*
- * @param args (ignored)
- *
- * @throws IOException Signals that an I/O exception has occurred.
+ * @param args
+ * (ignored)
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
*/
public static void main(String[] args) throws IOException {
@@ -28,14 +28,41 @@
}
-/** The black player. */
+ /** The black player. */
private GTPInterfaceRaw black = null;
-/** The white player. */
+ /** The white player. */
private GTPInterfaceRaw white = null;
-
- private BoardI currentBoard = new Board();
-
+
+ private BoardI currentBoard = BoardI.newBoard();
+
+ /**
+ * get the black
+ *
+ * @return the black
+ */
+ public final GTPInterfaceRaw getBlack() {
+ return this.black;
+ }
+
+ /**
+ * get the currentBoard
+ *
+ * @return the currentBoard
+ */
+ public final BoardI getCurrentBoard() {
+ return this.currentBoard;
+ }
+
+ /**
+ * get the white
+ *
+ * @return the white
+ */
+ public final GTPInterfaceRaw getWhite() {
+ return this.white;
+ }
+
/**
* Run the game. Assumes that the black and white players have
already been set up.
*
@@ -45,13 +72,13 @@
public boolean playOutGame() {
int passes = 0;
boolean blackNext = true;
- //TODO check the black and white players have been set up
+ // TODO check the black and white players have been set up
while (passes < 4) {
Move move = null;
if (blackNext) {
move = this.black.genMove(BoardI.VERTEX_BLACK);
- assert (move != null);
+ assert move != null;
this.white.play(move);
if (move.getPass())
passes++;
@@ -60,7 +87,7 @@
blackNext = false;
} else {
move = this.white.genMove(BoardI.VERTEX_WHITE);
- assert (move != null);
+ assert move != null;
this.black.play(move);
if (move.getPass())
passes++;
@@ -68,7 +95,7 @@
passes = 0;
blackNext = true;
}
- currentBoard = currentBoard.newBoard(move);
+ this.currentBoard = this.currentBoard.newBoard(move);
}
System.err.println(this.black.getFinalScore());
System.err.println(this.white.getFinalScore());
@@ -79,43 +106,23 @@
}
/**
- * get the black
- * @return the black
- */
- public final GTPInterfaceRaw getBlack() {
- return black;
- }
-
- /**
* set the black
- * @param black the black to set
+ *
+ * @param black
+ * the black to set
*/
public final void setBlack(GTPInterfaceRaw black) {
this.black = black;
}
/**
- * get the white
- * @return the white
- */
- public final GTPInterfaceRaw getWhite() {
- return white;
- }
-
- /**
* set the white
- * @param white the white to set
+ *
+ * @param white
+ * the white to set
*/
public final void setWhite(GTPInterfaceRaw white) {
this.white = white;
- }
-
- /**
- * get the currentBoard
- * @return the currentBoard
- */
- public final BoardI getCurrentBoard() {
- return currentBoard;
}
}
Modified: trunk/jgogears/jgogears/TwoGTPTest.java
==============================================================================
--- trunk/jgogears/jgogears/TwoGTPTest.java (original)
+++ trunk/jgogears/jgogears/TwoGTPTest.java Tue Mar 4 22:17:01 2008
@@ -5,14 +5,21 @@
import junit.framework.TestCase;
+// TODO: Auto-generated Javadoc
/**
- * test TwoGTP with a pair of GnuGo Players
+ * test TwoGTP with a pair of GnuGo Players.
+ *
* @author syeates
- *
*/
public class TwoGTPTest extends TestCase {
- public void testRaw() throws Exception {
+ /**
+ * Test raw.
+ *
+ * @throws Exception
+ * the exception
+ */
+ public void testRaw() throws Exception {
TwoGTPRaw two = new TwoGTPRaw();
assertNotNull(two);
two.setBlack(new GnuGoEngine(9));
@@ -20,7 +27,7 @@
two.playOutGame();
GTPScore scoreb = two.getBlack().getFinalScore();
GTPScore scorew = two.getWhite().getFinalScore();
- assertTrue(scoreb + " " + scorew, scoreb.equals(scorew));
- }
+ assertTrue(scoreb + " " + scorew, scoreb.equals(scorew));
+ }
}
Modified: trunk/jgogears/jgogears/Vertex.java
==============================================================================
--- trunk/jgogears/jgogears/Vertex.java (original)
+++ trunk/jgogears/jgogears/Vertex.java Tue Mar 4 22:17:01 2008
@@ -3,21 +3,22 @@
import java.util.Vector;
/**
- * A class representing a vertex on the board. There is no
representation of colour or the occupancy of the vertex.
- *
- * TODO write some tests for this
+ * A class representing a vertex on the board. There is no
representation of colour or the occupancy of the vertex. TODO
+ * write some tests for this
*
* @author Stuart
*/
public final class Vertex extends Vector<Short> implements
Comparable<Vertex> {
-
+ /** are we spewing out lots of debugging info? */
static final boolean DEBUG = false;
-
+
/**
* Short cut constructor with ints rather than shorts.
*
- * @param row the row
- * @param column the column
+ * @param row
+ * the row
+ * @param column
+ * the column
*/
public Vertex(int row, int column) {
this.add((short) row);
@@ -27,8 +28,10 @@
/**
* Preferred constuctor.
*
- * @param row the row
- * @param column the column
+ * @param row
+ * the row
+ * @param column
+ * the column
*/
public Vertex(short row, short column) {
this.add(row);
@@ -38,7 +41,8 @@
/**
* Constuctor based on a string.
*
- * @param vertexString the vertex string
+ * @param vertexString
+ * the vertex string
*/
public Vertex(String vertexString) {
if (DEBUG)
@@ -127,7 +131,7 @@
if (vertexString.length() == 2) {
this.setColumn((vertexString.charAt(1) - '1'));
} else if (vertexString.length() == 3) {
- this.setColumn(((vertexString.charAt(1) - '0') * 10) +
(vertexString.charAt(2) - '1'));
+ this.setColumn((vertexString.charAt(1) - '0') * 10 +
vertexString.charAt(2) - '1');
} else
throw new IllegalArgumentException("trying to parse (4) \"" +
vertexString + "\", \"" + vertexString + "\"");
if (DEBUG)
@@ -137,20 +141,20 @@
/**
* Comparison operator to ensure that (in)equality operators work as expected.
*
- * @param v the v
- *
+ * @param v
+ * the v
* @return the int
*/
public int compareTo(Vertex v) {
- if (v.getRow() > this.getRow())
- return 1;
- if (v.getRow() < this.getRow())
- return -1;
- if (v.getColumn() > this.getColumn())
- return 1;
- if (v.getColumn() < this.getColumn())
- return -1;
+ if (v.getRow() > this.getRow())
+ return 1;
+ if (v.getRow() < this.getRow())
+ return -1;
+ if (v.getColumn() > this.getColumn())
+ return 1;
+ if (v.getColumn() < this.getColumn())
+ return -1;
return 0;
}
@@ -158,21 +162,21 @@
* equality operator to ensure that two different vertex objects
representing the same vertex are recognised as
* being equal.
*
- * @param o the o
- *
+ * @param o
+ * the o
* @return true, if equals
*/
@Override
public boolean equals(Object o) {
- if ((this == null) && (o == null))
+ if (this == null && o == null)
return true;
- if ((o == null) || (this == null))
+ if (o == null || this == null)
return false;
if (o.getClass() != this.getClass())
return super.equals(o);
try {
Vertex v = (Vertex) o;
- if ((v.getRow() == this.getRow()) && (v.getColumn() == this.getColumn()))
+ if (v.getRow() == this.getRow() && v.getColumn() == this.getColumn())
return true;
else
return false;
@@ -208,7 +212,8 @@
/**
* set the column of this vertex.
*
- * @param column the column
+ * @param column
+ * the column
*/
private void setColumn(int column) {
short row = this.getRow();
@@ -220,7 +225,8 @@
/**
* Set the row of this vertex.
*
- * @param row the row
+ * @param row
+ * the row
*/
private void setRow(int row) {
short column = this.getColumn();
Modified: trunk/jgogears/jgogears/Zobrist.java
==============================================================================
--- trunk/jgogears/jgogears/Zobrist.java (original)
+++ trunk/jgogears/jgogears/Zobrist.java Tue Mar 4 22:17:01 2008
@@ -2,30 +2,26 @@
import java.util.*;
-
/**
- * Class representing a Zobrist hash, a binary hash of the current
board state.
- *
- * TODO add proper references
+ * Class representing a Zobrist hash, a binary hash of the current
board state. TODO add proper references
*
* @author Stuart
*/
public class Zobrist extends BitSet {
-
+
/** The Constant MAX_BOARD_SIZE. */
public static final short MAX_BOARD_SIZE = 25;
-
+
/** The Constant MAX_COLOUR. */
public static final short MAX_COLOUR = 4;
-
+
/** The Constant ZOBRIST_SIZE. */
public static final short ZOBRIST_SIZE = 96;
// initialisers ...
/** The static grid of all random values */
static BitSet[][][] grid = null;
-
/**
* Initialises the static grid of random values
@@ -56,18 +52,22 @@
/**
* Constructor building a Zobrist from an existing Zobrist and a move.
*
- * @param old the old
- * @param row the row
- * @param column the column
- * @param colour the colour
+ * @param old
+ * the old
+ * @param row
+ * the row
+ * @param column
+ * the column
+ * @param colour
+ * the colour
*/
public Zobrist(Zobrist old, int row, int column, int colour) {
init();
- if ((row >= MAX_BOARD_SIZE) || (row < 0))
+ if (row >= MAX_BOARD_SIZE || row < 0)
throw new Error("" + row);
- if ((column >= MAX_BOARD_SIZE) || (column < 0))
+ if (column >= MAX_BOARD_SIZE || column < 0)
throw new Error("" + column);
- if ((colour >= BoardI.VERTEX_MAX) || (colour < BoardI.VERTEX_MIN))
+ if (colour >= BoardI.VERTEX_MAX || colour < BoardI.VERTEX_MIN)
throw new Error("" + colour);
this.clear();
this.xor(old);
@@ -77,8 +77,8 @@
/**
* compare this zobrist to another object, potentially another zobrist
*
- * @param o the other Object
- *
+ * @param o
+ * the other Object
* @return 0 if equal, otherwise 1/-1
*/
public int compareTo(Object o) {
Modified: trunk/jgogears/jgogears/ZobristTest.java
==============================================================================
--- trunk/jgogears/jgogears/ZobristTest.java (original)
+++ trunk/jgogears/jgogears/ZobristTest.java Tue Mar 4 22:17:01 2008
@@ -2,6 +2,7 @@
import junit.framework.TestCase;
+// TODO: Auto-generated Javadoc
/**
* tests for Zobrist.
*
@@ -9,9 +10,9 @@
*/
public class ZobristTest extends TestCase {
-
+
/**
- * Check that all of the hashes are different
+ * Check that all of the hashes are different.
*/
public void testEachNotEqual() {
// this is needed to initialise the random numbers
@@ -24,13 +25,13 @@
for (int l = 0; l < Zobrist.MAX_BOARD_SIZE; l++)
for (int m = 0; m < Zobrist.MAX_BOARD_SIZE; m++)
for (int n = 0; n < Zobrist.MAX_COLOUR; n++)
- if ((i != l) || (j != m) || (k != n))
+ if (i != l || j != m || k != n)
assertFalse("" + i + " " + j + " " + k + " " + l + " " + m
+ " " + n,
Zobrist.grid[i][j][k] == Zobrist.grid[l][m][n]);
}
/**
- * Check that placing a move and then removing it gives the same hash
+ * Check that placing a move and then removing
==============================================================================
Diff truncated at 200k characters