UNPKG

pgn.js

Version:

Chess PGN, Portable Game Notation, Javascript Library

40 lines (36 loc) 889 B
export class Util { /** * @private */ static fill_move(move, chess) { move.fen = chess.fen() move.uci = move.from + move.to + (move.flags=='p'?move.promotion:''); move.vars = [] if (chess.isGameOver()) { move.over = {} if (chess.isCheckmate()) { move.over.mate = true; } else if (chess.isDraw()) { if (chess.isStalemate()) move.over.draw = 'stale'; else if (chess.isInsufficientMaterial()) move.over.draw = 'material'; else if (chess.isThreefoldRepetition()) move.over.draw = '3fold'; else move.over.draw = 'fifty'; } } if (chess.isCheck()) { move.check = true } } /** * @private */ static move_num_from_fen(fen) { const tokens = fen?.split(/\s+/) return (tokens&&tokens.length>5)?parseInt(tokens[5]):1; } };