-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest7.html
58 lines (49 loc) · 1.55 KB
/
test7.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="docs.css">
<script src="ksgf.js"></script>
<script>
function test7() {
var inputText = document.getElementById("input").innerHTML;
KSGF.setAppName("My Text Reading App");
var game = new KSGF.Game();
var boardsize = 13
game.rows = boardsize;
game.cols = boardsize;
var items = inputText.split(/[,.;:\s+]/); // list of separators ,.;: and whitespace
for (var i=0; i<items.length; i++) {
var val = items[i];
if ( (val.length == 2 || val.length == 3) ) {
var c = parseInt(val.charCodeAt(0) - "a".charCodeAt(0) + 1); // eg b
var r = parseInt(val.slice(1, val.length)); // eg 6, 12
if (Number.isInteger(r) && Number.isInteger(c) && r > 0 && r <= boardsize && c > 0 && c <= boardsize)
game.makeMove(r,c);
}
}
// show the SGF text
var text = game.encode();
var preElement = document.getElementById("output");
preElement.innerHTML = text;
}
</script>
<title>KSGF</title>
</head>
<body onload="test7()">
<h1>KSGF test 7</h1>
<p>Set up a game, and give it a board size of 13. Read text containing some moves like a1, b2 from the top 'input' box, and form a game.
Display a SGF representation of the game in the bottom 'output' box.
<p>Input:</p>
<pre id="input">
This paragraph is ignored, as there are no recognised moves.
1. a1 b2
2. d4; e5
The moves given above are decoded.
The move a99 is ignored as it is off the board.
</pre>
<p>The output is:</p>
<pre id="output">
</pre>
</body>
</html>