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 5.0.1 to 5.2.0

25

dist/chess/Chess.d.ts
import { Position } from './Position';
import { Move } from './Move';
import { SimpleMove } from './SimpleMove';
import { IChessUser } from '../types/Interfaces';
import { IGameData, IChessPlayer } from '../types/Interfaces';
import { Squares, Colors } from '../types/Types';

@@ -37,12 +37,4 @@ export declare enum ChessRatingType {

}
export interface IChessSettings {
id?: number;
my_color?: string;
white?: IChessUser;
black?: IChessUser;
fen?: string;
moves?: any[];
}
export declare class Chess {
private settings;
private data;
private savedMove;

@@ -73,4 +65,4 @@ private savedPos;

GameId: number;
White?: IChessUser;
Black?: IChessUser;
White?: IChessPlayer;
Black?: IChessPlayer;
Event?: string;

@@ -90,3 +82,3 @@ Site?: string;

*/
constructor(settings?: IChessSettings);
constructor(data?: IGameData);
get CurrentMove(): Move;

@@ -96,2 +88,6 @@ get CurrentPos(): Position;

get NonStandardStart(): boolean;
init(): void;
private assignPlayer;
private isInstanceOfTreePart;
private decodeMoves;
private clear;

@@ -101,3 +97,2 @@ private clearStandardTags;

private clearMoves;
private decodeMoves;
private positionChanged;

@@ -111,3 +106,3 @@ checkGameState(): ChessGameState;

*/
addMove(sm: SimpleMove, san?: string): Move;
addMove(sm: SimpleMove, san?: string, fen?: string): Move;
/**

@@ -114,0 +109,0 @@ * Переместиться на указанную позицию в главной линии партии

216

dist/chess/Chess.js

@@ -143,2 +143,24 @@ "use strict";

exports.ChessGameState = ChessGameState;
const defaultGameData = {
game: {
id: 0,
load: false,
insite: false,
variant: {
key: "standard",
name: "Standard",
shortName: "Std"
},
speed: "correspondence",
rated: false,
initialFen: "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
player: "white",
turns: 0,
startedAtTurn: 0,
status: {
name: "noStart"
},
},
orientation: "white"
};
class Chess {

@@ -148,3 +170,3 @@ /**

*/
constructor(settings) {
constructor(data) {
this.savedMove = null;

@@ -169,16 +191,11 @@ this.savedPos = null;

this.NoQueenPromotion = false;
this.GameId = 0;
this.Result = ChessResultColor.None;
this.settings = settings || {};
this.data = data || defaultGameData;
this.Tags = new ChessTags(this);
this.Altered = false;
this.pgnLastMovePos = this.pgnNextMovePos = 0;
if (this.settings.fen && (this.settings.fen != FenString_1.FenString.standartStart)) {
this.startFen = this.settings.fen;
this.startPos = new Position_1.Position(this.settings.fen);
}
else {
this.startPos = Position_1.ChessPositionStd;
}
this.startPos = Position_1.ChessPositionStd;
this.clear();
this.GameId = this.settings.id || 0;
this.init();
this.positionChanged();

@@ -198,2 +215,64 @@ }

}
init() {
const { game, player, opponent, steps, treeParts } = this.data;
if (game) {
if (game.initialFen != FenString_1.FenString.standartStart) {
this.startFen = game.initialFen;
this.startPos = new Position_1.Position(game.initialFen);
}
else {
this.startPos = Position_1.ChessPositionStd;
}
this.GameId = game.id;
this.Event = game.event;
if (game.opening) {
this.EcoCode = game.opening.code;
}
}
this.assignPlayer(player);
this.assignPlayer(opponent);
const moves = steps !== null && steps !== void 0 ? steps : treeParts;
if (moves) {
this.supressEvents = true;
this.decodeMoves(moves);
this.supressEvents = false;
}
this.ToMove = this.currentPos.WhoMove;
}
assignPlayer(player) {
if (player) {
if (player.color === "black") {
this.Black = player;
}
else {
this.White = player;
}
}
}
isInstanceOfTreePart(object) {
return 'eval' in object;
}
decodeMoves(moves) {
for (let i = 0; i < moves.length; i++) {
const mv = moves[i];
if (mv.uci === undefined) {
continue;
}
const sm = this.currentPos.readCoordMove(mv.uci);
if (sm !== null) {
sm.plyCount = this.CurrentPos.PlyCount + 1;
sm.permanent = true;
sm.san = mv.san;
if (this.isInstanceOfTreePart(mv)) {
if (mv.comments && (mv.comments.length > 0)) {
sm.comments = mv.comments[0].comment;
}
}
const move = this.addMove(sm, sm.san, mv.fen);
move.id = mv.id || "0";
move.data = mv;
this.moveList[move.moveKey] = move;
}
}
}
clear() {

@@ -212,4 +291,18 @@ this.GameId = 0;

clearStandardTags() {
this.White = { id: 0, username: "?" };
this.Black = { id: 0, username: "?" };
this.White = {
color: "white",
name: "?",
user: {
id: 0,
username: "?"
}
};
this.Black = {
color: "black",
name: "?",
user: {
id: 0,
username: "?"
}
};
this.Event = "?";

@@ -248,48 +341,10 @@ this.Site = "?";

this.StartPlyCount = this.currentPos.PlyCount;
const { moves } = this.settings;
if (moves) {
this.supressEvents = true;
this.decodeMoves(moves);
this.supressEvents = false;
}
this.ToMove = this.currentPos.WhoMove;
}
decodeMoves(moves) {
for (let i = 0; i < moves.length; i++) {
// 0 - from/to/color
// 1 - san
// 2 - captured
// 3 - promote
// 4 - comments
// 5 - nag
// 6 - variations
const mv = moves[i];
const sm = new SimpleMove_1.SimpleMove();
sm.PlyCount = this.CurrentPos.PlyCount + 1;
const from = mv[0] & 63;
const to = (mv[0] >> 6) & 63;
const color = (mv[0] >> 12) & 63;
const capturedPiece = mv[2] & 63;
const capturedSquare = (mv[2] >> 6) & 63;
sm.From = Square_1.Square.isSquare(from) ? from : Square_1.Square.NullSquare;
sm.To = Square_1.Square.isSquare(to) ? to : Square_1.Square.NullSquare;
;
sm.Color = Color_1.Color.isColor(color) ? color : Color_1.Color.None;
sm.CapturedPiece = Piece_1.Piece.isPiece(capturedPiece) ? capturedPiece : Piece_1.Piece.None;
sm.CapturedSquare = Square_1.Square.isSquare(capturedSquare) ? capturedSquare : Square_1.Square.NullSquare;
sm.San = mv[1];
sm.Promote = Piece_1.Piece.isPieceType(mv[3]) ? mv[3] : Piece_1.Piece.None;
sm.Comments = mv[4];
sm.Nag = mv[5];
sm.Permanent = true;
const move = this.addMove(sm, sm.San);
this.moveList[move.moveKey] = move;
}
}
positionChanged() {
if (!this.supressEvents) {
if (!this.currentMove.Fen) {
this.currentMove.Fen = FenString_1.FenString.fromPosition(this.currentPos);
if (!this.currentMove.fen) {
this.currentMove.fen = FenString_1.FenString.fromPosition(this.currentPos);
}
this.Fen = this.currentMove.Fen;
this.Fen = this.currentMove.fen;
}

@@ -341,6 +396,6 @@ }

const move = this.currentMove.Prev;
const thisFen = move.Fen;
const thisFen = move.fen;
let rc = 1;
while (!move.START_MARKER) {
if (thisFen === move.Fen) {
if (thisFen === move.fen) {
rc++;

@@ -356,16 +411,16 @@ }

const sm = new SimpleMove_1.SimpleMove();
sm.PieceNum = currentPos.getPieceNum(fr);
sm.MovingPiece = currentPos.getPiece(fr);
if (!Piece_1.Piece.isPiece(sm.MovingPiece)) {
sm.pieceNum = currentPos.getPieceNum(fr);
sm.movingPiece = currentPos.getPiece(fr);
if (!Piece_1.Piece.isPiece(sm.movingPiece)) {
return;
}
sm.Color = Piece_1.Piece.color(sm.MovingPiece);
sm.From = fr;
sm.To = to;
sm.CapturedPiece = currentPos.getPiece(to);
sm.CapturedSquare = to;
sm.CastleFlags = currentPos.Castling.Flag;
sm.EpSquare = currentPos.EpTarget;
sm.Promote = Piece_1.Piece.None;
const piece = sm.MovingPiece;
sm.color = Piece_1.Piece.color(sm.movingPiece);
sm.from = fr;
sm.to = to;
sm.capturedPiece = currentPos.getPiece(to);
sm.capturedSquare = to;
sm.castleFlags = currentPos.Castling.Flag;
sm.epSquare = currentPos.EpTarget;
sm.promote = Piece_1.Piece.None;
const piece = sm.movingPiece;
const ptype = Piece_1.Piece.type(piece);

@@ -381,10 +436,10 @@ const enemy = Color_1.Color.flip(currentPos.WhoMove);

else {
sm.Promote = Piece_1.Piece.typeFromChar(promote);
sm.promote = Piece_1.Piece.typeFromChar(promote);
}
}
// Handle en passant capture:
if (ptype == Piece_1.Piece.Pawn && (sm.CapturedPiece == Piece_1.Piece.None) && (Square_1.Square.fyle(fr) != Square_1.Square.fyle(to))) {
if (ptype == Piece_1.Piece.Pawn && (sm.capturedPiece == Piece_1.Piece.None) && (Square_1.Square.fyle(fr) != Square_1.Square.fyle(to))) {
const enemyPawn = Piece_1.Piece.create(enemy, Piece_1.Piece.Pawn);
sm.CapturedSquare = (this.currentPos.WhoMove === Color_1.Color.White ? (to - 8) : (to + 8));
sm.CapturedPiece = enemyPawn;
sm.capturedSquare = (this.currentPos.WhoMove === Color_1.Color.White ? (to - 8) : (to + 8));
sm.capturedPiece = enemyPawn;
}

@@ -398,3 +453,3 @@ return sm;

*/
addMove(sm, san) {
addMove(sm, san, fen) {
const { currentPos } = this;

@@ -406,8 +461,8 @@ // We must be at the end of a game/variation to add a move:

}
if (!sm.San) {
if (!sm.san) {
if (!san || (san == undefined)) {
sm.San = this.currentPos.makeSanString(sm, Position_1.SanCheckLevel.MateTest);
sm.san = this.currentPos.makeSanString(sm, Position_1.SanCheckLevel.MateTest);
}
else {
sm.San = san;
sm.san = san;
}

@@ -417,3 +472,6 @@ }

this.currentPos.doSimpleMove(sm);
newMove.Fen = FenString_1.FenString.fromPosition(currentPos);
if (!fen) {
fen = FenString_1.FenString.fromPosition(currentPos);
}
newMove.fen = fen;
this.CurrentPlyCount++;

@@ -456,3 +514,3 @@ if (!this.varDepth) {

this.currentMove = this.moveList[key];
this.currentPos = new Position_1.Position(this.currentMove.Fen);
this.currentPos = new Position_1.Position(this.currentMove.fen);
this.CurrentPlyCount = this.currentPos.PlyCount;

@@ -471,3 +529,3 @@ this.currentMove = this.currentMove.Next;

}
this.currentPos.doSimpleMove(this.currentMove.moveData);
this.currentPos.doSimpleMove(this.currentMove.sm);
this.currentMove = this.currentMove.Next;

@@ -488,3 +546,3 @@ this.CurrentPlyCount++;

this.currentMove = prev;
this.currentPos.undoSimpleMove(this.currentMove.moveData);
this.currentPos.undoSimpleMove(this.currentMove.sm);
this.CurrentPlyCount--;

@@ -491,0 +549,0 @@ this.positionChanged();

import { SimpleMove } from './SimpleMove';
import { Colors } from '../types/Types';
import { ITreePart, IMovePart } from '../types/Interfaces';
/**

@@ -10,11 +11,2 @@ * Move in position

private ply;
private from?;
private to?;
private color?;
private capturedSquare?;
private capturedPiece?;
private promote?;
private piece_num;
private permanent;
private legal_moves;
private parent;

@@ -26,8 +18,9 @@ private prev_move;

uid: string;
id: number;
moveData: SimpleMove | null;
Name: string;
WhoMove: Colors.BW;
Comments: string;
Fen: string | undefined;
id: string;
name: string;
whoMove: Colors.BW;
comments: string;
fen: string | undefined;
sm: SimpleMove | null;
data?: ITreePart | IMovePart;
/**

@@ -34,0 +27,0 @@ * @constructor

@@ -6,4 +6,2 @@ "use strict";

const Color_1 = require("./Color");
const Piece_1 = require("./Piece");
const Square_1 = require("./Square");
/**

@@ -20,17 +18,9 @@ * Move in position

this.parent = null;
this.id = 0;
this.id = "0";
this.uid = shortid.generate();
this.Name = "";
this.moveData = null;
this.from = Square_1.Square.NullSquare;
this.to = Square_1.Square.NullSquare;
this.color = Color_1.Color.None;
this.capturedSquare = Square_1.Square.NullSquare;
this.capturedPiece = Piece_1.Piece.None;
this.promote = Piece_1.Piece.None;
this.piece_num = 0;
this.WhoMove = Color_1.Color.White;
this.name = "";
this.sm = null;
this.whoMove = Color_1.Color.White;
this.ply = 0;
this.Comments = "";
this.permanent = true;
this.comments = "";
this.START_MARKER = false;

@@ -40,8 +30,7 @@ this.END_MARKER = false;

this.next_move = null;
this.legal_moves = [];
}
static init(fen, parent) {
const firstMove = new Move();
firstMove.Name = "FirstMove";
firstMove.Fen = fen;
firstMove.name = "FirstMove";
firstMove.fen = fen;
firstMove.ply = 0;

@@ -51,3 +40,3 @@ firstMove.START_MARKER = true;

firstMove.next_move = new Move();
firstMove.next_move.Name = "LastMove";
firstMove.next_move.name = "LastMove";
firstMove.next_move.ply = 0;

@@ -113,3 +102,3 @@ firstMove.next_move.START_MARKER = false;

if (prev) {
varRoot = Move.init(prev.Fen, prev);
varRoot = Move.init(prev.fen, prev);
prev.vars.push(varRoot);

@@ -147,5 +136,5 @@ }

newMove.varNo = this.varNo;
newMove.moveData = sm;
newMove.Name = sm.San ? sm.San : sm.PlyCount.toString();
newMove.ply = sm.PlyCount;
newMove.sm = sm;
newMove.name = sm.san ? sm.san : sm.plyCount.toString();
newMove.ply = sm.plyCount;
newMove.next_move = this;

@@ -152,0 +141,0 @@ newMove.prev_move = this.prev_move;

@@ -6,20 +6,20 @@ import { Colors, Pieces, Squares } from '../types/Types';

export declare class SimpleMove {
PieceNum: number;
MovingPiece?: Pieces.Piece;
From?: Squares.Square;
To?: Squares.Square;
Color?: Colors.BW;
CapturedNum: number;
CapturedPiece?: Pieces.Piece;
Promote?: Pieces.PieceType;
CapturedSquare?: Squares.Square;
CastleFlags: number;
EpSquare?: Squares.Square;
OldHalfMoveClock: number;
PlyCount: number;
San: string;
Comments: string;
Nag: string;
Permanent: boolean;
pieceNum: number;
movingPiece?: Pieces.Piece;
from?: Squares.Square;
to?: Squares.Square;
color?: Colors.BW;
capturedNum: number;
capturedPiece?: Pieces.Piece;
promote?: Pieces.PieceType;
capturedSquare?: Squares.Square;
castleFlags: number;
epSquare?: Squares.Square;
oldHalfMoveClock: number;
plyCount: number;
san?: string;
comments?: string;
nag?: string;
permanent: boolean;
toString(): string;
}

@@ -14,22 +14,19 @@ "use strict";

constructor() {
this.PieceNum = 0;
this.MovingPiece = np;
this.From = ns;
this.To = ns;
this.Color = Color_1.Color.None;
this.CapturedNum = 0;
this.CapturedPiece = np;
this.Promote = np;
this.CapturedSquare = ns; // only different to "to" field if this capture is an en passant capture.
this.CastleFlags = 0;
this.EpSquare = ns;
this.OldHalfMoveClock = 0;
this.PlyCount = 0;
this.San = "";
this.Comments = "";
this.Nag = "";
this.Permanent = true;
this.pieceNum = 0;
this.movingPiece = np;
this.from = ns;
this.to = ns;
this.color = Color_1.Color.None;
this.capturedNum = 0;
this.capturedPiece = np;
this.promote = np;
this.capturedSquare = ns; // only different to "to" field if this capture is an en passant capture.
this.castleFlags = 0;
this.epSquare = ns;
this.oldHalfMoveClock = 0;
this.plyCount = 0;
this.permanent = true;
}
toString() {
return this.San;
return this.san || "";
}

@@ -36,0 +33,0 @@ }

@@ -21,4 +21,4 @@ import { IUser } from 'onix-core/dist/app/IUser';

name: StatusName;
result: number;
result_name: string;
result?: number;
result_name?: string;
}

@@ -39,6 +39,6 @@ export declare type PerfNameType = 'main' | 'maina' | 'classic' | 'classia' | SpeedNameType | VariantNameType;

speed: 'correspondence' | 'classical' | SpeedNameType;
perf: PerfNameType;
rated: boolean;
perf?: PerfNameType;
rated?: boolean;
initialFen: string;
fen: string;
fen?: string;
player: Colors.Name;

@@ -48,11 +48,11 @@ turns: number;

status: IGameStatus;
event: string;
event?: string;
tournamentId?: number;
createdAt: number;
private: boolean;
advance: boolean;
createdAt?: number;
private?: boolean;
advance?: boolean;
winner?: Colors.Name;
lastMove?: string;
check?: string;
moveCentis: number[];
moveCentis?: number[];
opening?: IChessOpening;

@@ -155,7 +155,7 @@ }

export interface IGameData {
game: IChessGame;
game?: IChessGame;
tournament?: IChessTournament;
clock?: IBlitzClock;
correspondence?: ICorrespondenceClock | IAdvanceClock;
player: IChessPlayer;
player?: IChessPlayer;
opponent?: IChessPlayer;

@@ -162,0 +162,0 @@ orientation: Colors.Name;

{
"name": "onix-chess",
"version": "5.0.1",
"version": "5.2.0",
"description": "Onix chess library",

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

@@ -12,3 +12,3 @@ import toSafeInteger from 'lodash-es/toSafeInteger';

import { SimpleMove } from './SimpleMove';
import { IChessUser } from '../types/Interfaces';
import { IChessUser, IChessGame, IGameData, IMovePart, ITreePart, IChessPlayer } from '../types/Interfaces';
import { FenString } from './FenString';

@@ -157,15 +157,30 @@ import { Squares, Colors } from '../types/Types';

export interface IChessSettings {
id?: number,
my_color?: string,
white?: IChessUser,
black?: IChessUser,
fen?: string,
moves?: any[]
}
type encodedMoves = [number, string, number, number, string, string];
const defaultGameData: IGameData = {
game: {
id: 0,
load: false,
insite: false,
variant: {
key: "standard",
name: "Standard",
shortName: "Std"
},
speed: "correspondence",
rated: false,
initialFen: "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
player: "white",
turns: 0,
startedAtTurn: 0,
status: {
name: "noStart"
},
},
orientation: "white"
};
export class Chess {
private settings: IChessSettings;
private data: IGameData;
private savedMove: Move | null = null;

@@ -203,5 +218,5 @@ private savedPos: Position | null = null;

public Tags: ChessTags;
public GameId: number;
public White?: IChessUser;
public Black?: IChessUser;
public GameId: number = 0;
public White?: IChessPlayer;
public Black?: IChessPlayer;
public Event?: string;

@@ -222,4 +237,4 @@ public Site?: string;

*/
constructor(settings?: IChessSettings) {
this.settings = settings || {};
constructor(data?: IGameData) {
this.data = data || defaultGameData;

@@ -230,13 +245,7 @@ this.Tags = new ChessTags(this);

if (this.settings.fen && (this.settings.fen != FenString.standartStart)) {
this.startFen = this.settings.fen;
this.startPos = new Position(this.settings.fen);
} else {
this.startPos = ChessPositionStd;
}
this.startPos = ChessPositionStd;
this.clear();
this.init();
this.GameId = this.settings.id || 0;
this.positionChanged();

@@ -261,2 +270,73 @@ }

public init() {
const { game, player, opponent, steps, treeParts } = this.data;
if (game) {
if (game.initialFen != FenString.standartStart) {
this.startFen = game.initialFen;
this.startPos = new Position(game.initialFen);
} else {
this.startPos = ChessPositionStd;
}
this.GameId = game.id;
this.Event = game.event;
if (game.opening) {
this.EcoCode = game.opening.code;
}
}
this.assignPlayer(player);
this.assignPlayer(opponent);
const moves = steps ?? treeParts;
if (moves) {
this.supressEvents = true;
this.decodeMoves(moves);
this.supressEvents = false;
}
this.ToMove = this.currentPos.WhoMove;
}
private assignPlayer(player?: IChessPlayer) {
if (player) {
if (player.color === "black") {
this.Black = player;
} else {
this.White = player;
}
}
}
private isInstanceOfTreePart(object: IMovePart|ITreePart): object is ITreePart {
return 'eval' in object;
}
private decodeMoves(moves: IMovePart[]|ITreePart[]) {
for (let i = 0; i < moves.length; i++) {
const mv = moves[i];
if (mv.uci === undefined) {
continue;
}
const sm = this.currentPos.readCoordMove(mv.uci);
if (sm !== null) {
sm.plyCount = this.CurrentPos.PlyCount + 1;
sm.permanent = true;
sm.san = mv.san;
if (this.isInstanceOfTreePart(mv)) {
if (mv.comments && (mv.comments.length > 0)) {
sm.comments = mv.comments[0].comment;
}
}
const move = this.addMove(sm, sm.san, mv.fen);
move.id = mv.id || "0";
move.data = mv;
this.moveList[move.moveKey] = move;
}
}
}
private clear() {

@@ -278,4 +358,20 @@ this.GameId = 0;

private clearStandardTags () {
this.White = { id: 0, username: "?"};
this.Black = { id: 0, username: "?"};
this.White = {
color: "white",
name: "?",
user: {
id: 0,
username: "?"
}
};
this.Black = {
color: "black",
name: "?",
user: {
id: 0,
username: "?"
}
};
this.Event = "?";

@@ -319,9 +415,2 @@ this.Site = "?";

this.StartPlyCount = this.currentPos.PlyCount;
const { moves } = this.settings;
if (moves) {
this.supressEvents = true;
this.decodeMoves(moves);
this.supressEvents = false;
}

@@ -331,44 +420,9 @@ this.ToMove = this.currentPos.WhoMove;

private decodeMoves(moves: encodedMoves[]) {
for (let i = 0; i < moves.length; i++) {
// 0 - from/to/color
// 1 - san
// 2 - captured
// 3 - promote
// 4 - comments
// 5 - nag
// 6 - variations
const mv = moves[i];
const sm = new SimpleMove();
sm.PlyCount = this.CurrentPos.PlyCount + 1;
const from = mv[0] & 63;
const to = (mv[0] >> 6) & 63;
const color = (mv[0] >> 12) & 63;
const capturedPiece = mv[2] & 63;
const capturedSquare = (mv[2] >> 6) & 63;
sm.From = Square.isSquare(from) ? from : Square.NullSquare;
sm.To = Square.isSquare(to) ? to : Square.NullSquare;;
sm.Color = Color.isColor(color) ? color : Color.None;
sm.CapturedPiece = Piece.isPiece(capturedPiece) ? capturedPiece : Piece.None;
sm.CapturedSquare = Square.isSquare(capturedSquare) ? capturedSquare : Square.NullSquare;
sm.San = mv[1];
sm.Promote = Piece.isPieceType(mv[3]) ? mv[3] : Piece.None;
sm.Comments = mv[4];
sm.Nag = mv[5];
sm.Permanent = true;
const move = this.addMove(sm, sm.San);
this.moveList[move.moveKey] = move;
}
}
private positionChanged() {
if (!this.supressEvents) {
if (!this.currentMove.Fen) {
this.currentMove.Fen = FenString.fromPosition(this.currentPos);
if (!this.currentMove.fen) {
this.currentMove.fen = FenString.fromPosition(this.currentPos);
}
this.Fen = this.currentMove.Fen;
this.Fen = this.currentMove.fen;
}

@@ -421,6 +475,6 @@ }

const move = this.currentMove.Prev!;
const thisFen = move.Fen;
const thisFen = move.fen;
let rc = 1;
while (!move.START_MARKER) {
if (thisFen === move.Fen) {
if (thisFen === move.fen) {
rc++;

@@ -439,18 +493,18 @@ }

const sm = new SimpleMove();
sm.PieceNum = currentPos.getPieceNum(fr);
sm.MovingPiece = currentPos.getPiece(fr);
if (!Piece.isPiece(sm.MovingPiece)) {
sm.pieceNum = currentPos.getPieceNum(fr);
sm.movingPiece = currentPos.getPiece(fr);
if (!Piece.isPiece(sm.movingPiece)) {
return;
}
sm.Color = Piece.color(sm.MovingPiece);
sm.From = fr;
sm.To = to;
sm.CapturedPiece = currentPos.getPiece(to);
sm.CapturedSquare = to;
sm.CastleFlags = currentPos.Castling.Flag;
sm.EpSquare = currentPos.EpTarget;
sm.Promote = Piece.None;
sm.color = Piece.color(sm.movingPiece);
sm.from = fr;
sm.to = to;
sm.capturedPiece = currentPos.getPiece(to);
sm.capturedSquare = to;
sm.castleFlags = currentPos.Castling.Flag;
sm.epSquare = currentPos.EpTarget;
sm.promote = Piece.None;
const piece = sm.MovingPiece;
const piece = sm.movingPiece;
const ptype = Piece.type(piece);

@@ -466,3 +520,3 @@ const enemy = Color.flip(currentPos.WhoMove);

} else {
sm.Promote = Piece.typeFromChar(promote);
sm.promote = Piece.typeFromChar(promote);
}

@@ -472,6 +526,6 @@ }

// Handle en passant capture:
if (ptype == Piece.Pawn && (sm.CapturedPiece == Piece.None) && (Square.fyle(fr) != Square.fyle(to))) {
if (ptype == Piece.Pawn && (sm.capturedPiece == Piece.None) && (Square.fyle(fr) != Square.fyle(to))) {
const enemyPawn = Piece.create(enemy, Piece.Pawn);
sm.CapturedSquare = (this.currentPos.WhoMove === Color.White ? (to - 8) as Squares.Square : (to + 8) as Squares.Square);
sm.CapturedPiece = enemyPawn;
sm.capturedSquare = (this.currentPos.WhoMove === Color.White ? (to - 8) as Squares.Square : (to + 8) as Squares.Square);
sm.capturedPiece = enemyPawn;
}

@@ -487,3 +541,3 @@

*/
public addMove(sm: SimpleMove, san?: string) {
public addMove(sm: SimpleMove, san?: string, fen?: string) {
const { currentPos } = this;

@@ -497,7 +551,7 @@

if (!sm.San) {
if (!sm.san) {
if (!san || (san == undefined)) {
sm.San = this.currentPos.makeSanString(sm, SanCheckLevel.MateTest);
sm.san = this.currentPos.makeSanString(sm, SanCheckLevel.MateTest);
} else {
sm.San = san;
sm.san = san;
}

@@ -509,3 +563,6 @@ }

this.currentPos.doSimpleMove(sm);
newMove.Fen = FenString.fromPosition(currentPos);
if (!fen) {
fen = FenString.fromPosition(currentPos);
}
newMove.fen = fen;
this.CurrentPlyCount++;

@@ -555,3 +612,3 @@

this.currentMove = this.moveList[key];
this.currentPos = new Position(this.currentMove.Fen);
this.currentPos = new Position(this.currentMove.fen);
this.CurrentPlyCount = this.currentPos.PlyCount;

@@ -573,3 +630,3 @@ this.currentMove = this.currentMove.Next!;

this.currentPos.doSimpleMove(this.currentMove.moveData!);
this.currentPos.doSimpleMove(this.currentMove.sm!);
this.currentMove = this.currentMove.Next!;

@@ -593,3 +650,3 @@ this.CurrentPlyCount++;

this.currentMove = prev;
this.currentPos.undoSimpleMove(this.currentMove.moveData!);
this.currentPos.undoSimpleMove(this.currentMove.sm!);
this.CurrentPlyCount--;

@@ -596,0 +653,0 @@ this.positionChanged();

@@ -7,2 +7,3 @@ import * as shortid from 'shortid';

import { Squares, Colors, Pieces } from '../types/Types';
import { ITreePart, IMovePart } from '../types/Interfaces';

@@ -16,11 +17,2 @@ /**

private ply: number;
private from?: Squares.Square;
private to?: Squares.Square;
private color?: Colors.BW;
private capturedSquare?: Squares.Square;
private capturedPiece?: number;
private promote?: Pieces.PieceType;
private piece_num: number;
private permanent: boolean;
private legal_moves: SimpleMove[];
private parent: Move | null = null;

@@ -35,9 +27,11 @@

public uid: string;
public id: number = 0;
public moveData: SimpleMove | null;
public Name: string;
public WhoMove: Colors.BW;
public Comments: string;
public Fen: string | undefined;
public id: string = "0";
public name: string;
public whoMove: Colors.BW;
public comments: string;
public fen: string | undefined;
public sm: SimpleMove | null;
public data?: ITreePart | IMovePart;
/**

@@ -48,15 +42,7 @@ * @constructor

this.uid = shortid.generate();
this.Name = "";
this.moveData = null;
this.from = Square.NullSquare;
this.to = Square.NullSquare;
this.color = Color.None;
this.capturedSquare = Square.NullSquare;
this.capturedPiece = Piece.None;
this.promote = Piece.None;
this.piece_num = 0;
this.WhoMove = Color.White;
this.name = "";
this.sm = null;
this.whoMove = Color.White;
this.ply = 0;
this.Comments = "";
this.permanent = true;
this.comments = "";
this.START_MARKER = false;

@@ -66,3 +52,2 @@ this.END_MARKER = false;

this.next_move = null;
this.legal_moves = [];
}

@@ -72,4 +57,4 @@

const firstMove = new Move();
firstMove.Name = "FirstMove";
firstMove.Fen = fen;
firstMove.name = "FirstMove";
firstMove.fen = fen;
firstMove.ply = 0;

@@ -80,3 +65,3 @@ firstMove.START_MARKER = true;

firstMove.next_move = new Move();
firstMove.next_move.Name = "LastMove";
firstMove.next_move.name = "LastMove";
firstMove.next_move.ply = 0;

@@ -157,3 +142,3 @@ firstMove.next_move.START_MARKER = false;

if (prev) {
varRoot = Move.init(prev.Fen, prev);
varRoot = Move.init(prev.fen, prev);
prev.vars.push(varRoot);

@@ -199,5 +184,5 @@ }

newMove.varNo = this.varNo;
newMove.moveData = sm;
newMove.Name = sm.San ? sm.San : sm.PlyCount.toString();
newMove.ply = sm.PlyCount;
newMove.sm = sm;
newMove.name = sm.san ? sm.san : sm.plyCount.toString();
newMove.ply = sm.plyCount;

@@ -204,0 +189,0 @@ newMove.next_move = this;

@@ -13,24 +13,24 @@ import { Colors, Pieces, Squares } from '../types/Types';

export class SimpleMove {
public PieceNum: number = 0;
public MovingPiece?: Pieces.Piece = np;
public From?: Squares.Square = ns;
public To?: Squares.Square = ns;
public Color?: Colors.BW = Color.None;
public CapturedNum = 0;
public CapturedPiece?: Pieces.Piece = np;
public Promote?: Pieces.PieceType = np;
public CapturedSquare?: Squares.Square = ns; // only different to "to" field if this capture is an en passant capture.
public CastleFlags = 0;
public EpSquare?: Squares.Square = ns;
public OldHalfMoveClock = 0;
public pieceNum: number = 0;
public movingPiece?: Pieces.Piece = np;
public from?: Squares.Square = ns;
public to?: Squares.Square = ns;
public color?: Colors.BW = Color.None;
public capturedNum = 0;
public capturedPiece?: Pieces.Piece = np;
public promote?: Pieces.PieceType = np;
public capturedSquare?: Squares.Square = ns; // only different to "to" field if this capture is an en passant capture.
public castleFlags = 0;
public epSquare?: Squares.Square = ns;
public oldHalfMoveClock = 0;
public PlyCount = 0;
public San: string = "";
public Comments: string = "";
public Nag: string = "";
public Permanent: boolean = true;
public plyCount = 0;
public san?: string;
public comments?: string;
public nag?: string;
public permanent: boolean = true;
public toString(): string {
return this.San;
return this.san || "";
}
}

@@ -29,4 +29,4 @@ import { IUser } from 'onix-core/dist/app/IUser';

name: StatusName;
result: number;
result_name: string;
result?: number;
result_name?: string;
}

@@ -52,6 +52,6 @@

speed: 'correspondence' | 'classical' | SpeedNameType;
perf: PerfNameType;
rated: boolean;
perf?: PerfNameType;
rated?: boolean;
initialFen: string;
fen: string;
fen?: string;
player: Colors.Name;

@@ -61,11 +61,11 @@ turns: number;

status: IGameStatus;
event: string;
event?: string;
tournamentId?: number;
createdAt: number;
private: boolean;
advance: boolean;
createdAt?: number;
private?: boolean;
advance?: boolean;
winner?: Colors.Name;
lastMove?: string;
check?: string;
moveCentis: number[];
moveCentis?: number[];
opening?: IChessOpening;

@@ -184,7 +184,7 @@ }

export interface IGameData {
game: IChessGame;
game?: IChessGame;
tournament?: IChessTournament;
clock?: IBlitzClock;
correspondence?: ICorrespondenceClock | IAdvanceClock;
player: IChessPlayer;
player?: IChessPlayer;
opponent?: IChessPlayer;

@@ -191,0 +191,0 @@ orientation: Colors.Name;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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