-
Notifications
You must be signed in to change notification settings - Fork 1
/
test5.html
80 lines (73 loc) · 2.43 KB
/
test5.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="docs.css">
<script src="ksgf.js"></script>
<script>
function test5() {
var inputText = document.getElementById("input").innerHTML;
KSGF.setAppName("My Test Prog");
var game = new KSGF.Game();
var success = game.decode(inputText);
if (!success) {
alert("read failed, error: " + game.errorCode + " : " + game.getErrorMessage());
return;
}
var boardsize = game.rows;
var cellContents = [];
for ( var i = 0; i<=boardsize; i++ ) {
cellContents[i] = [];
for ( var j = 0; j<=boardsize; j++ ) {
cellContents[i].push(KSGF.EMPTY);
}
}
var move = game.currentMove;
var turn = game.currentTurn;
while ( !move.isRoot() ) {
turn = (turn == KSGF.BLACK) ? KSGF.WHITE : KSGF.BLACK;
cellContents[move.row][move.col] = turn; //KSGF.BLACK or KSGF.WHITE
move = move.previousMove;
}
var text = "";
var indentX = 0;
var indentY = 0;
for ( var i = 1; i<=boardsize; i++ ) {
for ( var j = 1; j<=boardsize; j++ ) {
var cellColour = "#EECC44";
if (cellContents[i][j] == KSGF.BLACK) cellColour = "#000000";
else if (cellContents[i][j] == KSGF.WHITE) cellColour = "#FFFFFF";
text += '<svg width="40" height="40" style="position: absolute; left: ' + indentX + 'px; top: ' + indentY + 'px;">';
text += '<polygon points="18,0 36,10 36,30 18,40 0,30 0,10" fill="' + cellColour + '"></polygon></svg>';
indentX += 40;
}
indentY += 34;
indentX = indentY * 20/34;
}
document.getElementById("board").innerHTML = text;
var text1 = game.encode();
var preElement = document.getElementById("output");
preElement.innerHTML = text1;
}
</script>
<title>KSGF</title>
</head>
<body style="background-color: grey;" onload="test5()">
<h1>KSGF test 5</h1>
<p>Read an SGF game from the text in the top 'input' box. Show the played game (not the other explored moves) on a board.
Display a reformatted SGF representation of the game in the bottom 'output' box.
<p>Input:</p>
<pre id="input">
(;AP[A Hex Program]SZ[11]FF[4]GM[11];B[d3](;W[e3](;B[g2];W[h2];B[h3](;W[i3])
(;W[h4];B[h5];W[i5]))(;B[f4];W[g4];B[h4]IP[];W[h5]))(;W[d4];B[d5];W[c6])
(;W[f4];B[g4];W[h4])(;W[f8];B[g7];W[h7];B[h8]))
</pre>
<p>The Hex board:</p>
<div style = " position: relative; width: 400px; height: 400px;">
<div id="board"></div>
</div>
<p>The output is:</p>
<pre id="output">
</pre>
</body>
</html>