mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-04-13 23:52:45 +02:00
DroidFish: Fixed incorrect ECO classification.
This commit is contained in:
parent
9a27cda809
commit
c22210fb56
@ -44,7 +44,6 @@ public class EcoBuilder {
|
|||||||
int nameIdx; // Index in names array, or -1
|
int nameIdx; // Index in names array, or -1
|
||||||
ArrayList<Node> children = new ArrayList<Node>();
|
ArrayList<Node> children = new ArrayList<Node>();
|
||||||
Node parent;
|
Node parent;
|
||||||
int lineLength; // Length in plies of line this node came from
|
|
||||||
}
|
}
|
||||||
private ArrayList<Node> nodes;
|
private ArrayList<Node> nodes;
|
||||||
private ArrayList<String> names;
|
private ArrayList<String> names;
|
||||||
@ -59,7 +58,6 @@ public class EcoBuilder {
|
|||||||
rootNode.index = 0;
|
rootNode.index = 0;
|
||||||
rootNode.move = new Move(0, 0, 0);
|
rootNode.move = new Move(0, 0, 0);
|
||||||
rootNode.nameIdx = -1;
|
rootNode.nameIdx = -1;
|
||||||
rootNode.lineLength = 0;
|
|
||||||
nodes.add(rootNode);
|
nodes.add(rootNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,10 +78,22 @@ public class EcoBuilder {
|
|||||||
gotMoves |= !isHeader;
|
gotMoves |= !isHeader;
|
||||||
}
|
}
|
||||||
readGame(pgn.toString());
|
readGame(pgn.toString());
|
||||||
|
setNameIndices(0);
|
||||||
|
|
||||||
writeDataFile(ecoDatFile);
|
writeDataFile(ecoDatFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** For all tree nodes, if nameIndex not already set,
|
||||||
|
* set it from parent node nameIndex. */
|
||||||
|
private void setNameIndices(int nodeIdx) {
|
||||||
|
Node n = nodes.get(nodeIdx);
|
||||||
|
for (Node c : n.children) {
|
||||||
|
if (c.nameIdx == -1)
|
||||||
|
c.nameIdx = n.nameIdx;
|
||||||
|
setNameIndices(c.index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Read and process one game. */
|
/** Read and process one game. */
|
||||||
private void readGame(String pgn) throws Throwable {
|
private void readGame(String pgn) throws Throwable {
|
||||||
if (pgn.isEmpty())
|
if (pgn.isEmpty())
|
||||||
@ -111,22 +121,14 @@ public class EcoBuilder {
|
|||||||
names.add(name);
|
names.add(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
int lineLength = 0;
|
|
||||||
while (true) {
|
|
||||||
if (tree.variations().isEmpty())
|
|
||||||
break;
|
|
||||||
lineLength++;
|
|
||||||
tree.goForward(0);
|
|
||||||
}
|
|
||||||
while (tree.currentNode.getParent() != null)
|
|
||||||
tree.goBack();
|
|
||||||
|
|
||||||
// Add corresponding moves to data structures
|
// Add corresponding moves to data structures
|
||||||
Node parent = nodes.get(0);
|
Node parent = nodes.get(0);
|
||||||
while (true) {
|
while (true) {
|
||||||
ArrayList<Move> moves = tree.variations();
|
ArrayList<Move> moves = tree.variations();
|
||||||
if (moves.isEmpty())
|
if (moves.isEmpty()) {
|
||||||
|
parent.nameIdx = nameIdx;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
Move m = moves.get(0);
|
Move m = moves.get(0);
|
||||||
tree.goForward(0);
|
tree.goForward(0);
|
||||||
int oldIdx = -1;
|
int oldIdx = -1;
|
||||||
@ -140,18 +142,13 @@ public class EcoBuilder {
|
|||||||
Node node = new Node();
|
Node node = new Node();
|
||||||
node.index = nodes.size();
|
node.index = nodes.size();
|
||||||
node.move = m;
|
node.move = m;
|
||||||
node.nameIdx = nameIdx;
|
node.nameIdx = parent.nameIdx;
|
||||||
node.parent = parent;
|
node.parent = parent;
|
||||||
node.lineLength = lineLength;
|
|
||||||
nodes.add(node);
|
nodes.add(node);
|
||||||
parent.children.add(node);
|
parent.children.add(node);
|
||||||
parent = node;
|
parent = node;
|
||||||
} else {
|
} else {
|
||||||
parent = parent.children.get(oldIdx);
|
parent = parent.children.get(oldIdx);
|
||||||
if (parent.lineLength > lineLength) {
|
|
||||||
parent.lineLength = lineLength;
|
|
||||||
parent.nameIdx = nameIdx;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user