(function() {
var board = null;
-var moves = [];
+var history = [];
var move_override = 0;
var entity_map = {
var get_game = function() {
var game = new Chess();
for (var i = 0; i < move_override; ++i) {
- game.move(moves[i]);
+ game.move(history[i]);
}
return game;
}
var td = document.createElement("td");
tr.appendChild(td);
$(td).addClass("move");
+ if (line[j] !== undefined) {
+ if (history.length % 2 == 0) {
+ $(td).text(((history.length / 2) + 1) + ". ");
+ } else {
+ $(td).text(((history.length / 2) + 0.5) + ". …");
+ }
+ }
+
var move_a = document.createElement("a");
move_a.href = "javascript:make_move('" + line[j] + "')";
td.appendChild(move_a);
}
var make_move = function(move) {
- moves.length = move_override;
- moves.push(move);
- move_override = moves.length;
+ history.length = move_override;
+ history.push(move);
+ move_override = history.length;
update();
}
window['make_move'] = make_move;
window['prev_move'] = prev_move;
var next_move = function() {
- if (move_override < moves.length) {
+ if (move_override < history.length) {
++move_override;
update();
}
// illegal move
if (move === null) return 'snapback';
- moves = game.history({ verbose: true });
- move_override = moves.length;
+ history = game.history({ verbose: true });
+ move_override = history.length;
};
// update the board position after the piece snap