forked from tensorflow/minigo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposition.js
More file actions
87 lines (87 loc) · 3.31 KB
/
Copy pathposition.js
File metadata and controls
87 lines (87 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
define(["require", "exports", "./base", "./util"], function (require, exports, base_1, util_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Annotation;
(function (Annotation) {
let Shape;
(function (Shape) {
Shape[Shape["Dot"] = 0] = "Dot";
})(Shape = Annotation.Shape || (Annotation.Shape = {}));
})(Annotation || (Annotation = {}));
exports.Annotation = Annotation;
class Position {
constructor(id, parent, stones, lastMove, toPlay, gameOver, isMainLine) {
this.id = id;
this.parent = parent;
this.stones = stones;
this.lastMove = lastMove;
this.toPlay = toPlay;
this.gameOver = gameOver;
this.isMainLine = isMainLine;
this.n = 0;
this.q = null;
this.search = [];
this.variations = new Map();
this.annotations = [];
this.childN = null;
this.childQ = null;
this.children = [];
this.captures = [0, 0];
this.comment = "";
this.moveNum = parent != null ? parent.moveNum + 1 : 0;
if (lastMove != null && lastMove != 'pass' && lastMove != 'resign') {
this.annotations.push({
p: lastMove,
shape: Annotation.Shape.Dot,
colors: ['#ef6c02'],
});
}
}
addChild(id, move, stones, gameOver) {
for (let child of this.children) {
if (child.lastMove == null) {
throw new Error('Child node shouldn\'t have a null lastMove');
}
if (base_1.movesEqual(child.lastMove, move)) {
if (!base_1.stonesEqual(stones, child.stones)) {
throw new Error(`Position has child ${base_1.toKgs(move)} with different stones`);
}
return child;
}
}
let isMainLine = this.isMainLine && this.children.length == 0;
let child = new Position(id, this, stones, move, base_1.otherColor(this.toPlay), gameOver, isMainLine);
this.children.push(child);
return child;
}
update(update) {
const props = ['n', 'q', 'childN', 'childQ'];
util_1.partialUpdate(update, this, props);
if (update.variations != null) {
for (let key in update.variations) {
this.variations.set(key, update.variations[key]);
}
if ("pv" in update.variations) {
let pv = update.variations["pv"];
if (pv.length > 0) {
this.variations.set(base_1.toKgs(pv[0]), pv);
}
}
}
}
getFullLine() {
let result = [];
let node;
for (node = this.parent; node != null; node = node.parent) {
result.push(node);
}
result.reverse();
for (node = this; node != null; node = node.children[0]) {
result.push(node);
}
return result;
}
}
exports.Position = Position;
});
//# sourceMappingURL=position.js.map