fetch_analysis();
}
+var get_history_url = function() {
+ var history = game.history({ verbose: true }).map(function(x) { return x.san; });
+ history.length = move_override;
+ return '/?' + history.join(',');
+}
+
var fetch_analysis = function() {
var fen = current_display_fen();
$.ajax({
[ "Move", TYPE_MOVE ],
[ "Games", TYPE_INTEGER ],
[ "%", TYPE_RATIO ],
+ [ "CGames", TYPE_INTEGER ],
+ [ "Hum", TYPE_RATIO ],
[ "Win%", TYPE_RATIO ],
[ "WWin", TYPE_INTEGER ],
[ "%WW", TYPE_RATIO ],
var white = parseInt(move['white']);
var draw = parseInt(move['draw']);
var black = parseInt(move['black']);
+ var computer = parseInt(move['computer']);
line.push(move['move']); // Move.
transpose_only.push(move['transpose_only']);
var num = white + draw + black;
line.push(num); // N.
line.push(num / total_num); // %.
+ line.push(computer); // CGames.
+
+ // Adjust so that the human index is 50% overall.
+ var exp = Math.log(0.5) / Math.log(data['computer_games'] / data['total_games']);
+ line.push(1.0 - Math.pow(computer / num, exp)); // Hum.
// Win%.
var white_win_ratio = (white + 0.5 * draw) / num;
}
window['set_includetransp'] = set_includetransp;
-var make_move = function(move) {
+var make_move = function(move, do_update) {
var history = game.history({ verbose: true });
if (move_override < history.length && history[move_override].san == move) {
// User effectively only moved forward in history.
fens.push(game.fen());
++move_override;
}
- update();
+
+ if (do_update !== false) {
+ update();
+ window.history.pushState(null, null, get_history_url());
+ }
}
window['make_move'] = make_move;
if (move_override > 0) {
--move_override;
update();
+ window.history.replaceState(null, null, get_history_url());
}
}
window['prev_move'] = prev_move;
if (move_override < game.history().length) {
++move_override;
update();
+ window.history.replaceState(null, null, get_history_url());
}
}
window['next_move'] = next_move;
-var set_move = function(n) {
+var set_move = function(n, do_update) {
move_override = n;
- update();
+ if (do_update !== false) {
+ update();
+ window.history.replaceState(null, null, get_history_url());
+ }
}
window['set_move'] = set_move;
make_move(pseudogame.history({ verbose: true }).pop().san);
}
+var onpopstate = function() {
+ var old_moves = game.history({ verbose: true }).map(function(x) { return x.san; });
+ var new_moves = document.location.search.replace(/^\?/, "").split(",");
+
+ if (new_moves.length == 1 && new_moves[0] == "") {
+ new_moves = [];
+ }
+
+ var num_shared_moves;
+ for (num_shared_moves = 0; num_shared_moves < Math.min(old_moves.length, new_moves.length); ++num_shared_moves) {
+ if (old_moves[i] != new_moves[i]) {
+ break;
+ }
+ }
+
+ set_move(num_shared_moves, false);
+ for (var i = num_shared_moves; i < new_moves.length; ++i) {
+ make_move(new_moves[i], false);
+ }
+ update();
+ window.history.replaceState(null, null, get_history_url());
+}
+
var init = function() {
// Create board.
board = new window.ChessBoard('board', {
onDrop: onDrop,
onSnapEnd: onSnapEnd
});
- update();
+
+ window.onpopstate = onpopstate;
+ onpopstate();
$(window).keyup(function(event) {
if (event.which == 39) {