-
Notifications
You must be signed in to change notification settings - Fork 64
/
index.php
290 lines (260 loc) · 10.4 KB
/
index.php
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php include("header.phtml"); ?>
<script type="text/javascript" src="js/rsh.compressed.js"></script>
<div id="options"></div>
<div id="options-joseki" style="display: none">
<strong>Joseki Tutor:</strong>
<a href="/#kjd">Kogo's Joseki Dictionary</a> |
<a href="/#kombilo">Kombilo / Pro Game Database</a>
</div>
<div id="options-gnugo" style="display: none">
<strong>GNU Go</strong>
Board Size:
<a href="/#gnugo">19x19</a> |
<a href="/#gnugo-9">9x9</a> |
<a href="/#gnugo-13">13x13</a>
Your Color: <select id="human-color">
<option value="W">White</option>
<option value="B">Black</option>
</select>
Handicap: <select id="handicap">
<option value="0">None</option>
<option value="1">1 stone</option>
<option value="2">2 stones</option>
<option value="3">3 stones</option>
<option value="4">4 stones</option>
<option value="5">5 stones</option>
<option value="6">6 stones</option>
<option value="7">7 stones</option>
<option value="8">8 stones</option>
<option value="9">9 stones</option>
</select>
</div>
<div id="options-blank" style="display: none">
<strong>Blank Board:</strong>
<a href="/#blank">19x19</a> |
<a href="/#blank-9">9x9</a> |
<a href="/#blank-13">13x13</a>
</div>
<div id="player-container"></div>
<script type="text/javascript">
var player;
(function() {
var byId = eidogo.util.byId,
hide = eidogo.util.hide,
show = eidogo.util.show,
addEvent = eidogo.util.addEvent;
// Provide handlers for frontend things (page title, permalinks) that
// aren't handled by Player directly
var hooks = {
initGame: function() {
document.title = "EidoGo - " + this.getGameDescription();
},
showGameInfo: function(info) {
if (this.gameName == "kjd") {
['KM', 'HA', 'CP', 'DT'].forEach(function(p) { delete info[p]; });
info.GC = "Available from " +
"<a href='http://waterfire.us/joseki.htm'>http://waterfire.us/joseki.htm</a><br><br>" +
"KJD Copyright 2006-2007 by Andre Ay. Copyright 1998-2005 " +
"by Gary Odom. Portions copyright 2000-2001 by Stefan " +
"Verstraeten. Used with permission.";
} else if (this.gameName == "kombilo") {
info.GN = "Kombilo / Pro Game Database";
info.GC = "Continuations derived from around 10,000 pro games.\n\n" +
"Since the continuations are computed automatically, there is a certain " +
"amount of spurious, non-fuseki moves included.";
}
},
setPermalink: function() {
if (!this.gameName || ['search', 'gnugo', 'url'].contains(this.gameName)) return;
var gn = this.gameName || "";
// Use move-based path for josekis to future-proof permalinks
var path = (gn == "kjd" || gn == "kombilo" ?
this.cursor.getPathMoves().join("") :
this.cursor.getPath().join(","));
var hash = gn + (path ? ":" + path : "");
addHistory(hash);
},
searchRegion: function(params) {
this.hooks.initGame.call(this); // update title
var hash = "search:" + params.q + ":" + params.w + "x" + params.h +
":" + this.compressPattern(params.p);
if (params.a && params.a != "corner") hash += ":" + params.a;
if (hash != location.hash.replace(/^#/, ""))
addHistory(hash);
},
saved: function(gn) {
loadGame({gameName: gn, loadPath: [0,0]}, function() {
var url = location.href.replace(/#[^#]+$/, "") + "#" + this.gameName;
this.setPermalink();
this.prependComment("Game saved to <a href='" + url + "'>" + url + "</a>");
}.bind(this));
}
};
// Load game data; create a Player instance if necessary
function loadGame(params, completeFn) {
params = params || {};
var cfg = {
progressiveLoad: false,
markCurrent: true,
markVariations: true,
markNext: false,
showGameInfo: true,
showPlayerInfo: true,
showOptions: true,
showTools: true,
showNavTree: true,
problemMode: false
};
for (var key in params) {
cfg[key] = params[key];
}
if (!player) {
player = new eidogo.Player({
container: "player-container",
sgfPath: "sgf/",
searchUrl: "backend/search.php",
saveUrl: "backend/save.php",
downloadUrl: "backend/download.php?id=",
scoreEstUrl: "",//"backend/gnugo.php",
hooks: hooks,
enableShortcuts: true
});
// Temporary notice for score est
addEvent(player.dom.scoreEst, "click", function(e) {
alert("Sorry, Score Estimate is temporarily unavailable.\n\nIt was using excessive server resources. If you have a server with lots of spare CPU cycles, let me know.");
eidogo.util.stopEvent(e);
return false;
});
}
player.loadSgf(cfg, completeFn && completeFn.bind(player));
}
var notLoaded = true;
// Perform the appriate loading action depending on what hash is given
function loadState(hash) {
notLoaded = false;
var hashParts = hash ? hash.replace(/^#/, "").split(/:/) : [];
var gameName = hashParts[0] || "";
var loadPath = hashParts[1] ? hashParts[1].split(",") : null;
var rest = hashParts.slice(1);
hide("options");
if (!gameName || gameName == "kjd" || gameName == "kombilo")
loadJoseki(gameName, loadPath);
else if (gameName == "url")
loadUrl(hash.replace(/^#?url:/, ""));
else if (gameName == "raw")
loadRaw(decodeURIComponent(hash.replace(/^#?raw:/g, "").replace(/\+/g, " ")));
else if (gameName == "search")
loadSearch(rest);
else if (gameName.indexOf("gnugo") === 0)
loadGnuGo(gameName);
else if (gameName.indexOf("blank") === 0)
loadBlank(gameName);
else
loadGame({gameName: gameName, loadPath: loadPath});
}
function loadJoseki(gameName, loadPath) {
byId("options").innerHTML = byId("options-joseki").innerHTML;
show("options");
if (loadPath) {
// Parse moves out of string like "aepqnctt"
var s = loadPath[0];
var coord;
loadPath = [];
while (coord = s.substring(0, 2)) {
loadPath.push(coord);
s = s.substring(2);
}
}
loadGame({
gameName: gameName || "kjd",
progressiveUrl: gameName == "kombilo" ? "backend/search.php" : "backend/kjd_progressive.php",
loadPath: loadPath,
progressiveLoad: true,
progressiveMode: gameName == "kombilo" ? "pattern" : "id",
markNext: true,
showPlayerInfo: false,
showOptions: false});
}
function loadSearch(args) {
if (args.length) {
loadGame({showOptions: false});
player.loadSearch.apply(player, args);
} else {
loadGame({
gameName: "search",
showOptions: false,
loadPath: [0,0]});
}
}
function loadUrl(url) {
loadGame({
gameName: "url",
sgfUrl: "backend/fetch.php?url=" + url});
}
function loadRaw(data) {
loadGame({
gameName: "raw",
sgf: data});
}
function loadGnuGo(gameName) {
loadGame({gameName: ""}, function() {
this.showComments("<p>Sorry, GNU Go is temporarily unavailable.</p><p>It was using excessive server resources. If you have a server with lots of spare CPU cycles, let me know.</p>");
});
return;
byId("options").innerHTML = byId("options-gnugo").innerHTML;
show("options");
var params = {
gameName: "",
opponentUrl: "backend/gnugo.php",
opponentColor: "B",
opponentLevel: 7,
handicap: 0
};
var parts = gameName.split("-");
if (parts[1])
params.boardSize = parts[1];
var inputColor = byId("human-color"),
inputHandi = byId("handicap");
var changeHandler = function() {
params.opponentColor = inputColor.value == "W" ? "B" : "W";
params.handicap = inputHandi.value;
loadGame(params);
}
addEvent(inputColor, "change", changeHandler);
addEvent(inputHandi, "change", changeHandler);
loadGame(params);
}
function loadBlank(gameName) {
byId("options").innerHTML = byId("options-blank").innerHTML;
show("options");
loadGame({gameName: gameName});
}
function addHistory(hash) {
// Safari 2 sucks
if (dhtmlHistory.isSafari)
location.hash = hash;
else
dhtmlHistory.add(hash);
}
// Appease RSH
window.dhtmlHistory.create({
toJSON: function(o) { return ''; },
fromJSON: function(s) { return {}; }});
// Ajaxify our links
addEvent(document, "click", function(evt) {
var target = eidogo.util.getTarget(evt)
if (target.nodeName.toUpperCase() != "A" || target.href.indexOf("#") == -1) return true;
var hash = target.href.replace(/^.*#/, "");
addHistory(hash);
player.closeSearch();
loadState(hash);
eidogo.util.stopEvent(evt);
});
dhtmlHistory.initialize();
dhtmlHistory.addListener(loadState);
// Make sure we load our state on first page load (RSH quirk)
if (notLoaded)
loadState(location.hash.replace(/^#/, ""));
})();
</script>
<?php include("footer.phtml"); ?>