[jgogears commit] r67 - in trunk/jgogears: doc jgogears jgogears/engine

0 views
Skip to first unread message

codesite...@google.com

unread,
Mar 25, 2008, 7:10:59 PM3/25/08
to jgog...@googlegroups.com
Author: syeates
Date: Tue Mar 25 16:10:21 2008
New Revision: 67

Added:
trunk/jgogears/jgogears/RandomTest.java
Modified:
trunk/jgogears/doc/TODO
trunk/jgogears/jgogears/Random.java
trunk/jgogears/jgogears/engine/Engine.java
trunk/jgogears/jgogears/engine/Scorer.java
trunk/jgogears/jgogears/engine/Trainer.java

Log:
moves are now random

Modified: trunk/jgogears/doc/TODO
==============================================================================
--- trunk/jgogears/doc/TODO (original)
+++ trunk/jgogears/doc/TODO Tue Mar 25 16:10:21 2008
@@ -11,7 +11,6 @@
* change training to only train on winning moves rather than all moves
* decided whether to dual licence under the Apache 2 license
* find a decent training corpus
-* make moves a little more random. They're meant to be random at the
moment, but apparently aren't...

SGF Support
===========
@@ -49,4 +48,5 @@
* separate the Model/Node data structures from the algorithms
* better tests of the Board implementations
* jgogears.engine.Engine now up and running
+* make moves a little more random. They're meant to be random at the
moment, but apparently aren't...


Modified: trunk/jgogears/jgogears/Random.java
==============================================================================
--- trunk/jgogears/jgogears/Random.java (original)
+++ trunk/jgogears/jgogears/Random.java Tue Mar 25 16:10:21 2008
@@ -11,23 +11,34 @@
*/
public class Random {
/** The random number generator */
- private static final java.util.Random random = new java.util.Random();
+ private static final java.util.Random random = new
java.util.Random(new java.util.Date().getTime());
/** A small value used as a small increment to probabilities */
public static final double DELTA = (double) 0.01;

/**
- * Gets the random.
*
- * @return the random
+ * get the next double
+ * @return the next double
*/
static public final double nextDouble() {
double r = random.nextDouble();
return r;
}
+ /**
+ *
+ * get the next boolean
+ * @return the next boolean
+ */
static public final boolean nextBoolean() {
boolean r = random.nextBoolean();
return r;
}
+ /**
+ *
+ * get the next integer
+ * @param max the maximum integer
+ * @return the next integer
+ */
static public final int nextInt(int max) {
int r = random.nextInt(max);
return r;
@@ -42,12 +53,31 @@
double r = random.nextDouble();
return r * DELTA;
}
-
+ /**
+ * a randomised max function
+ * @param first the first double
+ * @param second the second double
+ * @return the largest or a random value if equal
+ */
static public final double getRandomBest(double first,double second){
- if (first + getRandomDelta() >= second + getRandomDelta())
+ if (first > second)
return first;
- else
+ if (second > first)
return second;
+ return first;
+ }
+ /**
+ * a randomised max function
+ * @param first the first double
+ * @param second the second double
+ * @return the largest or a random value if equal
+ */
+ static public final boolean isLarger(double first,double second){
+ if (first > second)
+ return true;
+ if (second > first)
+ return false;
+ return nextBoolean();
}

Added: trunk/jgogears/jgogears/RandomTest.java
==============================================================================
--- (empty file)
+++ trunk/jgogears/jgogears/RandomTest.java Tue Mar 25 16:10:21 2008
@@ -0,0 +1,34 @@
+/**
+ *
+ */
+package jgogears;
+
+import junit.framework.TestCase;
+
+/**
+ * TODO
+ * @author syeates
+ *
+ */
+public class RandomTest extends TestCase {
+ public void testisLarger(){
+ assertTrue(Random.isLarger(9.0,1.0));
+ assertTrue(Random.isLarger(1.1,1.0));
+ assertTrue(Random.isLarger(1.2,1.0));
+ assertTrue(Random.isLarger(0.2,0.0));
+ assertTrue(Random.isLarger(0.2,0.1));
+
+ assertFalse(Random.isLarger(1.0,9.0));
+ assertFalse(Random.isLarger(1.0,1.1));
+ assertFalse(Random.isLarger(1.0,1.2));
+ assertFalse(Random.isLarger(0.0,0.2));
+ assertFalse(Random.isLarger(0.1,0.2));
+
+ while(Random.isLarger(0.1,0.1))
+ ;
+ while(!Random.isLarger(0.1,0.1))
+ ;
+
+ }
+
+}

Modified: trunk/jgogears/jgogears/engine/Engine.java
==============================================================================
--- trunk/jgogears/jgogears/engine/Engine.java (original)
+++ trunk/jgogears/jgogears/engine/Engine.java Tue Mar 25 16:10:21 2008
@@ -48,7 +48,7 @@
for (int i = 0; i < 200; i++) {
GTPState state = new GTPState();
state = two.move();
- //System.out.println(state.getBoard());
+ System.out.println(state.getBoard());
}
}


Modified: trunk/jgogears/jgogears/engine/Scorer.java
==============================================================================
--- trunk/jgogears/jgogears/engine/Scorer.java (original)
+++ trunk/jgogears/jgogears/engine/Scorer.java Tue Mar 25 16:10:21 2008
@@ -30,15 +30,14 @@
if (DEBUG)
System.err.println("In getBestScore");
double[][] result = this.getScores(model, board, white);
- double best = Double.MAX_VALUE;
+ double best = 1.1;
int I = -1, J = -1;
int i, j;
for (i = 0; i < board.getSize(); i++)
for (j = 0; j < board.getSize(); j++) {
- if (result[i][j] < best) {
+ if (!Random.isLarger(result[i][j],best)) {
if (RuleSet.DEFAULT.moveIsLegal(null, board, new Move(i, j,
white ? BoardI.VERTEX_WHITE
- : BoardI.VERTEX_BLACK))
- && best > result[i][j]) {
+ : BoardI.VERTEX_BLACK))) {
best = result[i][j];
I = i;
J = j;
@@ -49,6 +48,8 @@
}
if (DEBUG)
System.err.println("exiting getBestScore");
+ if (I == -1)
+ throw new Error("Internal error in Scorer");
return new Vertex(I, J);
}


Modified: trunk/jgogears/jgogears/engine/Trainer.java
==============================================================================
--- trunk/jgogears/jgogears/engine/Trainer.java (original)
+++ trunk/jgogears/jgogears/engine/Trainer.java Tue Mar 25 16:10:21 2008
@@ -46,7 +46,7 @@
* @return the minimum size, including both played and not-played visits.
*/
public final double getMinBranchSize() {
- return model.getGamesTrained() * 3. + 20.0;
+ return model.getGamesTrained() * 2.0 + 20.0;
}


Reply all
Reply to author
Forward
0 new messages