UNPKG

chlss

Version:

Open-Source Chess Engine in TypeScript.

25 lines (24 loc) 853 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BoardNotation = void 0; const coords_1 = require("./coords"); const BoardNotationChars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; exports.BoardNotation = { toBoardNotation(squareIndex) { const x = coords_1.Coords.toX(squareIndex); const y = coords_1.Coords.toY(squareIndex); return `${BoardNotationChars[x]}${8 - y}`; }, fromBoardNotation(boardNotation) { function error() { throw new Error("'fromBoardNotation' parsing error."); } const x = BoardNotationChars.indexOf(boardNotation[0]); if (x === -1) error(); const y = parseInt(boardNotation[1]) - 1; if (y < 0 || y > 7) error(); return coords_1.Coords.toSquareIndex(x, 7 - y); } };