Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

onix-chess

Package Overview
Dependencies
Maintainers
1
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

onix-chess - npm Package Compare versions

Comparing version 1.5.26 to 1.7.28

17

dist/chess/FenString.d.ts
import { Position } from './Position';
/** Flags **/
export declare enum FenFormat {
board = 0,
color = 1,
castlingEp = 2,
complete = 3
}
export declare class FenString {
static fenStandartStart: string;
static fenEmptyBoard: string;
/** Flags **/
static fenCompact: number;
static fenBoard: number;
static fenCastlingEp: number;
static fenFull: number;
static toStringBoard(fen: string): string;
static toByteBoard(fen: string): any[];
static trim(fen: string, flag: FenFormat): string;
static toPosition(pos: Position, fen: string, forceCastling?: boolean): boolean;
static fromPosition(pos: Position, flag?: number): string;
static fromPosition(pos: Position, flag?: FenFormat): string;
}

@@ -38,2 +38,3 @@ import repeat from 'lodash-es/repeat';

FP_p2f[Piece.BBishop] = "b";
var fenEmptyBoardStd = "8/8/8/8/8/8/8/8 w KQkq - 0 1";
function fen2Piece(fenCharacter) {

@@ -45,46 +46,61 @@ return (fenPieces[fenCharacter]) ? fenPieces[fenCharacter] : Piece.NoPiece;

}
var fenEmptyBoardRaw = "1111111111111111111111111111111111111111111111111111111111111111 w KQkq - 0 1";
function normalizeFen(fen) {
if (!fen) {
return fenEmptyBoardStd;
}
while (fen.indexOf(" ") >= 0) {
fen = fen.replace(" ", " ");
}
return fen;
}
/** Flags **/
export var FenFormat;
(function (FenFormat) {
FenFormat[FenFormat["board"] = 0] = "board";
FenFormat[FenFormat["color"] = 1] = "color";
FenFormat[FenFormat["castlingEp"] = 2] = "castlingEp";
FenFormat[FenFormat["complete"] = 3] = "complete";
})(FenFormat || (FenFormat = {}));
var FenString = /** @class */ (function () {
function FenString() {
}
FenString.toStringBoard = function (fen) {
if (!fen) {
fen = fenEmptyBoardRaw;
}
while (fen.indexOf(" ") >= 0) {
fen = fen.replace(" ", " ");
}
FenString.trim = function (fen, flag) {
fen = normalizeFen(fen);
var tok = fen.split(/\s+/);
var board_text = String(tok[0]);
// replace NOPIECE square with repeated "1" string
for (var i = 2; i <= 8; i++) {
var re = new RegExp(String(i), "g");
board_text = board_text.replace(re, repeat("1", i));
var result = String(tok[0]);
if (flag >= FenFormat.color) {
if (tok.length > 1) {
// color
result += (tok[1] === "b") ? " b" : " w";
if (flag >= FenFormat.castlingEp) {
if (tok.length > 2) {
// castling
result += " " + tok[2];
if (tok.length > 3) {
// enpassant
result += " " + tok[3];
if (flag >= FenFormat.complete) {
if (tok.length > 4) {
// half-move count
result += " " + tok[4];
if (tok.length > 5) {
// move number
result += " " + tok[5];
}
}
}
}
}
}
}
}
// remove slashes
board_text = board_text.replace(/\//g, "");
if (board_text.length !== 64) {
return undefined;
}
return board_text;
return result;
};
FenString.toByteBoard = function (fen) {
var board_text = FenString.toStringBoard(fen);
var board = [];
for (var i = 0; i < 64; i++) {
board[fenToSquare(i)] = fen2Piece(board_text.charAt(i));
}
return board;
};
FenString.toPosition = function (pos, fen, forceCastling) {
if (forceCastling === void 0) { forceCastling = true; }
if (!fen) {
fen = fenEmptyBoardRaw;
}
while (fen.indexOf(" ") >= 0) {
fen = fen.replace(" ", " ");
}
var i = 0, sq = 0;
fen = normalizeFen(fen);
var tok = fen.split(/\s+/);
var board_text = String(tok[0]);
var i = 0;
var sq = 0;
// replace NOPIECE square with repeated "1" string

@@ -107,3 +123,3 @@ for (i = 2; i <= 8; i++) {

}
if (tok[1]) {
if (tok.length > 1) {
// now the side to move:

@@ -114,3 +130,3 @@ pos.WhoMove = (tok[1] === "b") ? Color.Black : Color.White;

pos.Castling = 0;
if (tok[2] || forceCastling) {
if ((tok.length > 2) || forceCastling) {
if (tok[2] === "-") {

@@ -183,3 +199,3 @@ // do nothing

FenString.fromPosition = function (pos, flag) {
if (flag === void 0) { flag = FenString.fenFull; }
if (flag === void 0) { flag = FenFormat.complete; }
var fen = "";

@@ -190,3 +206,3 @@ var pB;

var NOPIECERun = 0;
if ((rank !== 7) && (flag > FenString.fenCompact)) {
if (rank !== 7) {
fen += "/";

@@ -211,5 +227,5 @@ }

}
if (flag >= FenString.fenBoard) {
if (flag >= FenFormat.color) {
fen += (pos.WhoMove == Color.Black ? " b" : " w");
if (flag >= FenString.fenCastlingEp) {
if (flag >= FenFormat.castlingEp) {
if (pos.Castling === 0) {

@@ -240,3 +256,3 @@ fen += " -";

}
if (flag >= FenString.fenFull) {
if (flag >= FenFormat.complete) {
fen += " " + pos.HalfMoveCount.toString();

@@ -250,8 +266,3 @@ fen += " " + (Math.floor(pos.PlyCount / 2) + 1).toString();

FenString.fenStandartStart = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
FenString.fenEmptyBoard = "8/8/8/8/8/8/8/8 w KQkq - 0 1";
/** Flags **/
FenString.fenCompact = 0;
FenString.fenBoard = 1;
FenString.fenCastlingEp = 2;
FenString.fenFull = 3;
FenString.fenEmptyBoard = fenEmptyBoardStd;
return FenString;

@@ -258,0 +269,0 @@ }());

@@ -56,3 +56,3 @@ import { SimpleMove } from './SimpleMove';

*/
exitVariation(): Window | this;
exitVariation(): this | Window;
truncate(): void;

@@ -59,0 +59,0 @@ append(sm: SimpleMove): Move;

@@ -8,4 +8,5 @@ export { Intl } from './Intl';

export { SimpleMove } from './chess/SimpleMove';
export { Position, ChessPositionStd } from './chess/Position';
export { FenString } from './chess/FenString';
export { Position } from './chess/Position';
export { IOpeningPosition } from './chess/IOpeningPosition';
export { Chess } from './chess/Chess';

@@ -8,4 +8,5 @@ export { Intl } from './Intl';

export { SimpleMove } from './chess/SimpleMove';
export { Position, ChessPositionStd } from './chess/Position';
export { FenString } from './chess/FenString';
export { Position } from './chess/Position';
export { Chess } from './chess/Chess';
//# sourceMappingURL=index.js.map
{
"name": "onix-chess",
"version": "1.5.26",
"version": "1.7.28",
"description": "Onix chess library",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -43,2 +43,4 @@ import repeat from 'lodash-es/repeat';

const fenEmptyBoardStd = "8/8/8/8/8/8/8/8 w KQkq - 0 1";
function fen2Piece(fenCharacter: string): number

@@ -54,71 +56,78 @@ {

const fenEmptyBoardRaw = "1111111111111111111111111111111111111111111111111111111111111111 w KQkq - 0 1";
function normalizeFen(fen: string): string {
if (!fen) {
return fenEmptyBoardStd;
}
while (fen.indexOf(" ") >= 0) {
fen = fen.replace(" ", " ");
}
return fen;
}
/** Flags **/
export enum FenFormat {
board = 0,
color = 1,
castlingEp = 2,
complete = 3,
}
export class FenString {
public static fenStandartStart = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
public static fenEmptyBoard = "8/8/8/8/8/8/8/8 w KQkq - 0 1";
public static fenEmptyBoard = fenEmptyBoardStd;
/** Flags **/
public static fenCompact = 0;
public static fenBoard = 1;
public static fenCastlingEp = 2;
public static fenFull = 3;
public static trim(fen: string, flag: FenFormat) {
fen = normalizeFen(fen);
public static toStringBoard(fen: string): string
{
if (!fen) {
fen = fenEmptyBoardRaw;
}
while (fen.indexOf(" ") >= 0) {
fen = fen.replace(" ", " ");
}
const tok = fen.split(/\s+/);
let board_text = String(tok[0]);
let result = String(tok[0]);
// replace NOPIECE square with repeated "1" string
for (let i: number = 2; i <= 8; i++) {
var re = new RegExp(String(i), "g");
board_text = board_text.replace(re, repeat("1", i));
}
if (flag >= FenFormat.color) {
if (tok.length > 1) {
// color
result += (tok[1] === "b") ? " b" : " w";
// remove slashes
board_text = board_text.replace(/\//g, "");
if (board_text.length !== 64) {
return undefined;
}
if (flag >= FenFormat.castlingEp) {
if (tok.length > 2) {
// castling
result += " " + tok[2];
if (tok.length > 3) {
// enpassant
result += " " + tok[3];
return board_text;
}
if (flag >= FenFormat.complete) {
if (tok.length > 4) {
// half-move count
result += " " + tok[4];
public static toByteBoard(fen: string)
{
const board_text = FenString.toStringBoard(fen);
const board = [];
for (let i: number = 0; i < 64; i++) {
board[fenToSquare(i)] = fen2Piece(board_text.charAt(i));
if (tok.length > 5) {
// move number
result += " " + tok[5];
}
}
}
}
}
}
}
}
return board;
return result;
}
public static toPosition(pos: Position, fen: string, forceCastling: boolean = true) {
if (!fen) {
fen = fenEmptyBoardRaw;
}
fen = normalizeFen(fen);
while (fen.indexOf(" ") >= 0) {
fen = fen.replace(" ", " ");
}
const tok = fen.split(/\s+/);
let board_text = String(tok[0]);
let i: number = 0;
let sq: number = 0;
var i: number = 0,
sq: number = 0;
var tok = fen.split(/\s+/);
var board_text = String(tok[0]);
// replace NOPIECE square with repeated "1" string
for (i = 2; i <= 8; i++) {
var re = new RegExp(String(i), "g");
const re = new RegExp(String(i), "g");
board_text = board_text.replace(re, repeat("1", i));

@@ -136,3 +145,3 @@ }

for (sq = 0; sq < 64; sq++) {
var p = fen2Piece[board_text.charAt(sq)];
const p = fen2Piece[board_text.charAt(sq)];
if (p !== Piece.NoPiece) {

@@ -143,3 +152,3 @@ pos.addPiece(p, fenToSquare(sq));

if (tok[1]) {
if (tok.length > 1) {
// now the side to move:

@@ -152,3 +161,3 @@ pos.WhoMove = (tok[1] === "b") ? Color.Black : Color.White;

pos.Castling = 0;
if (tok[2] || forceCastling) {
if ((tok.length > 2) || forceCastling) {
if (tok[2] === "-") {

@@ -227,5 +236,5 @@ // do nothing

public static fromPosition(pos: Position, flag: number = FenString.fenFull) {
public static fromPosition(pos: Position, flag: FenFormat = FenFormat.complete) {
let fen = "";
var pB: number;
let pB: number;

@@ -235,3 +244,3 @@ const board = pos.Board;

let NOPIECERun = 0;
if ((rank !== 7) && (flag > FenString.fenCompact)) { fen += "/"; }
if (rank !== 7) { fen += "/"; }
for (let fyle = 0; fyle <= 7; fyle++) {

@@ -250,6 +259,6 @@ pB = board[Square.create(fyle, rank)];

if (flag >= FenString.fenBoard) {
if (flag >= FenFormat.color) {
fen += (pos.WhoMove == Color.Black ? " b" : " w");
if (flag >= FenString.fenCastlingEp) {
if (flag >= FenFormat.castlingEp) {
if (pos.Castling === 0) {

@@ -283,3 +292,3 @@ fen += " -";

if (flag >= FenString.fenFull) {
if (flag >= FenFormat.complete) {
fen += " " + pos.HalfMoveCount.toString();

@@ -286,0 +295,0 @@ fen += " " + (Math.floor(pos.PlyCount / 2) + 1).toString();

@@ -8,4 +8,5 @@ export { Intl } from './Intl';

export { SimpleMove } from './chess/SimpleMove';
export { Position, ChessPositionStd } from './chess/Position';
export { FenString } from './chess/FenString';
export { Position } from './chess/Position';
export { IOpeningPosition } from './chess/IOpeningPosition';
export { Chess } from './chess/Chess';

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc