- board: function() {
- var output = [],
- row = [];
-
- for (var i = SQUARES.a8; i <= SQUARES.h1; i++) {
- if (board[i] == null) {
- row.push(null)
- } else {
- row.push({type: board[i].type, color: board[i].color})
- }
- if ((i + 1) & 0x88) {
- output.push(row);
- row = []
- i += 8;
- }
- }
-
- return output;
- },
-
- pgn: function(options) {
- /* using the specification from http://www.chessclub.com/help/PGN-spec
- * example for html usage: .pgn({ max_width: 72, newline_char: "<br />" })
- */
- var newline = (typeof options === 'object' &&
- typeof options.newline_char === 'string') ?
- options.newline_char : '\n';
- var max_width = (typeof options === 'object' &&
- typeof options.max_width === 'number') ?
- options.max_width : 0;
- var result = [];
- var header_exists = false;
-
- /* add the PGN header headerrmation */
- for (var i in header) {
- /* TODO: order of enumerated properties in header object is not
- * guaranteed, see ECMA-262 spec (section 12.6.4)
- */
- result.push('[' + i + ' \"' + header[i] + '\"]' + newline);
- header_exists = true;
- }
-
- if (header_exists && history.length) {
- result.push(newline);
- }
-
- /* pop all of history onto reversed_history */
- var reversed_history = [];
- while (history.length > 0) {
- reversed_history.push(undo_move());
- }
-
- var moves = [];
- var move_string = '';
-
- /* build the list of moves. a move_string looks like: "3. e3 e6" */
- while (reversed_history.length > 0) {
- var move = reversed_history.pop();
-
- /* if the position started with black to move, start PGN with 1. ... */
- if (!history.length && move.color === 'b') {
- move_string = move_number + '. ...';
- } else if (move.color === 'w') {
- /* store the previous generated move_string if we have one */
- if (move_string.length) {
- moves.push(move_string);
- }
- move_string = move_number + '.';
- }
-
- move_string = move_string + ' ' + move_to_san(move, false);
- make_move(move);
- }
-
- /* are there any other leftover moves? */
- if (move_string.length) {
- moves.push(move_string);
- }
-
- /* is there a result? */
- if (typeof header.Result !== 'undefined') {
- moves.push(header.Result);
- }
-
- /* history should be back to what is was before we started generating PGN,
- * so join together moves
- */
- if (max_width === 0) {
- return result.join('') + moves.join(' ');
- }
-
- /* wrap the PGN output at max_width */
- var current_width = 0;
- for (var i = 0; i < moves.length; i++) {
- /* if the current move will push past max_width */
- if (current_width + moves[i].length > max_width && i !== 0) {
-
- /* don't end the line with whitespace */
- if (result[result.length - 1] === ' ') {
- result.pop();
- }
-
- result.push(newline);
- current_width = 0;
- } else if (i !== 0) {
- result.push(' ');
- current_width++;
- }
- result.push(moves[i]);
- current_width += moves[i].length;
- }
-
- return result.join('');
- },
-
- load_pgn: function(pgn, options) {
- // allow the user to specify the sloppy move parser to work around over
- // disambiguation bugs in Fritz and Chessbase
- var sloppy = (typeof options !== 'undefined' && 'sloppy' in options) ?
- options.sloppy : false;
-
- function mask(str) {
- return str.replace(/\\/g, '\\');
- }
-
- function has_keys(object) {
- for (var key in object) {
- return true;
- }
- return false;
- }
-
- function parse_pgn_header(header, options) {
- var newline_char = (typeof options === 'object' &&
- typeof options.newline_char === 'string') ?
- options.newline_char : '\r?\n';
- var header_obj = {};
- var headers = header.split(new RegExp(mask(newline_char)));
- var key = '';
- var value = '';
-
- for (var i = 0; i < headers.length; i++) {
- key = headers[i].replace(/^\[([A-Z][A-Za-z]*)\s.*\]$/, '$1');
- value = headers[i].replace(/^\[[A-Za-z]+\s"(.*)"\]$/, '$1');
- if (trim(key).length > 0) {
- header_obj[key] = value;
- }
- }
-
- return header_obj;
- }
-
- var newline_char = (typeof options === 'object' &&
- typeof options.newline_char === 'string') ?
- options.newline_char : '\r?\n';
- var regex = new RegExp('^(\\[(.|' + mask(newline_char) + ')*\\])' +
- '(' + mask(newline_char) + ')*' +
- '1.(' + mask(newline_char) + '|.)*$', 'g');
-
- /* get header part of the PGN file */
- var header_string = pgn.replace(regex, '$1');
-
- /* no info part given, begins with moves */
- if (header_string[0] !== '[') {
- header_string = '';
- }
-
- reset();
-
- /* parse PGN header */
- var headers = parse_pgn_header(header_string, options);
- for (var key in headers) {
- set_header([key, headers[key]]);
- }
-
- /* load the starting position indicated by [Setup '1'] and
- * [FEN position] */
- if (headers['SetUp'] === '1') {
- if (!(('FEN' in headers) && load(headers['FEN'], true ))) { // second argument to load: don't clear the headers
- return false;
- }
- }
-
- /* delete header to get the moves */
- var ms = pgn.replace(header_string, '').replace(new RegExp(mask(newline_char), 'g'), ' ');
-
- /* delete comments */
- ms = ms.replace(/(\{[^}]+\})+?/g, '');
-
- /* delete recursive annotation variations */
- var rav_regex = /(\([^\(\)]+\))+?/g
- while (rav_regex.test(ms)) {
- ms = ms.replace(rav_regex, '');
- }
-
- /* delete move numbers */
- ms = ms.replace(/\d+\.(\.\.)?/g, '');
-
- /* delete ... indicating black to move */
- ms = ms.replace(/\.\.\./g, '');
-
- /* delete numeric annotation glyphs */
- ms = ms.replace(/\$\d+/g, '');
-
- /* trim and get array of moves */
- var moves = trim(ms).split(new RegExp(/\s+/));
-
- /* delete empty entries */
- moves = moves.join(',').replace(/,,+/g, ',').split(',');
- var move = '';
-
- for (var half_move = 0; half_move < moves.length - 1; half_move++) {
- move = move_from_san(moves[half_move], sloppy);
-
- /* move not possible! (don't clear the board to examine to show the
- * latest valid position)
- */
- if (move == null) {
- return false;
- } else {
- make_move(move);
- }
- }
-
- /* examine last move */
- move = moves[moves.length - 1];
- if (POSSIBLE_RESULTS.indexOf(move) > -1) {
- if (has_keys(header) && typeof header.Result === 'undefined') {
- set_header(['Result', move]);
- }
- }
- else {
- move = move_from_san(move, sloppy);
- if (move == null) {
- return false;
- } else {
- make_move(move);
- }
- }
- return true;
- },
-
- header: function() {
- return set_header(arguments);
- },
-
- ascii: function() {
- return ascii();
- },
+ // board: function() {
+ // var output = [],
+ // row = [];
+
+ // for (var i = SQUARES.a8; i <= SQUARES.h1; i++) {
+ // if (board[i] == null) {
+ // row.push(null)
+ // } else {
+ // row.push({type: board[i].type, color: board[i].color})
+ // }
+ // if ((i + 1) & 0x88) {
+ // output.push(row);
+ // row = []
+ // i += 8;
+ // }
+ // }
+
+ // return output;
+ // },
+
+ // pgn: function(options) {
+ // /* using the specification from http://www.chessclub.com/help/PGN-spec
+ // * example for html usage: .pgn({ max_width: 72, newline_char: "<br />" })
+ // */
+ // var newline = (typeof options === 'object' &&
+ // typeof options.newline_char === 'string') ?
+ // options.newline_char : '\n';
+ // var max_width = (typeof options === 'object' &&
+ // typeof options.max_width === 'number') ?
+ // options.max_width : 0;
+ // var result = [];
+ // var header_exists = false;
+
+ // /* add the PGN header headerrmation */
+ // for (var i in header) {
+ // /* TODO: order of enumerated properties in header object is not
+ // * guaranteed, see ECMA-262 spec (section 12.6.4)
+ // */
+ // result.push('[' + i + ' \"' + header[i] + '\"]' + newline);
+ // header_exists = true;
+ // }
+
+ // if (header_exists && history.length) {
+ // result.push(newline);
+ // }
+
+ // /* pop all of history onto reversed_history */
+ // var reversed_history = [];
+ // while (history.length > 0) {
+ // reversed_history.push(undo_move());
+ // }
+
+ // var moves = [];
+ // var move_string = '';
+
+ // /* build the list of moves. a move_string looks like: "3. e3 e6" */
+ // while (reversed_history.length > 0) {
+ // var move = reversed_history.pop();
+
+ // /* if the position started with black to move, start PGN with 1. ... */
+ // if (!history.length && move.color === 'b') {
+ // move_string = move_number + '. ...';
+ // } else if (move.color === 'w') {
+ // /* store the previous generated move_string if we have one */
+ // if (move_string.length) {
+ // moves.push(move_string);
+ // }
+ // move_string = move_number + '.';
+ // }
+
+ // move_string = move_string + ' ' + move_to_san(move, false);
+ // make_move(move);
+ // }
+
+ // /* are there any other leftover moves? */
+ // if (move_string.length) {
+ // moves.push(move_string);
+ // }
+
+ // /* is there a result? */
+ // if (typeof header.Result !== 'undefined') {
+ // moves.push(header.Result);
+ // }
+
+ // /* history should be back to what is was before we started generating PGN,
+ // * so join together moves
+ // */
+ // if (max_width === 0) {
+ // return result.join('') + moves.join(' ');
+ // }
+
+ // /* wrap the PGN output at max_width */
+ // var current_width = 0;
+ // for (var i = 0; i < moves.length; i++) {
+ // /* if the current move will push past max_width */
+ // if (current_width + moves[i].length > max_width && i !== 0) {
+
+ // /* don't end the line with whitespace */
+ // if (result[result.length - 1] === ' ') {
+ // result.pop();
+ // }
+
+ // result.push(newline);
+ // current_width = 0;
+ // } else if (i !== 0) {
+ // result.push(' ');
+ // current_width++;
+ // }
+ // result.push(moves[i]);
+ // current_width += moves[i].length;
+ // }
+
+ // return result.join('');
+ // },
+
+ // load_pgn: function(pgn, options) {
+ // // allow the user to specify the sloppy move parser to work around over
+ // // disambiguation bugs in Fritz and Chessbase
+ // var sloppy = (typeof options !== 'undefined' && 'sloppy' in options) ?
+ // options.sloppy : false;
+
+ // function mask(str) {
+ // return str.replace(/\\/g, '\\');
+ // }
+
+ // function has_keys(object) {
+ // for (var key in object) {
+ // return true;
+ // }
+ // return false;
+ // }
+
+ // function parse_pgn_header(header, options) {
+ // var newline_char = (typeof options === 'object' &&
+ // typeof options.newline_char === 'string') ?
+ // options.newline_char : '\r?\n';
+ // var header_obj = {};
+ // var headers = header.split(new RegExp(mask(newline_char)));
+ // var key = '';
+ // var value = '';
+
+ // for (var i = 0; i < headers.length; i++) {
+ // key = headers[i].replace(/^\[([A-Z][A-Za-z]*)\s.*\]$/, '$1');
+ // value = headers[i].replace(/^\[[A-Za-z]+\s"(.*)"\]$/, '$1');
+ // if (trim(key).length > 0) {
+ // header_obj[key] = value;
+ // }
+ // }
+
+ // return header_obj;
+ // }
+
+ // var newline_char = (typeof options === 'object' &&
+ // typeof options.newline_char === 'string') ?
+ // options.newline_char : '\r?\n';
+ // var regex = new RegExp('^(\\[(.|' + mask(newline_char) + ')*\\])' +
+ // '(' + mask(newline_char) + ')*' +
+ // '1.(' + mask(newline_char) + '|.)*$', 'g');
+
+ // /* get header part of the PGN file */
+ // var header_string = pgn.replace(regex, '$1');
+
+ // /* no info part given, begins with moves */
+ // if (header_string[0] !== '[') {
+ // header_string = '';
+ // }
+
+ // reset();
+
+ // /* parse PGN header */
+ // var headers = parse_pgn_header(header_string, options);
+ // for (var key in headers) {
+ // set_header([key, headers[key]]);
+ // }
+
+ // /* load the starting position indicated by [Setup '1'] and
+ // * [FEN position] */
+ // if (headers['SetUp'] === '1') {
+ // if (!(('FEN' in headers) && load(headers['FEN'], true ))) { // second argument to load: don't clear the headers
+ // return false;
+ // }
+ // }
+
+ // /* delete header to get the moves */
+ // var ms = pgn.replace(header_string, '').replace(new RegExp(mask(newline_char), 'g'), ' ');
+
+ // /* delete comments */
+ // ms = ms.replace(/(\{[^}]+\})+?/g, '');
+
+ // /* delete recursive annotation variations */
+ // var rav_regex = /(\([^\(\)]+\))+?/g
+ // while (rav_regex.test(ms)) {
+ // ms = ms.replace(rav_regex, '');
+ // }
+
+ // /* delete move numbers */
+ // ms = ms.replace(/\d+\.(\.\.)?/g, '');
+
+ // /* delete ... indicating black to move */
+ // ms = ms.replace(/\.\.\./g, '');
+
+ // /* delete numeric annotation glyphs */
+ // ms = ms.replace(/\$\d+/g, '');
+
+ // /* trim and get array of moves */
+ // var moves = trim(ms).split(new RegExp(/\s+/));
+
+ // /* delete empty entries */
+ // moves = moves.join(',').replace(/,,+/g, ',').split(',');
+ // var move = '';
+
+ // for (var half_move = 0; half_move < moves.length - 1; half_move++) {
+ // move = move_from_san(moves[half_move], sloppy);
+
+ // /* move not possible! (don't clear the board to examine to show the
+ // * latest valid position)
+ // */
+ // if (move == null) {
+ // return false;
+ // } else {
+ // make_move(move);
+ // }
+ // }
+
+ // /* examine last move */
+ // move = moves[moves.length - 1];
+ // if (POSSIBLE_RESULTS.indexOf(move) > -1) {
+ // if (has_keys(header) && typeof header.Result === 'undefined') {
+ // set_header(['Result', move]);
+ // }
+ // }
+ // else {
+ // move = move_from_san(move, sloppy);
+ // if (move == null) {
+ // return false;
+ // } else {
+ // make_move(move);
+ // }
+ // }
+ // return true;
+ // },
+
+ // header: function() {
+ // return set_header(arguments);
+ // },
+
+ // ascii: function() {
+ // return ascii();
+ // },