@mychess/openings
Version:
Chess openings.
66 lines (65 loc) • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var openings_1 = require("./openings");
var openings_2 = require("./openings");
exports.Openings = openings_2.Openings;
var chess_js_1 = require("chess.js");
var Fen = /** @class */ (function () {
function Fen(pgn) {
this.pgn = pgn;
this.chess = new chess_js_1.Chess(pgn);
}
Fen.prototype.getFens = function () {
var moves = this.getMoves();
var fen = [];
var chess = new chess_js_1.Chess();
for (var i = 0; i < 30; i++) {
if (!moves[i])
continue;
var yam = moves[i].split(' ');
var w = yam[0];
var b = yam[1];
chess.move(w);
fen.push(chess.fen());
chess.move(b);
fen.push(chess.fen());
}
return fen;
};
Fen.prototype.getOpenings = function () {
var fens = this.getFens();
var openings = [];
for (var i = 0; i < fens.length; i++) {
var opening = openings_1.Openings.byFen(fens[i]);
if (opening) {
openings.push(opening);
}
}
return openings;
//return Object.values(Book)
};
Fen.prototype.getMoves = function (group) {
if (group === void 0) { group = true; }
var moves = this.pgn.split('.');
var result = [];
for (var i = 0; i < moves.length; i++) {
var move = moves[i];
var clean = move.trim();
var sector = clean.split(' ');
var one = typeof sector[0] == 'undefined' ? '' : sector[0];
var two = typeof sector[1] == 'undefined' ? '' : sector[1];
if (group) {
result.push((one + " " + two).trim());
}
else {
if (one)
result.push(one.trim());
if (two)
result.push(two.trim());
}
}
return result.slice(1);
};
return Fen;
}());
exports.Fen = Fen;