onix-chess
Advanced tools
Comparing version 6.7.3 to 7.0.0
@@ -6,3 +6,3 @@ import { Squares, Colors } from '../types/Types'; | ||
import { SimpleMove } from './SimpleMove'; | ||
import { IGameData, IMovePart, ITreePart, IChessPlayer, IChessOpening } from '../types/Interfaces'; | ||
import { IGameData, IMovePart, ITreePart, IChessPlayer, IChessOpening, IGameAnalysis } from '../types/Interfaces'; | ||
export declare enum ChessRatingType { | ||
@@ -44,11 +44,5 @@ None = 0, | ||
private currentMove; | ||
private currentPos; | ||
private curPos; | ||
private startPos; | ||
private startFen; | ||
/** | ||
* Side to move in starting position | ||
*/ | ||
get ToMove(): Colors.BW; | ||
get CurrentPlyCount(): number; | ||
get StartPlyCount(): number; | ||
Altered: boolean; | ||
@@ -74,2 +68,5 @@ InPromotion: boolean; | ||
get RawData(): Readonly<IGameData>; | ||
get ToMove(): Colors.BW; | ||
get CurrentPlyCount(): number; | ||
get StartPlyCount(): number; | ||
get CurrentMove(): Move; | ||
@@ -79,2 +76,3 @@ get CurrentPos(): Position; | ||
get NonStandardStart(): boolean; | ||
anatysis: IGameAnalysis; | ||
/** | ||
@@ -81,0 +79,0 @@ * @constructor |
@@ -17,2 +17,3 @@ "use strict"; | ||
const Common_1 = require("./Common"); | ||
const EvalItem_1 = require("../analysis/EvalItem"); | ||
var ChessRatingType; | ||
@@ -160,2 +161,3 @@ (function (ChessRatingType) { | ||
this.Result = GameResult_1.GameResult.Color.None; | ||
this.anatysis = {}; | ||
this.data = data || defaultGameData; | ||
@@ -176,5 +178,5 @@ this.Tags = new ChessTags(this); | ||
} | ||
/** | ||
* Side to move in starting position | ||
*/ | ||
get RawData() { | ||
return this.data; | ||
} | ||
get ToMove() { | ||
@@ -189,5 +191,2 @@ return this.CurrentPos.WhoMove; | ||
} | ||
get RawData() { | ||
return this.data; | ||
} | ||
get CurrentMove() { | ||
@@ -197,3 +196,3 @@ return this.currentMove; | ||
get CurrentPos() { | ||
return this.currentPos; | ||
return this.curPos; | ||
} | ||
@@ -211,2 +210,3 @@ set StartFen(value) { | ||
this.NoQueenPromotion = false; | ||
this.anatysis = {}; | ||
this.clearStandardTags(); | ||
@@ -267,7 +267,8 @@ this.clearExtraTags(); | ||
// Set up start | ||
this.currentPos = new Position_1.Position(); | ||
this.currentPos.copyFrom(this.startPos); | ||
this.curPos = new Position_1.Position(); | ||
this.curPos.copyFrom(this.startPos); | ||
} | ||
init() { | ||
const { game, player, opponent, steps, treeParts } = this.data; | ||
var _a, _b, _c, _d, _e; | ||
const { game, player, opponent, analysis, steps, treeParts } = this.data; | ||
if (game) { | ||
@@ -285,2 +286,24 @@ this.GameId = game.id; | ||
this.assignPlayer(opponent); | ||
if (analysis) { | ||
this.anatysis.state = (_a = analysis.state) !== null && _a !== void 0 ? _a : "empty"; | ||
if ((this.anatysis.state == "inprogress") && (analysis.completed)) { | ||
this.anatysis.completed = analysis.completed; | ||
} | ||
if (analysis.white) { | ||
this.anatysis.white = { | ||
blunder: toSafeInteger_1.default(analysis.white.blunder), | ||
mistake: toSafeInteger_1.default(analysis.white.mistake), | ||
inaccuracy: toSafeInteger_1.default(analysis.white.inaccuracy), | ||
acpl: toSafeInteger_1.default(analysis.white.acpl) | ||
}; | ||
} | ||
if (analysis.black) { | ||
this.anatysis.black = { | ||
blunder: toSafeInteger_1.default(analysis.black.blunder), | ||
mistake: toSafeInteger_1.default(analysis.black.mistake), | ||
inaccuracy: toSafeInteger_1.default(analysis.black.inaccuracy), | ||
acpl: toSafeInteger_1.default(analysis.black.acpl) | ||
}; | ||
} | ||
} | ||
const moves = treeParts !== null && treeParts !== void 0 ? treeParts : steps; | ||
@@ -290,2 +313,32 @@ if (moves) { | ||
this.decodeMoves(moves); | ||
if (treeParts) { | ||
let move = this.CurrentMove.Begin; | ||
while (!move.END_MARKER) { | ||
if (!move.START_MARKER && ((_b = move.sm) === null || _b === void 0 ? void 0 : _b.eval) && ((_c = move.Prev.sm) === null || _c === void 0 ? void 0 : _c.eval)) { | ||
move.sm.eval.normalize(move.Prev.sm.eval); | ||
} | ||
move = move.Next; | ||
} | ||
; | ||
move = this.CurrentMove.Begin; | ||
while (!move.END_MARKER) { | ||
if (!move.isLast() && ((_d = move.sm) === null || _d === void 0 ? void 0 : _d.eval) && ((_e = move.Next.sm) === null || _e === void 0 ? void 0 : _e.eval)) { | ||
move.sm.eval.extend(move.Next.sm.eval); | ||
} | ||
move = move.Next; | ||
} | ||
; | ||
} | ||
if (game === null || game === void 0 ? void 0 : game.moveCentis) { | ||
const times = [].concat(game === null || game === void 0 ? void 0 : game.moveCentis); | ||
let move = this.CurrentMove.First; | ||
while (!move.END_MARKER && times.length) { | ||
const time = times.shift(); | ||
if (move.sm) { | ||
move.sm.time = toSafeInteger_1.default(time); | ||
} | ||
move = move.Next; | ||
} | ||
; | ||
} | ||
this.supressEvents = false; | ||
@@ -309,5 +362,13 @@ } | ||
if (mv.uci === undefined) { | ||
if (this.isInstanceOfTreePart(mv)) { | ||
const move = this.CurrentMove.First; | ||
if (move && move.sm) { | ||
move.sm.eval = new EvalItem_1.EvalItem(mv.eval); | ||
move.sm.judgments = mv.comments; | ||
move.sm.glyphs = mv.glyphs; | ||
} | ||
} | ||
return; | ||
} | ||
const sm = this.currentPos.readCoordMove(mv.uci); | ||
const sm = this.curPos.readCoordMove(mv.uci); | ||
if (sm !== null) { | ||
@@ -319,6 +380,3 @@ sm.ply = this.CurrentPos.PlyCount + 1; | ||
if (this.isInstanceOfTreePart(mv)) { | ||
if (mv.comments && (mv.comments.length > 0)) { | ||
sm.comments = mv.comments[0].comment; | ||
} | ||
sm.eval = mv.eval; | ||
sm.eval = new EvalItem_1.EvalItem(mv.eval); | ||
sm.judgments = mv.comments; | ||
@@ -342,3 +400,3 @@ sm.glyphs = mv.glyphs; | ||
if (!this.currentMove.fen) { | ||
this.currentMove.fen = FenString_1.FenString.fromPosition(this.currentPos); | ||
this.currentMove.fen = FenString_1.FenString.fromPosition(this.curPos); | ||
} | ||
@@ -350,5 +408,5 @@ this.Fen = this.currentMove.fen; | ||
const state = new ChessGameState(); | ||
const mlist = this.currentPos.generateMoves(Piece_1.Piece.None, Position_1.GenerateMode.All, true); | ||
const mlist = this.curPos.generateMoves(Piece_1.Piece.None, Position_1.GenerateMode.All, true); | ||
if (mlist.length === 0) { | ||
if (this.currentPos.isKingInCheck()) { | ||
if (this.curPos.isKingInCheck()) { | ||
state.InCheckMate = true; | ||
@@ -360,14 +418,14 @@ } | ||
} | ||
if ((!this.currentPos.hasPiece(Piece_1.Piece.WPawn)) && | ||
(!this.currentPos.hasPiece(Piece_1.Piece.WQueen)) && | ||
(!this.currentPos.hasPiece(Piece_1.Piece.WRook))) { | ||
if ((!this.currentPos.hasPiece(Piece_1.Piece.WKnight)) && (!this.currentPos.hasPiece(Piece_1.Piece.WBishop))) { | ||
if ((!this.curPos.hasPiece(Piece_1.Piece.WPawn)) && | ||
(!this.curPos.hasPiece(Piece_1.Piece.WQueen)) && | ||
(!this.curPos.hasPiece(Piece_1.Piece.WRook))) { | ||
if ((!this.curPos.hasPiece(Piece_1.Piece.WKnight)) && (!this.curPos.hasPiece(Piece_1.Piece.WBishop))) { | ||
// King only | ||
state.IsNoMaterialWhite = true; | ||
} | ||
else if ((!this.currentPos.hasPiece(Piece_1.Piece.WKnight)) && (this.currentPos.getPieceCount(Piece_1.Piece.WBishop) === 1)) { | ||
else if ((!this.curPos.hasPiece(Piece_1.Piece.WKnight)) && (this.curPos.getPieceCount(Piece_1.Piece.WBishop) === 1)) { | ||
// King and bishop | ||
state.IsNoMaterialWhite = true; | ||
} | ||
else if ((this.currentPos.getPieceCount(Piece_1.Piece.WKnight) === 1) && (!this.currentPos.hasPiece(Piece_1.Piece.WBishop))) { | ||
else if ((this.curPos.getPieceCount(Piece_1.Piece.WKnight) === 1) && (!this.curPos.hasPiece(Piece_1.Piece.WBishop))) { | ||
// King and knight | ||
@@ -377,14 +435,14 @@ state.IsNoMaterialWhite = true; | ||
} | ||
if ((!this.currentPos.hasPiece(Piece_1.Piece.BPawn)) && | ||
(!this.currentPos.hasPiece(Piece_1.Piece.BQueen)) && | ||
(!this.currentPos.hasPiece(Piece_1.Piece.BRook))) { | ||
if ((!this.currentPos.hasPiece(Piece_1.Piece.BKnight)) && (!this.currentPos.hasPiece(Piece_1.Piece.BBishop))) { | ||
if ((!this.curPos.hasPiece(Piece_1.Piece.BPawn)) && | ||
(!this.curPos.hasPiece(Piece_1.Piece.BQueen)) && | ||
(!this.curPos.hasPiece(Piece_1.Piece.BRook))) { | ||
if ((!this.curPos.hasPiece(Piece_1.Piece.BKnight)) && (!this.curPos.hasPiece(Piece_1.Piece.BBishop))) { | ||
// King only | ||
state.IsNoMaterialBlack = true; | ||
} | ||
else if ((!this.currentPos.hasPiece(Piece_1.Piece.BKnight)) && (this.currentPos.getPieceCount(Piece_1.Piece.BBishop) === 1)) { | ||
else if ((!this.curPos.hasPiece(Piece_1.Piece.BKnight)) && (this.curPos.getPieceCount(Piece_1.Piece.BBishop) === 1)) { | ||
// King and bishop | ||
state.IsNoMaterialBlack = true; | ||
} | ||
else if ((this.currentPos.getPieceCount(Piece_1.Piece.BKnight) === 1) && (!this.currentPos.hasPiece(Piece_1.Piece.BBishop))) { | ||
else if ((this.curPos.getPieceCount(Piece_1.Piece.BKnight) === 1) && (!this.curPos.hasPiece(Piece_1.Piece.BBishop))) { | ||
// King and knight | ||
@@ -403,7 +461,7 @@ state.IsNoMaterialBlack = true; | ||
state.IsPosRepeation = rc >= 3; | ||
state.Is50MovesRule = this.currentPos.HalfMoveCount > 100; | ||
state.Is50MovesRule = this.curPos.HalfMoveCount > 100; | ||
return state; | ||
} | ||
makeMove(fr, to, promote) { | ||
const { currentPos } = this; | ||
const { curPos: currentPos } = this; | ||
const sm = new SimpleMove_1.SimpleMove(); | ||
@@ -440,3 +498,3 @@ sm.pieceNum = currentPos.getPieceNum(fr); | ||
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.capturedSquare = (this.curPos.WhoMove === Color_1.Color.White ? (to - 8) : (to + 8)); | ||
sm.capturedPiece = enemyPawn; | ||
@@ -452,3 +510,3 @@ } | ||
addMove(sm, san, fen) { | ||
const { currentPos } = this; | ||
const { curPos: currentPos } = this; | ||
// We must be at the end of a game/variation to add a move: | ||
@@ -461,3 +519,3 @@ if (!this.currentMove.END_MARKER) { | ||
if (!san || (san == undefined)) { | ||
sm.san = this.currentPos.makeSanString(sm, Position_1.SanCheckLevel.MateTest); | ||
sm.san = this.curPos.makeSanString(sm, Position_1.SanCheckLevel.MateTest); | ||
} | ||
@@ -469,3 +527,3 @@ else { | ||
const newMove = this.currentMove.append(sm); | ||
this.currentPos.doSimpleMove(sm); | ||
this.curPos.doSimpleMove(sm); | ||
if (!fen) { | ||
@@ -490,6 +548,6 @@ fen = FenString_1.FenString.fromPosition(currentPos); | ||
if (!this.currentMove.isBegin()) { | ||
this.currentPos = new Position_1.Position(this.currentMove.Prev.fen); | ||
this.curPos = new Position_1.Position(this.currentMove.Prev.fen); | ||
} | ||
else { | ||
this.currentPos.copyFrom(this.startPos); | ||
this.curPos.copyFrom(this.startPos); | ||
} | ||
@@ -506,3 +564,3 @@ this.supressEvents = false; | ||
this.currentMove = this.CurrentMove.Begin; | ||
this.currentPos.copyFrom(this.startPos); | ||
this.curPos.copyFrom(this.startPos); | ||
// this.currentPos = new Position(this.currentMove.fen); | ||
@@ -540,3 +598,3 @@ } | ||
if (!this.currentMove.END_MARKER) { | ||
this.currentPos.doSimpleMove(this.currentMove.sm); | ||
this.curPos.doSimpleMove(this.currentMove.sm); | ||
} | ||
@@ -556,3 +614,3 @@ this.positionChanged(); | ||
if (this.currentMove.inVariation()) { | ||
this.currentPos.undoSimpleMove(this.currentMove.sm); | ||
this.curPos.undoSimpleMove(this.currentMove.sm); | ||
this.currentMove = this.currentMove.exitVariation(); | ||
@@ -562,6 +620,6 @@ this.positionChanged(); | ||
} | ||
this.currentPos.copyFrom(this.startPos); | ||
this.curPos.copyFrom(this.startPos); | ||
} | ||
else if (!this.currentMove.END_MARKER) { | ||
this.currentPos.undoSimpleMove(this.currentMove.sm); | ||
this.curPos.undoSimpleMove(this.currentMove.sm); | ||
} | ||
@@ -568,0 +626,0 @@ this.currentMove = this.currentMove.Prev; |
@@ -6,2 +6,3 @@ "use strict"; | ||
const Color_1 = require("./Color"); | ||
const SimpleMove_1 = require("./SimpleMove"); | ||
const Position_1 = require("./Position"); | ||
@@ -37,2 +38,3 @@ /** | ||
firstMove.ply = 0; | ||
firstMove.sm = new SimpleMove_1.SimpleMove(); | ||
firstMove.START_MARKER = true; | ||
@@ -43,2 +45,3 @@ firstMove.END_MARKER = false; | ||
firstMove.next_move.ply = 0; | ||
firstMove.next_move.sm = new SimpleMove_1.SimpleMove(); | ||
firstMove.next_move.START_MARKER = false; | ||
@@ -45,0 +48,0 @@ firstMove.next_move.END_MARKER = true; |
@@ -1,3 +0,4 @@ | ||
import { IEval, IGlyph, IJudgment } from '../types/Interfaces'; | ||
import { IGlyph, IJudgment } from '../types/Interfaces'; | ||
import { Colors, Pieces, Squares } from '../types/Types'; | ||
import { EvalItem } from '../analysis/EvalItem'; | ||
/** | ||
@@ -21,4 +22,5 @@ * Move data. | ||
san?: string; | ||
time: number; | ||
comments?: string; | ||
eval?: IEval; | ||
eval?: EvalItem; | ||
judgments?: IJudgment[]; | ||
@@ -25,0 +27,0 @@ glyphs?: IGlyph[]; |
@@ -27,2 +27,3 @@ "use strict"; | ||
this.ply = 0; | ||
this.time = 0; | ||
this.permanent = true; | ||
@@ -29,0 +30,0 @@ } |
@@ -18,4 +18,5 @@ { | ||
"nextMove": "Next move", | ||
"lastMove": "Last move" | ||
"lastMove": "Last move", | ||
"mateIn": "Mate in #%d" | ||
} | ||
} |
@@ -18,4 +18,5 @@ { | ||
"nextMove": "Próximo movimiento", | ||
"lastMove": "Último movimiento" | ||
"lastMove": "Último movimiento", | ||
"mateIn": "Mate está a #%d" | ||
} | ||
} |
@@ -18,4 +18,5 @@ { | ||
"nextMove": "Следующий ход", | ||
"lastMove": "Последний ход" | ||
"lastMove": "Последний ход", | ||
"mateIn": "Мат через %d" | ||
} | ||
} |
@@ -29,2 +29,3 @@ import { IUser } from 'onix-core/dist/app/IUser'; | ||
}; | ||
export declare type AnalyseStatus = "empty" | "unanalysed" | "inprogress" | "ready"; | ||
export interface IChessOpening { | ||
@@ -133,3 +134,3 @@ code: string; | ||
export interface IGameAnalysis { | ||
state?: string; | ||
state?: AnalyseStatus; | ||
completed?: number; | ||
@@ -136,0 +137,0 @@ by?: string; |
{ | ||
"name": "onix-chess", | ||
"version": "6.7.3", | ||
"version": "7.0.0", | ||
"description": "Onix chess library", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -6,3 +6,2 @@ import toSafeInteger from 'lodash-es/toSafeInteger'; | ||
import { Hashtable } from 'onix-core'; | ||
import { Squares, Colors } from '../types/Types'; | ||
@@ -16,5 +15,7 @@ import { Color } from './Color'; | ||
import { SimpleMove } from './SimpleMove'; | ||
import { IGameData, IMovePart, ITreePart, IChessPlayer, IChessOpening } from '../types/Interfaces'; | ||
import { IGameData, IMovePart, ITreePart, IChessPlayer, IChessOpening, IGameAnalysis } from '../types/Interfaces'; | ||
import { FenString } from './FenString'; | ||
import { plyToColor, plyToTurn, turnToPly } from './Common'; | ||
import { EvalItem } from '../analysis/EvalItem'; | ||
import { setMaxListeners } from 'process'; | ||
@@ -161,22 +162,8 @@ export enum ChessRatingType { | ||
private moveList: { [index: string]: Move } = {}; | ||
private currentMove!: Move; | ||
private currentPos!: Position; | ||
private curPos!: Position; | ||
private startPos: Position; | ||
private startFen: string = FenString.standartStart; | ||
/** | ||
* Side to move in starting position | ||
*/ | ||
public get ToMove() { | ||
return this.CurrentPos.WhoMove; | ||
} | ||
public get CurrentPlyCount() { | ||
return this.CurrentMove.PlyCount; | ||
} | ||
public get StartPlyCount() { | ||
return (this.startPos) ? this.startPos.PlyCount + 1 : 1; | ||
} | ||
public Altered: boolean; | ||
@@ -212,2 +199,14 @@ public InPromotion: boolean = false; | ||
public get ToMove() { | ||
return this.CurrentPos.WhoMove; | ||
} | ||
public get CurrentPlyCount() { | ||
return this.CurrentMove.PlyCount; | ||
} | ||
public get StartPlyCount() { | ||
return (this.startPos) ? this.startPos.PlyCount + 1 : 1; | ||
} | ||
public get CurrentMove(): Move { | ||
@@ -218,3 +217,3 @@ return this.currentMove; | ||
public get CurrentPos(): Position { | ||
return this.currentPos; | ||
return this.curPos; | ||
} | ||
@@ -230,2 +229,4 @@ | ||
public anatysis: IGameAnalysis = {}; | ||
/** | ||
@@ -262,2 +263,4 @@ * @constructor | ||
this.anatysis = {}; | ||
this.clearStandardTags(); | ||
@@ -326,8 +329,8 @@ this.clearExtraTags(); | ||
// Set up start | ||
this.currentPos = new Position(); | ||
this.currentPos.copyFrom(this.startPos); | ||
this.curPos = new Position(); | ||
this.curPos.copyFrom(this.startPos); | ||
} | ||
public init() { | ||
const { game, player, opponent, steps, treeParts } = this.data; | ||
const { game, player, opponent, analysis, steps, treeParts } = this.data; | ||
if (game) { | ||
@@ -349,2 +352,27 @@ this.GameId = game.id; | ||
if (analysis) { | ||
this.anatysis.state = analysis.state ?? "empty"; | ||
if ((this.anatysis.state == "inprogress") && (analysis.completed)) { | ||
this.anatysis.completed = analysis.completed; | ||
} | ||
if (analysis.white) { | ||
this.anatysis.white = { | ||
blunder: toSafeInteger(analysis.white.blunder), | ||
mistake: toSafeInteger(analysis.white.mistake), | ||
inaccuracy: toSafeInteger(analysis.white.inaccuracy), | ||
acpl: toSafeInteger(analysis.white.acpl) | ||
} | ||
} | ||
if (analysis.black) { | ||
this.anatysis.black = { | ||
blunder: toSafeInteger(analysis.black.blunder), | ||
mistake: toSafeInteger(analysis.black.mistake), | ||
inaccuracy: toSafeInteger(analysis.black.inaccuracy), | ||
acpl: toSafeInteger(analysis.black.acpl) | ||
} | ||
} | ||
} | ||
const moves = treeParts ?? steps; | ||
@@ -354,2 +382,35 @@ if (moves) { | ||
this.decodeMoves(moves); | ||
if (treeParts) { | ||
let move = this.CurrentMove.Begin; | ||
while (!move.END_MARKER) { | ||
if (!move.START_MARKER && move.sm?.eval && move.Prev.sm?.eval) { | ||
move.sm.eval.normalize(move.Prev.sm!.eval!) | ||
} | ||
move = move.Next; | ||
}; | ||
move = this.CurrentMove.Begin; | ||
while (!move.END_MARKER) { | ||
if (!move.isLast() && move.sm?.eval && move.Next.sm?.eval) { | ||
move.sm!.eval!.extend(move.Next.sm!.eval!) | ||
} | ||
move = move.Next; | ||
}; | ||
} | ||
if (game?.moveCentis) { | ||
const times = (<number[]>[]).concat(game?.moveCentis); | ||
let move = this.CurrentMove.First; | ||
while (!move.END_MARKER && times.length) { | ||
const time = times.shift(); | ||
if (move.sm) { | ||
move.sm.time = toSafeInteger(time); | ||
} | ||
move = move.Next; | ||
}; | ||
} | ||
this.supressEvents = false; | ||
@@ -375,6 +436,14 @@ } | ||
if (mv.uci === undefined) { | ||
if (this.isInstanceOfTreePart(mv)) { | ||
const move = this.CurrentMove.First; | ||
if (move && move.sm) { | ||
move.sm.eval = new EvalItem(mv.eval); | ||
move.sm.judgments = mv.comments; | ||
move.sm.glyphs = mv.glyphs; | ||
} | ||
} | ||
return; | ||
} | ||
const sm = this.currentPos.readCoordMove(mv.uci); | ||
const sm = this.curPos.readCoordMove(mv.uci); | ||
if (sm !== null) { | ||
@@ -386,7 +455,3 @@ sm.ply = this.CurrentPos.PlyCount + 1; | ||
if (this.isInstanceOfTreePart(mv)) { | ||
if (mv.comments && (mv.comments.length > 0)) { | ||
sm.comments = mv.comments[0].comment; | ||
} | ||
sm.eval = mv.eval; | ||
sm.eval = new EvalItem(mv.eval); | ||
sm.judgments = mv.comments; | ||
@@ -414,3 +479,3 @@ sm.glyphs = mv.glyphs; | ||
if (!this.currentMove.fen) { | ||
this.currentMove.fen = FenString.fromPosition(this.currentPos); | ||
this.currentMove.fen = FenString.fromPosition(this.curPos); | ||
} | ||
@@ -425,6 +490,6 @@ | ||
const mlist = this.currentPos.generateMoves(Piece.None, GenerateMode.All, true); | ||
const mlist = this.curPos.generateMoves(Piece.None, GenerateMode.All, true); | ||
if (mlist.length === 0) { | ||
if (this.currentPos.isKingInCheck()) { | ||
if (this.curPos.isKingInCheck()) { | ||
state.InCheckMate = true; | ||
@@ -436,12 +501,12 @@ } else { | ||
if ((!this.currentPos.hasPiece(Piece.WPawn)) && | ||
(!this.currentPos.hasPiece(Piece.WQueen)) && | ||
(!this.currentPos.hasPiece(Piece.WRook))) { | ||
if ((!this.currentPos.hasPiece(Piece.WKnight)) && (!this.currentPos.hasPiece(Piece.WBishop))) { | ||
if ((!this.curPos.hasPiece(Piece.WPawn)) && | ||
(!this.curPos.hasPiece(Piece.WQueen)) && | ||
(!this.curPos.hasPiece(Piece.WRook))) { | ||
if ((!this.curPos.hasPiece(Piece.WKnight)) && (!this.curPos.hasPiece(Piece.WBishop))) { | ||
// King only | ||
state.IsNoMaterialWhite = true; | ||
} else if ((!this.currentPos.hasPiece(Piece.WKnight)) && (this.currentPos.getPieceCount(Piece.WBishop) === 1)) { | ||
} else if ((!this.curPos.hasPiece(Piece.WKnight)) && (this.curPos.getPieceCount(Piece.WBishop) === 1)) { | ||
// King and bishop | ||
state.IsNoMaterialWhite = true; | ||
} else if ((this.currentPos.getPieceCount(Piece.WKnight) === 1) && (!this.currentPos.hasPiece(Piece.WBishop))) { | ||
} else if ((this.curPos.getPieceCount(Piece.WKnight) === 1) && (!this.curPos.hasPiece(Piece.WBishop))) { | ||
// King and knight | ||
@@ -452,12 +517,12 @@ state.IsNoMaterialWhite = true; | ||
if ((!this.currentPos.hasPiece(Piece.BPawn)) && | ||
(!this.currentPos.hasPiece(Piece.BQueen)) && | ||
(!this.currentPos.hasPiece(Piece.BRook))) { | ||
if ((!this.currentPos.hasPiece(Piece.BKnight)) && (!this.currentPos.hasPiece(Piece.BBishop))) { | ||
if ((!this.curPos.hasPiece(Piece.BPawn)) && | ||
(!this.curPos.hasPiece(Piece.BQueen)) && | ||
(!this.curPos.hasPiece(Piece.BRook))) { | ||
if ((!this.curPos.hasPiece(Piece.BKnight)) && (!this.curPos.hasPiece(Piece.BBishop))) { | ||
// King only | ||
state.IsNoMaterialBlack = true; | ||
} else if ((!this.currentPos.hasPiece(Piece.BKnight)) && (this.currentPos.getPieceCount(Piece.BBishop) === 1)) { | ||
} else if ((!this.curPos.hasPiece(Piece.BKnight)) && (this.curPos.getPieceCount(Piece.BBishop) === 1)) { | ||
// King and bishop | ||
state.IsNoMaterialBlack = true; | ||
} else if ((this.currentPos.getPieceCount(Piece.BKnight) === 1) && (!this.currentPos.hasPiece(Piece.BBishop))) { | ||
} else if ((this.curPos.getPieceCount(Piece.BKnight) === 1) && (!this.curPos.hasPiece(Piece.BBishop))) { | ||
// King and knight | ||
@@ -478,3 +543,3 @@ state.IsNoMaterialBlack = true; | ||
state.IsPosRepeation = rc >= 3; | ||
state.Is50MovesRule = this.currentPos.HalfMoveCount > 100; | ||
state.Is50MovesRule = this.curPos.HalfMoveCount > 100; | ||
@@ -485,3 +550,3 @@ return state; | ||
public makeMove(fr: Squares.Square, to: Squares.Square, promote?: string) { | ||
const { currentPos } = this; | ||
const { curPos: currentPos } = this; | ||
const sm = new SimpleMove(); | ||
@@ -521,3 +586,3 @@ sm.pieceNum = currentPos.getPieceNum(fr); | ||
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.capturedSquare = (this.curPos.WhoMove === Color.White ? (to - 8) as Squares.Square : (to + 8) as Squares.Square); | ||
sm.capturedPiece = enemyPawn; | ||
@@ -535,3 +600,3 @@ } | ||
public addMove(sm: SimpleMove, san?: string, fen?: string) { | ||
const { currentPos } = this; | ||
const { curPos: currentPos } = this; | ||
@@ -546,3 +611,3 @@ // We must be at the end of a game/variation to add a move: | ||
if (!san || (san == undefined)) { | ||
sm.san = this.currentPos.makeSanString(sm, SanCheckLevel.MateTest); | ||
sm.san = this.curPos.makeSanString(sm, SanCheckLevel.MateTest); | ||
} else { | ||
@@ -555,3 +620,3 @@ sm.san = san; | ||
this.currentPos.doSimpleMove(sm); | ||
this.curPos.doSimpleMove(sm); | ||
if (!fen) { | ||
@@ -579,5 +644,5 @@ fen = FenString.fromPosition(currentPos); | ||
if (!this.currentMove.isBegin()) { | ||
this.currentPos = new Position(this.currentMove.Prev.fen); | ||
this.curPos = new Position(this.currentMove.Prev.fen); | ||
} else { | ||
this.currentPos.copyFrom(this.startPos); | ||
this.curPos.copyFrom(this.startPos); | ||
} | ||
@@ -596,3 +661,3 @@ | ||
this.currentMove = this.CurrentMove.Begin; | ||
this.currentPos.copyFrom(this.startPos); | ||
this.curPos.copyFrom(this.startPos); | ||
// this.currentPos = new Position(this.currentMove.fen); | ||
@@ -635,3 +700,3 @@ } | ||
if (!this.currentMove.END_MARKER) { | ||
this.currentPos.doSimpleMove(this.currentMove.sm!); | ||
this.curPos.doSimpleMove(this.currentMove.sm!); | ||
} | ||
@@ -655,3 +720,3 @@ | ||
if (this.currentMove.inVariation()) { | ||
this.currentPos.undoSimpleMove(this.currentMove.sm!); | ||
this.curPos.undoSimpleMove(this.currentMove.sm!); | ||
this.currentMove = this.currentMove.exitVariation(); | ||
@@ -662,5 +727,5 @@ this.positionChanged(); | ||
this.currentPos.copyFrom(this.startPos); | ||
this.curPos.copyFrom(this.startPos); | ||
} else if (!this.currentMove.END_MARKER) { | ||
this.currentPos.undoSimpleMove(this.currentMove.sm!); | ||
this.curPos.undoSimpleMove(this.currentMove.sm!); | ||
} | ||
@@ -667,0 +732,0 @@ |
@@ -58,2 +58,3 @@ import * as shortid from 'shortid'; | ||
firstMove.ply = 0; | ||
firstMove.sm = new SimpleMove(); | ||
firstMove.START_MARKER = true; | ||
@@ -65,2 +66,3 @@ firstMove.END_MARKER = false; | ||
firstMove.next_move.ply = 0; | ||
firstMove.next_move.sm = new SimpleMove(); | ||
firstMove.next_move.START_MARKER = false; | ||
@@ -67,0 +69,0 @@ firstMove.next_move.END_MARKER = true; |
import { IEval, IGlyph, IJudgment } from '../types/Interfaces'; | ||
import { Colors, Pieces, Squares } from '../types/Types'; | ||
import { EvalItem } from '../analysis/EvalItem' | ||
import { Color } from './Color'; | ||
@@ -29,4 +30,5 @@ import { Piece } from './Piece'; | ||
public san?: string; | ||
public time: number = 0; | ||
public comments?: string; | ||
public eval?: IEval; | ||
public eval?: EvalItem; | ||
public judgments?: IJudgment[]; | ||
@@ -33,0 +35,0 @@ public glyphs?: IGlyph[]; |
@@ -18,4 +18,5 @@ { | ||
"nextMove": "Next move", | ||
"lastMove": "Last move" | ||
"lastMove": "Last move", | ||
"mateIn": "Mate in #%d" | ||
} | ||
} |
@@ -18,4 +18,5 @@ { | ||
"nextMove": "Próximo movimiento", | ||
"lastMove": "Último movimiento" | ||
"lastMove": "Último movimiento", | ||
"mateIn": "Mate está a #%d" | ||
} | ||
} |
@@ -18,4 +18,5 @@ { | ||
"nextMove": "Следующий ход", | ||
"lastMove": "Последний ход" | ||
"lastMove": "Последний ход", | ||
"mateIn": "Мат через %d" | ||
} | ||
} |
@@ -42,2 +42,4 @@ import { IUser } from 'onix-core/dist/app/IUser'; | ||
export type AnalyseStatus = "empty" | "unanalysed" | "inprogress" | "ready"; | ||
export interface IChessOpening { | ||
@@ -49,3 +51,2 @@ code: string; | ||
export interface IChessGame { | ||
@@ -171,3 +172,3 @@ id: number | string; | ||
export interface IGameAnalysis { | ||
state?: string; | ||
state?: AnalyseStatus; | ||
completed?: number; | ||
@@ -174,0 +175,0 @@ by?: string; |
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 not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
506000
94
9690