SGF file parser work in progress.

This commit is contained in:
2012-09-22 17:40:42 -04:00
parent ca6863b43e
commit ded284deb4
20 changed files with 4083 additions and 5 deletions

View File

@@ -6,5 +6,6 @@
<classpathentry kind="lib" path="lib/junit-4.10.jar"/> <classpathentry kind="lib" path="lib/junit-4.10.jar"/>
<classpathentry kind="lib" path="lib/log4j-1.2.16.jar"/> <classpathentry kind="lib" path="lib/log4j-1.2.16.jar"/>
<classpathentry kind="lib" path="lib/kgsGtp.jar"/> <classpathentry kind="lib" path="lib/kgsGtp.jar"/>
<classpathentry kind="lib" path="lib/antlrworks-1.4.3.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

BIN
lib/antlrworks-1.4.3.jar Normal file

Binary file not shown.

View File

@@ -111,7 +111,7 @@ public class GoGame implements Runnable {
} else if ("alphabeta".equals(policyName)) { } else if ("alphabeta".equals(policyName)) {
return new AlphaBeta(); return new AlphaBeta();
} else if ("montecarlo".equals(policyName)) { } else if ("montecarlo".equals(policyName)) {
return new MonteCarloUCT(new RandomMovePolicy(), 10000L); return new MonteCarloUCT(new RandomMovePolicy(), 3000L);
} else { } else {
LOGGER.info("Unable to create Policy for unsupported name: " + policyName); LOGGER.info("Unable to create Policy for unsupported name: " + policyName);
System.exit(INVALID_MOVE_GENERATOR); System.exit(INVALID_MOVE_GENERATOR);

View File

@@ -65,9 +65,9 @@ public abstract class MonteCarlo implements Policy {
} }
elapsedTime = System.currentTimeMillis() - startTime; elapsedTime = System.currentTimeMillis() - startTime;
//} while (elapsedTime < searchTimeLimit); } while (elapsedTime < searchTimeLimit);
//TODO: for debugging, temporarily specify the number of state evaluations rather than time limit //TODO: for debugging, temporarily specify the number of state evaluations rather than time limit
} while (numStateEvaluations < searchTimeLimit); //} while (numStateEvaluations < searchTimeLimit);
return getBestAction(rootNode); return getBestAction(rootNode);
} }

View File

@@ -26,8 +26,9 @@ public class MonteCarloUCT extends MonteCarlo {
double bestScore = Double.NEGATIVE_INFINITY; double bestScore = Double.NEGATIVE_INFINITY;
GameTreeNode<MonteCarloProperties> bestNode = node; GameTreeNode<MonteCarloProperties> bestNode = node;
//TODO: WHAT TO DO if the optimum leaf node is actually a terminal node? //What if the optimum leaf node is actually a terminal node?
//from Kocsis and Szepesvari, the value of an actual terminal node is 0, unless estimated by rollout //Grom Kocsis and Szepesvari, the value of an actual terminal node is 0, so it will never be grown.
double nodeVisits = node.getProperties().getVisits(); double nodeVisits = node.getProperties().getVisits();
for (Action action : node.getActions()) { for (Action action : node.getActions()) {

View File

@@ -0,0 +1,15 @@
(;FF[4]GM[1]SZ[19]CA[UTF-8]SO[gokifu.com]BC[kr]WC[cn]EV[]PB[Lee Sedol]BR[9p]PW[Gu Li]WR[9p]KM[7.5]
DT[2012-09-16]RE[W+R];B[qd];W[dc];B[dq];W[do];B[pp];W[cq];B[de];W[cg];B[cc];W[gc];B[gd];W[hd];B[fc]
;W[fd];B[ge];W[fb];B[hc];W[ec];B[gb];W[fc];B[id];W[cd];B[he];W[oc];B[pe];W[qk];B[qi];W[qn];B[qo]
;W[pn];B[np];W[oj];B[oi];W[ni];B[nj];W[pi];B[oh];W[pj];B[ph];W[qh];B[qg];W[rh];B[ri];W[rg];B[rf]
;W[oo];B[op];W[mj];B[mc];W[nk];B[cr];W[cp];B[gq];W[md];B[nc];W[qf];B[sh];W[pg];B[sg];W[od];B[nd]
;W[oe];B[ne];W[nf];B[qg];W[og];B[nh];W[mh];B[mg];W[ng];B[qh];W[mf];B[lg];W[lf];B[ld];W[qc];B[rc]
;W[pb];B[rb];W[kg];B[lh];W[mi];B[dl];W[br];B[ce];W[bd];B[dg];W[dh];B[be];W[eg];B[fe];W[dd];B[df]
;W[ci];B[gl];W[fh];B[ad];W[bc];B[dr];W[dm];B[em];W[cm];B[gg];W[gh];B[jq];W[fo];B[il];W[hg];B[ho]
;W[lo];B[lq];W[kp];B[kq];W[ee];B[ef];W[ff];B[ed];W[gp];B[hq];W[ee];B[pf];W[of];B[ed];W[gn];B[ei]
;W[eh];B[ii];W[kd];B[kc];W[ke];B[nb];W[fl];B[fk];W[ek];B[fj];W[dj];B[gf];W[gm];B[kh];W[jh];B[jg]
;W[ig];B[jf];W[jd];B[je];W[kf];B[ki];W[jc];B[kb];W[jb];B[ib];W[ja];B[ob];W[ic];B[ih];W[ha];B[hb]
;W[ga];B[ma];W[hh];B[hk];W[kl];B[kk];W[jk];B[jj];W[lk];B[bg];W[bh];B[cf];W[ch];B[ag];W[ac];B[el]
;W[fm];B[ae];W[rn];B[ro];W[fq];B[fr];W[so];B[sp];W[sn];B[rp];W[gj];B[hj];W[ej];B[fi];W[gi];B[gk]
;W[bj];B[jl];W[kj];B[ik];W[fg];B[ee];W[eq];B[er];W[km];B[bs];W[ar];B[rk];W[rl];B[qj];W[no];B[mp]
;W[ql];B[qb];W[ia];B[hd];W[pc];B[pa];W[jo];B[hm];W[dp])

View File

@@ -0,0 +1,13 @@
package net.woodyfolsom.msproj.sgf;
public class CoordValue extends StrValue {
public final char column;
public final char row;
public CoordValue(String coord) {
super(coord);
column = coord.charAt(0);
row = coord.charAt(1);
}
}

View File

@@ -0,0 +1,35 @@
package net.woodyfolsom.msproj.sgf;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class GameTree {
private List<Node> nodeSequence = new ArrayList<Node>();
private List<GameTree> subTrees = new ArrayList<GameTree>();
public int getNodeCount() {
return nodeSequence.size();
}
public List<Node> getNodeSequence() {
return Collections.unmodifiableList(nodeSequence);
}
public void setNodeSequence(List<Node> nodeSequence) {
this.nodeSequence.clear();
for(Node node : nodeSequence) {
this.nodeSequence.add(node);
}
}
public void addSubTree(GameTree subTree) {
subTrees.add(subTree);
}
public int getSubTreeCount() {
return subTrees.size();
}
}

View File

@@ -0,0 +1,16 @@
package net.woodyfolsom.msproj.sgf;
import java.util.ArrayList;
import java.util.List;
public class Node {
private List<SGFProperty> properties = new ArrayList<SGFProperty>();
public void addProperty(SGFProperty property) {
properties.add(property);
}
public int getPropertyCount() {
return properties.size();
}
}

View File

@@ -0,0 +1,25 @@
package net.woodyfolsom.msproj.sgf;
import java.util.ArrayList;
import java.util.List;
public class NodeCollection {
private List<GameTree> gameTrees = new ArrayList<GameTree>();
public void add(GameTree gameTree) {
gameTrees.add(gameTree);
}
public GameTree getGameTree(int index) {
return gameTrees.get(index);
}
public int getGameTreeCount() {
return gameTrees.size();
}
@Override
public String toString() {
return "foo";
}
}

View File

@@ -0,0 +1,7 @@
package net.woodyfolsom.msproj.sgf;
public class PlayerIdent extends StrIdent {
public PlayerIdent(String player) {
super(player);
}
}

View File

@@ -0,0 +1,7 @@
package net.woodyfolsom.msproj.sgf;
public class ResultValue extends StrValue {
public ResultValue(String result) {
super(result);
}
}

View File

@@ -0,0 +1,57 @@
T__19=19
T__20=20
T__21=21
T__22=22
T__23=23
T__24=24
T__25=25
T__26=26
T__27=27
T__28=28
T__29=29
T__30=30
T__31=31
T__32=32
T__33=33
T__34=34
T__35=35
T__36=36
T__37=37
T__38=38
T__39=39
COLON=4
COMMA=5
DIGIT=6
LBRACKET=7
LCLETTER=8
LPAREN=9
MINUS=10
PERIOD=11
PLUS=12
RBRACKET=13
RPAREN=14
SEMICOLON=15
SLASH=16
SPACE=17
UCLETTER=18
'AB'=19
'AP'=20
'BC'=21
'BR'=22
'CA'=23
'CP'=24
'EV'=25
'FF'=26
'GM'=27
'KM'=28
'PB'=29
'PC'=30
'PW'=31
'RE'=32
'RU'=33
'SO'=34
'SZ'=35
'TM'=36
'US'=37
'WC'=38
'WR'=39

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,22 @@
package net.woodyfolsom.msproj.sgf;
public class SGFProperty {
private StrIdent ident;
private StrValue value;
public StrIdent getIdent() {
return ident;
}
public StrValue getValue() {
return value;
}
public void setIdent(StrIdent ident) {
this.ident = ident;
}
public void setValue(StrValue value) {
this.value = value;
}
}

View File

@@ -0,0 +1,5 @@
package net.woodyfolsom.msproj.sgf;
public class SGFReader {
}

View File

@@ -0,0 +1,5 @@
package net.woodyfolsom.msproj.sgf;
public class SGFWriter {
}

View File

@@ -0,0 +1,9 @@
package net.woodyfolsom.msproj.sgf;
public class StrIdent {
public final String value;
public StrIdent(String value) {
this.value = value;
}
}

View File

@@ -0,0 +1,9 @@
package net.woodyfolsom.msproj.sgf;
public class StrValue {
public final String value;
public StrValue(String value) {
this.value = value;
}
}