onix-chess
Advanced tools
Comparing version 2.0.2 to 2.1.0
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=IChessUser.js.map |
@@ -0,20 +1,19 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Castle side | ||
*/ | ||
var Castle = /** @class */ (function () { | ||
function Castle() { | ||
} | ||
// Queen side. Long castling. | ||
Castle.QSide = 0; | ||
Castle.Q = 'O-O-O'; | ||
// King side. Short castling. | ||
Castle.KSide = 1; | ||
Castle.K = 'O-O'; | ||
Castle.WQCastle = 1; | ||
Castle.WKCastle = 2; | ||
Castle.BQCastle = 4; | ||
Castle.BKCastle = 8; | ||
return Castle; | ||
}()); | ||
export { Castle }; | ||
class Castle { | ||
} | ||
exports.Castle = Castle; | ||
// Queen side. Long castling. | ||
Castle.QSide = 0; | ||
Castle.Q = 'O-O-O'; | ||
// King side. Short castling. | ||
Castle.KSide = 1; | ||
Castle.K = 'O-O'; | ||
Castle.WQCastle = 1; | ||
Castle.WKCastle = 2; | ||
Castle.BQCastle = 4; | ||
Castle.BKCastle = 8; | ||
//# sourceMappingURL=Castle.js.map |
@@ -1,12 +0,14 @@ | ||
import toSafeInteger from 'lodash-es/toSafeInteger'; | ||
import isNumber from 'lodash-es/isNumber'; | ||
import indexOf from 'lodash-es/indexOf'; | ||
import { Color } from './Color'; | ||
import { Piece } from './Piece'; | ||
import { Square } from './Square'; | ||
import { Position, ChessPositionStd, SanCheckLevel, GenerateMode } from './Position'; | ||
import { Move } from './Move'; | ||
import { SimpleMove } from './SimpleMove'; | ||
import { FenString } from './FenString'; | ||
export var ChessRatingType; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const toSafeInteger_1 = require("lodash-es/toSafeInteger"); | ||
const isNumber_1 = require("lodash-es/isNumber"); | ||
const indexOf_1 = require("lodash-es/indexOf"); | ||
const Color_1 = require("./Color"); | ||
const Piece_1 = require("./Piece"); | ||
const Square_1 = require("./Square"); | ||
const Position_1 = require("./Position"); | ||
const Move_1 = require("./Move"); | ||
const SimpleMove_1 = require("./SimpleMove"); | ||
const FenString_1 = require("./FenString"); | ||
var ChessRatingType; | ||
(function (ChessRatingType) { | ||
@@ -18,11 +20,11 @@ ChessRatingType[ChessRatingType["None"] = 0] = "None"; | ||
ChessRatingType[ChessRatingType["Iccf"] = 4] = "Iccf"; | ||
})(ChessRatingType || (ChessRatingType = {})); | ||
var ChessRatingNames = ["Unknown", "Elo", "Rating", "Rapid", "ICCF"]; | ||
})(ChessRatingType = exports.ChessRatingType || (exports.ChessRatingType = {})); | ||
const ChessRatingNames = ["Unknown", "Elo", "Rating", "Rapid", "ICCF"]; | ||
function chessRatingParseType(value) { | ||
return (isNumber(value)) ? value : toSafeInteger(value); | ||
return (isNumber_1.default(value)) ? value : toSafeInteger_1.default(value); | ||
} | ||
function chessRatingParseValue(value) { | ||
return (isNumber(value)) ? value : toSafeInteger(value); | ||
return (isNumber_1.default(value)) ? value : toSafeInteger_1.default(value); | ||
} | ||
var stdTags = [ | ||
const stdTags = [ | ||
"gameid", | ||
@@ -43,3 +45,3 @@ "gtype_id", | ||
]; | ||
var addTags = [ | ||
const addTags = [ | ||
"whiteratingtype", | ||
@@ -53,18 +55,18 @@ "whiterating", | ||
]; | ||
var ChessTags = /** @class */ (function () { | ||
class ChessTags { | ||
/** | ||
* constructor | ||
*/ | ||
function ChessTags(owner) { | ||
constructor(owner) { | ||
this.owner = owner; | ||
this.tags = {}; | ||
} | ||
ChessTags.prototype.clear = function () { | ||
clear() { | ||
this.tags = {}; | ||
}; | ||
ChessTags.prototype.add = function (name, value) { | ||
} | ||
add(name, value) { | ||
if (name) { | ||
name = name.toLowerCase(); | ||
if (indexOf(stdTags, name) === -1) { | ||
if (indexOf(addTags, name) !== -1) { | ||
if (indexOf_1.default(stdTags, name) === -1) { | ||
if (indexOf_1.default(addTags, name) !== -1) { | ||
switch (name) { | ||
@@ -98,7 +100,6 @@ case "whiteratingtype": | ||
} | ||
}; | ||
return ChessTags; | ||
}()); | ||
export { ChessTags }; | ||
export var ChessResultColor; | ||
} | ||
} | ||
exports.ChessTags = ChessTags; | ||
var ChessResultColor; | ||
(function (ChessResultColor) { | ||
@@ -109,3 +110,3 @@ ChessResultColor[ChessResultColor["None"] = 0] = "None"; | ||
ChessResultColor[ChessResultColor["Draw"] = 3] = "Draw"; | ||
})(ChessResultColor || (ChessResultColor = {})); | ||
})(ChessResultColor = exports.ChessResultColor || (exports.ChessResultColor = {})); | ||
var ChessResultType; | ||
@@ -130,22 +131,19 @@ (function (ChessResultType) { | ||
]; | ||
var score = [0, 1, 0, 0.5]; | ||
var resultChar = ["*", "1", "0", "="]; | ||
var resultShortString = ["*", "1-0", "0-1", "=-="]; | ||
var resultLongStr = ["*", "1-0", "0-1", "1/2-1/2"]; | ||
var resultHtmlStr = ["*", "1–0", "0–1", "½–½"]; | ||
var ChessGameState = /** @class */ (function () { | ||
function ChessGameState() { | ||
} | ||
return ChessGameState; | ||
}()); | ||
export { ChessGameState }; | ||
var Chess = /** @class */ (function () { | ||
const score = [0, 1, 0, 0.5]; | ||
const resultChar = ["*", "1", "0", "="]; | ||
const resultShortString = ["*", "1-0", "0-1", "=-="]; | ||
const resultLongStr = ["*", "1-0", "0-1", "1/2-1/2"]; | ||
const resultHtmlStr = ["*", "1–0", "0–1", "½–½"]; | ||
class ChessGameState { | ||
} | ||
exports.ChessGameState = ChessGameState; | ||
class Chess { | ||
/** | ||
* @constructor | ||
*/ | ||
function Chess(settings) { | ||
constructor(settings) { | ||
this.varDepth = 0; | ||
this.supressEvents = false; | ||
this.moveList = {}; | ||
this.startFen = FenString.fenStandartStart; | ||
this.startFen = FenString_1.FenString.fenStandartStart; | ||
this.settings = settings || {}; | ||
@@ -155,8 +153,8 @@ this.Tags = new ChessTags(this); | ||
this.pgnLastMovePos = this.pgnNextMovePos = 0; | ||
if (this.settings.fen && (this.settings.fen != FenString.fenStandartStart)) { | ||
if (this.settings.fen && (this.settings.fen != FenString_1.FenString.fenStandartStart)) { | ||
this.startFen = this.settings.fen; | ||
this.startPos = new Position(this.settings.fen); | ||
this.startPos = new Position_1.Position(this.settings.fen); | ||
} | ||
else { | ||
this.startPos = ChessPositionStd; | ||
this.startPos = Position_1.ChessPositionStd; | ||
} | ||
@@ -167,31 +165,15 @@ this.clear(); | ||
} | ||
Object.defineProperty(Chess.prototype, "CurrentMove", { | ||
get: function () { | ||
return this.currentMove; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Chess.prototype, "CurrentPos", { | ||
get: function () { | ||
return this.currentPos; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Chess.prototype, "StartFen", { | ||
set: function (value) { | ||
this.startFen = value; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Chess.prototype, "NonStandardStart", { | ||
get: function () { | ||
return this.startFen !== FenString.fenStandartStart; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Chess.prototype.clear = function () { | ||
get CurrentMove() { | ||
return this.currentMove; | ||
} | ||
get CurrentPos() { | ||
return this.currentPos; | ||
} | ||
set StartFen(value) { | ||
this.startFen = value; | ||
} | ||
get NonStandardStart() { | ||
return this.startFen !== FenString_1.FenString.fenStandartStart; | ||
} | ||
clear() { | ||
this.GameId = 0; | ||
@@ -204,7 +186,7 @@ // CommentsFlag = NagsFlag = VarsFlag = 0; | ||
this.clearMoves(); | ||
}; | ||
} | ||
/// <summary> | ||
/// Clears all of the standard tags. | ||
/// </summary> | ||
Chess.prototype.clearStandardTags = function () { | ||
clearStandardTags() { | ||
this.White = { userId: 0, name: "?" }; | ||
@@ -221,13 +203,13 @@ this.Black = { userId: 0, name: "?" }; | ||
this.WhiteRatingType = this.BlackRatingType = ChessRatingType.Elo; | ||
}; | ||
} | ||
/// <summary> | ||
/// clear any nonstandard tags. | ||
/// </summary> | ||
Chess.prototype.clearExtraTags = function () { | ||
clearExtraTags() { | ||
this.Tags.clear(); | ||
}; | ||
} | ||
/// <summary> | ||
/// clear all moves. | ||
/// </summary> | ||
Chess.prototype.clearMoves = function () { | ||
clearMoves() { | ||
this.moveList = {}; | ||
@@ -241,8 +223,8 @@ this.NumHalfMoves = 0; | ||
this.savedPos = null; | ||
this.currentMove = Move.init(this.startFen); | ||
this.currentMove = Move_1.Move.init(this.startFen); | ||
// Set up start | ||
this.currentPos = new Position(); | ||
this.currentPos = new Position_1.Position(); | ||
this.currentPos.copyFrom(this.startPos); | ||
this.StartPlyCount = this.currentPos.PlyCount; | ||
var moves = this.settings.moves; | ||
const { moves } = this.settings; | ||
if (moves) { | ||
@@ -254,5 +236,5 @@ this.supressEvents = true; | ||
this.ToMove = this.currentPos.WhoMove; | ||
}; | ||
Chess.prototype.decodeMoves = function (moves) { | ||
for (var i = 0; i < moves.length; i++) { | ||
} | ||
decodeMoves(moves) { | ||
for (let i = 0; i < moves.length; i++) { | ||
// 0 - from/to/color | ||
@@ -266,3 +248,3 @@ // 1 - san | ||
var mv = moves[i]; | ||
var sm = new SimpleMove(); | ||
var sm = new SimpleMove_1.SimpleMove(); | ||
sm.PlyCount = this.CurrentPos.PlyCount + 1; | ||
@@ -282,14 +264,14 @@ sm.From = mv[0] & 63; | ||
} | ||
}; | ||
Chess.prototype.positionChanged = function () { | ||
} | ||
positionChanged() { | ||
if (!this.supressEvents) { | ||
if (!this.CurrentMove.Fen) { | ||
this.CurrentMove.Fen = FenString.fromPosition(this.currentPos); | ||
this.CurrentMove.Fen = FenString_1.FenString.fromPosition(this.currentPos); | ||
} | ||
this.Fen = this.CurrentMove.Fen; | ||
} | ||
}; | ||
Chess.prototype.checkGameState = function () { | ||
} | ||
checkGameState() { | ||
var state = new ChessGameState(); | ||
var mlist = this.currentPos.generateMoves(Piece.NoPiece, GenerateMode.All, true); | ||
var mlist = this.currentPos.generateMoves(Piece_1.Piece.NoPiece, Position_1.GenerateMode.All, true); | ||
if (mlist.length === 0) { | ||
@@ -303,14 +285,14 @@ if (this.currentPos.isKingInCheck()) { | ||
} | ||
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.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))) { | ||
// King only | ||
state.IsNoMaterialWhite = true; | ||
} | ||
else if ((!this.currentPos.hasPiece(Piece.WKnight)) && (this.currentPos.getPieceCount(Piece.WBishop) === 1)) { | ||
else if ((!this.currentPos.hasPiece(Piece_1.Piece.WKnight)) && (this.currentPos.getPieceCount(Piece_1.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.currentPos.getPieceCount(Piece_1.Piece.WKnight) === 1) && (!this.currentPos.hasPiece(Piece_1.Piece.WBishop))) { | ||
// King and knight | ||
@@ -320,14 +302,14 @@ 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.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))) { | ||
// King only | ||
state.IsNoMaterialBlack = true; | ||
} | ||
else if ((!this.currentPos.hasPiece(Piece.BKnight)) && (this.currentPos.getPieceCount(Piece.BBishop) === 1)) { | ||
else if ((!this.currentPos.hasPiece(Piece_1.Piece.BKnight)) && (this.currentPos.getPieceCount(Piece_1.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.currentPos.getPieceCount(Piece_1.Piece.BKnight) === 1) && (!this.currentPos.hasPiece(Piece_1.Piece.BBishop))) { | ||
// King and knight | ||
@@ -348,9 +330,9 @@ state.IsNoMaterialBlack = true; | ||
return state; | ||
}; | ||
Chess.prototype.makeMove = function (fr, to, promote) { | ||
var currentPos = this.currentPos; | ||
var sm = new SimpleMove(); | ||
} | ||
makeMove(fr, to, promote) { | ||
const { currentPos } = this; | ||
var sm = new SimpleMove_1.SimpleMove(); | ||
sm.PieceNum = currentPos.getPieceNum(fr); | ||
sm.MovingPiece = currentPos.getPiece(fr); | ||
sm.Color = Piece.color(sm.MovingPiece); | ||
sm.Color = Piece_1.Piece.color(sm.MovingPiece); | ||
sm.From = fr; | ||
@@ -362,9 +344,9 @@ sm.To = to; | ||
sm.EpSquare = currentPos.EpTarget; | ||
sm.Promote = Piece.NoPiece; | ||
sm.Promote = Piece_1.Piece.NoPiece; | ||
var piece = sm.MovingPiece; | ||
var ptype = Piece.type(piece); | ||
var enemy = Color.flip(currentPos.WhoMove); | ||
var ptype = Piece_1.Piece.type(piece); | ||
var enemy = Color_1.Color.flip(currentPos.WhoMove); | ||
// handle promotion: | ||
var promoteRank = (currentPos.WhoMove === Color.White ? 7 : 0); | ||
if ((ptype == Piece.Pawn) && (Square.rank(to) == promoteRank)) { | ||
var promoteRank = (currentPos.WhoMove === Color_1.Color.White ? 7 : 0); | ||
if ((ptype == Piece_1.Piece.Pawn) && (Square_1.Square.rank(to) == promoteRank)) { | ||
if (!promote) { | ||
@@ -375,13 +357,13 @@ this.InPromotion = true; | ||
else { | ||
sm.Promote = Piece.typeFromChar(promote); | ||
sm.Promote = Piece_1.Piece.typeFromChar(promote); | ||
} | ||
} | ||
// Handle en passant capture: | ||
if (ptype == Piece.Pawn && (sm.CapturedPiece == Piece.NoPiece) && (Square.fyle(fr) != Square.fyle(to))) { | ||
var enemyPawn = Piece.create(enemy, Piece.Pawn); | ||
sm.CapturedSquare = (this.currentPos.WhoMove === Color.White ? (to - 8) : (to + 8)); | ||
if (ptype == Piece_1.Piece.Pawn && (sm.CapturedPiece == Piece_1.Piece.NoPiece) && (Square_1.Square.fyle(fr) != Square_1.Square.fyle(to))) { | ||
var 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; | ||
} | ||
return sm; | ||
}; | ||
} | ||
/** | ||
@@ -392,4 +374,4 @@ * Add a move at current position and do it. The parameter 'san' can be NULL. If it is provided, it is stored with the move to speed up PGN printing. | ||
*/ | ||
Chess.prototype.addMove = function (sm, san) { | ||
var currentPos = this.currentPos; | ||
addMove(sm, san) { | ||
const { currentPos } = this; | ||
// We must be at the end of a game/variation to add a move: | ||
@@ -402,3 +384,3 @@ if (!this.currentMove.END_MARKER) { | ||
if (!san || (san == undefined)) { | ||
sm.San = this.currentPos.makeSanString(sm, SanCheckLevel.MateTest); | ||
sm.San = this.currentPos.makeSanString(sm, Position_1.SanCheckLevel.MateTest); | ||
} | ||
@@ -409,5 +391,5 @@ else { | ||
} | ||
var newMove = this.currentMove.append(sm); | ||
const newMove = this.currentMove.append(sm); | ||
this.currentPos.doSimpleMove(sm); | ||
newMove.Fen = FenString.fromPosition(currentPos); | ||
newMove.Fen = FenString_1.FenString.fromPosition(currentPos); | ||
this.CurrentPlyCount++; | ||
@@ -419,3 +401,3 @@ if (!this.varDepth) { | ||
return newMove; | ||
}; | ||
} | ||
/** | ||
@@ -425,3 +407,3 @@ * Переместиться на указанную позицию в главной линии партии | ||
*/ | ||
Chess.prototype.moveToPly = function (hmNumber) { | ||
moveToPly(hmNumber) { | ||
this.supressEvents = true; | ||
@@ -447,8 +429,8 @@ if (hmNumber > this.CurrentPlyCount) { | ||
this.supressEvents = false; | ||
}; | ||
Chess.prototype.moveToKey = function (key) { | ||
} | ||
moveToKey(key) { | ||
this.supressEvents = true; | ||
if (this.moveList[key]) { | ||
this.currentMove = this.moveList[key]; | ||
this.currentPos = new Position(this.currentMove.Fen); | ||
this.currentPos = new Position_1.Position(this.currentMove.Fen); | ||
this.CurrentPlyCount = this.currentPos.PlyCount; | ||
@@ -458,3 +440,3 @@ this.currentMove = this.currentMove.Next; | ||
this.supressEvents = false; | ||
}; | ||
} | ||
/** | ||
@@ -464,3 +446,3 @@ * Переместить текущую позицию на 1 вперед | ||
*/ | ||
Chess.prototype.moveForward = function () { | ||
moveForward() { | ||
if (this.currentMove.END_MARKER) { | ||
@@ -474,3 +456,3 @@ return false; | ||
return true; | ||
}; | ||
} | ||
/** | ||
@@ -480,4 +462,4 @@ * Move to 1 turn back | ||
*/ | ||
Chess.prototype.moveBackward = function () { | ||
var prev = this.currentMove.Prev; | ||
moveBackward() { | ||
const prev = this.currentMove.Prev; | ||
if (prev.START_MARKER) { | ||
@@ -491,16 +473,16 @@ return false; | ||
return true; | ||
}; | ||
} | ||
/** | ||
* Move to first move | ||
*/ | ||
Chess.prototype.moveFirst = function () { | ||
moveFirst() { | ||
this.moveToPly(0); | ||
}; | ||
} | ||
/** | ||
* Move to last move | ||
*/ | ||
Chess.prototype.moveLast = function () { | ||
moveLast() { | ||
this.moveToPly(9999); | ||
}; | ||
Chess.prototype.getResultName = function (mode) { | ||
} | ||
getResultName(mode) { | ||
if (mode === "char") { | ||
@@ -519,18 +501,17 @@ return resultChar[this.Result]; | ||
return "?"; | ||
}; | ||
Chess.plyToTurn = function (ply, startPly) { | ||
} | ||
static plyToTurn(ply, startPly) { | ||
startPly = startPly || 0; | ||
return toSafeInteger(1 + ((ply + startPly) - 1) / 2); | ||
}; | ||
Chess.plyToColor = function (ply, startPly) { | ||
return toSafeInteger_1.default(1 + ((ply + startPly) - 1) / 2); | ||
} | ||
static plyToColor(ply, startPly) { | ||
startPly = startPly || 0; | ||
return (((ply + startPly) % 2) == 1) ? Color.White : Color.Black; | ||
}; | ||
Chess.turnToPly = function (turn, color) { | ||
color = color || Color.White; | ||
var ply = (((turn - 1) * 2) + color + 1); | ||
}; | ||
return Chess; | ||
}()); | ||
export { Chess }; | ||
return (((ply + startPly) % 2) == 1) ? Color_1.Color.White : Color_1.Color.Black; | ||
} | ||
static turnToPly(turn, color) { | ||
color = color || Color_1.Color.White; | ||
let ply = (((turn - 1) * 2) + color + 1); | ||
} | ||
} | ||
exports.Chess = Chess; | ||
//# sourceMappingURL=Chess.js.map |
@@ -1,14 +0,14 @@ | ||
var WHITE = 0; | ||
var BLACK = 1; | ||
var NO_COLOR = 2; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const WHITE = 0; | ||
const BLACK = 1; | ||
const NO_COLOR = 2; | ||
/** | ||
* Color | ||
*/ | ||
var Color = /** @class */ (function () { | ||
function Color() { | ||
class Color { | ||
static flip(c) { | ||
return (1 - c); | ||
} | ||
Color.flip = function (c) { | ||
return (1 - c); | ||
}; | ||
Color.toName = function (c) { | ||
static toName(c) { | ||
switch (c) { | ||
@@ -22,12 +22,11 @@ case NO_COLOR: | ||
} | ||
}; | ||
Color.White = WHITE; | ||
Color.Black = BLACK; | ||
Color.NoColor = NO_COLOR; | ||
Color.WhiteChar = "w"; | ||
Color.BlackChar = "b"; | ||
Color.Names = ["white", "black", "none"]; | ||
return Color; | ||
}()); | ||
export { Color }; | ||
} | ||
} | ||
exports.Color = Color; | ||
Color.White = WHITE; | ||
Color.Black = BLACK; | ||
Color.NoColor = NO_COLOR; | ||
Color.WhiteChar = "w"; | ||
Color.BlackChar = "b"; | ||
Color.Names = ["white", "black", "none"]; | ||
//# sourceMappingURL=Color.js.map |
@@ -0,24 +1,26 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Zero (invalid) square | ||
*/ | ||
var ns = 65; | ||
const ns = 65; | ||
// None | ||
var NULL_DIR = 0; | ||
const NULL_DIR = 0; | ||
// Up | ||
var UP = 1; | ||
const UP = 1; | ||
// Down | ||
var DOWN = 2; | ||
const DOWN = 2; | ||
// Left | ||
var LEFT = 4; | ||
const LEFT = 4; | ||
// Right | ||
var RIGHT = 8; | ||
const RIGHT = 8; | ||
/* tslint:disable:no-bitwise */ | ||
// Up/Left | ||
var UP_LEFT = (UP | LEFT); | ||
const UP_LEFT = (UP | LEFT); | ||
// Up/Right | ||
var UP_RIGHT = (UP | RIGHT); | ||
const UP_RIGHT = (UP | RIGHT); | ||
// Down/Left | ||
var DOWN_LEFT = (DOWN | LEFT); | ||
const DOWN_LEFT = (DOWN | LEFT); | ||
// Down/Right | ||
var DOWN_RIGHT = (DOWN | RIGHT); | ||
const DOWN_RIGHT = (DOWN | RIGHT); | ||
/* tslint:enable:no-bitwise */ | ||
@@ -28,3 +30,3 @@ /** | ||
*/ | ||
var __dirOpposite = [ | ||
const __dirOpposite = [ | ||
NULL_DIR, | ||
@@ -45,3 +47,3 @@ DOWN, | ||
*/ | ||
var __dirIsDiagonal = [ | ||
const __dirIsDiagonal = [ | ||
false, | ||
@@ -62,3 +64,3 @@ false, | ||
*/ | ||
var __dirDelta = [ | ||
const __dirDelta = [ | ||
0, | ||
@@ -79,3 +81,3 @@ 8, | ||
*/ | ||
var __squareMoves = [ | ||
const __squareMoves = [ | ||
[ns, 8, ns, ns, ns, ns, ns, ns, 1, 9, ns], | ||
@@ -148,3 +150,3 @@ [ns, 9, ns, ns, 0, 8, ns, ns, 2, 10, ns], | ||
]; // H8 | ||
var squareMove = function (sq, dir) { | ||
const squareMove = (sq, dir) => { | ||
return __squareMoves[sq][dir]; | ||
@@ -199,50 +201,47 @@ }; | ||
*/ | ||
var Direction = /** @class */ (function () { | ||
function Direction() { | ||
} | ||
class Direction { | ||
/** | ||
* Return opposite movment | ||
*/ | ||
Direction.opposite = function (d) { | ||
static opposite(d) { | ||
return __dirOpposite[d]; | ||
}; | ||
} | ||
/** | ||
* Return true, if movment is diagonal | ||
*/ | ||
Direction.isDiagonal = function (d) { | ||
static isDiagonal(d) { | ||
return __dirIsDiagonal[d]; | ||
}; | ||
} | ||
/** | ||
* Return distance for movment. | ||
*/ | ||
Direction.delta = function (d) { | ||
static delta(d) { | ||
return __dirDelta[d]; | ||
}; | ||
Direction.squareDirection = function (fr, to) { | ||
} | ||
static squareDirection(fr, to) { | ||
return __sqDir[fr][to]; | ||
}; | ||
Direction.squareMove = function (sq, dir) { | ||
} | ||
static squareMove(sq, dir) { | ||
return squareMove(sq, dir); | ||
}; | ||
// None | ||
Direction.Null = NULL_DIR; | ||
// Up | ||
Direction.Up = UP; | ||
// Down | ||
Direction.Down = DOWN; | ||
// Left | ||
Direction.Left = LEFT; | ||
// Right | ||
Direction.Right = RIGHT; | ||
// Up/Left | ||
Direction.UpLeft = UP_LEFT; | ||
// Up/Right | ||
Direction.UpRight = UP_RIGHT; | ||
// Down/Left | ||
Direction.DownLeft = DOWN_LEFT; | ||
// Down/Right | ||
Direction.DownRight = DOWN_RIGHT; | ||
return Direction; | ||
}()); | ||
export { Direction }; | ||
} | ||
} | ||
exports.Direction = Direction; | ||
// None | ||
Direction.Null = NULL_DIR; | ||
// Up | ||
Direction.Up = UP; | ||
// Down | ||
Direction.Down = DOWN; | ||
// Left | ||
Direction.Left = LEFT; | ||
// Right | ||
Direction.Right = RIGHT; | ||
// Up/Left | ||
Direction.UpLeft = UP_LEFT; | ||
// Up/Right | ||
Direction.UpRight = UP_RIGHT; | ||
// Down/Left | ||
Direction.DownLeft = DOWN_LEFT; | ||
// Down/Right | ||
Direction.DownRight = DOWN_RIGHT; | ||
//# sourceMappingURL=Direction.js.map |
@@ -1,41 +0,43 @@ | ||
import repeat from 'lodash-es/repeat'; | ||
import toSafeInteger from 'lodash-es/toSafeInteger'; | ||
import { Piece } from './Piece'; | ||
import { Square } from './Square'; | ||
import { Color } from './Color'; | ||
import { Castle } from './Castle'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const repeat_1 = require("lodash-es/repeat"); | ||
const toSafeInteger_1 = require("lodash-es/toSafeInteger"); | ||
const Piece_1 = require("./Piece"); | ||
const Square_1 = require("./Square"); | ||
const Color_1 = require("./Color"); | ||
const Castle_1 = require("./Castle"); | ||
// Forsite to piece map | ||
var fenPieces = { | ||
"1": Piece.NoPiece, | ||
"P": Piece.WPawn, | ||
"K": Piece.WKing, | ||
"Q": Piece.WQueen, | ||
"R": Piece.WRook, | ||
"N": Piece.WKnight, | ||
"B": Piece.WBishop, | ||
"p": Piece.BPawn, | ||
"k": Piece.BKing, | ||
"q": Piece.BQueen, | ||
"r": Piece.BRook, | ||
"n": Piece.BKnight, | ||
"b": Piece.BBishop | ||
const fenPieces = { | ||
"1": Piece_1.Piece.NoPiece, | ||
"P": Piece_1.Piece.WPawn, | ||
"K": Piece_1.Piece.WKing, | ||
"Q": Piece_1.Piece.WQueen, | ||
"R": Piece_1.Piece.WRook, | ||
"N": Piece_1.Piece.WKnight, | ||
"B": Piece_1.Piece.WBishop, | ||
"p": Piece_1.Piece.BPawn, | ||
"k": Piece_1.Piece.BKing, | ||
"q": Piece_1.Piece.BQueen, | ||
"r": Piece_1.Piece.BRook, | ||
"n": Piece_1.Piece.BKnight, | ||
"b": Piece_1.Piece.BBishop | ||
}; | ||
// Piece to Forsite map | ||
var FP_p2f = []; | ||
FP_p2f[Piece.NoPiece] = "1"; | ||
FP_p2f[Piece.WPawn] = "P"; | ||
FP_p2f[Piece.WKing] = "K"; | ||
FP_p2f[Piece.WQueen] = "Q"; | ||
FP_p2f[Piece.WRook] = "R"; | ||
FP_p2f[Piece.WKnight] = "N"; | ||
FP_p2f[Piece.WBishop] = "B"; | ||
FP_p2f[Piece.BPawn] = "p"; | ||
FP_p2f[Piece.BKing] = "k"; | ||
FP_p2f[Piece.BQueen] = "q"; | ||
FP_p2f[Piece.BRook] = "r"; | ||
FP_p2f[Piece.BKnight] = "n"; | ||
FP_p2f[Piece.BBishop] = "b"; | ||
var fenEmptyBoardStd = "8/8/8/8/8/8/8/8 w KQkq - 0 1"; | ||
const FP_p2f = []; | ||
FP_p2f[Piece_1.Piece.NoPiece] = "1"; | ||
FP_p2f[Piece_1.Piece.WPawn] = "P"; | ||
FP_p2f[Piece_1.Piece.WKing] = "K"; | ||
FP_p2f[Piece_1.Piece.WQueen] = "Q"; | ||
FP_p2f[Piece_1.Piece.WRook] = "R"; | ||
FP_p2f[Piece_1.Piece.WKnight] = "N"; | ||
FP_p2f[Piece_1.Piece.WBishop] = "B"; | ||
FP_p2f[Piece_1.Piece.BPawn] = "p"; | ||
FP_p2f[Piece_1.Piece.BKing] = "k"; | ||
FP_p2f[Piece_1.Piece.BQueen] = "q"; | ||
FP_p2f[Piece_1.Piece.BRook] = "r"; | ||
FP_p2f[Piece_1.Piece.BKnight] = "n"; | ||
FP_p2f[Piece_1.Piece.BBishop] = "b"; | ||
const fenEmptyBoardStd = "8/8/8/8/8/8/8/8 w KQkq - 0 1"; | ||
function fen2Piece(fenCharacter) { | ||
return (fenPieces[fenCharacter]) ? fenPieces[fenCharacter] : Piece.NoPiece; | ||
return (fenPieces[fenCharacter]) ? fenPieces[fenCharacter] : Piece_1.Piece.NoPiece; | ||
} | ||
@@ -55,3 +57,3 @@ function fenToSquare(sq) { | ||
/** Flags **/ | ||
export var FenFormat; | ||
var FenFormat; | ||
(function (FenFormat) { | ||
@@ -62,10 +64,8 @@ FenFormat[FenFormat["board"] = 0] = "board"; | ||
FenFormat[FenFormat["complete"] = 3] = "complete"; | ||
})(FenFormat || (FenFormat = {})); | ||
var FenString = /** @class */ (function () { | ||
function FenString() { | ||
} | ||
FenString.trim = function (fen, flag) { | ||
})(FenFormat = exports.FenFormat || (exports.FenFormat = {})); | ||
class FenString { | ||
static trim(fen, flag) { | ||
fen = normalizeFen(fen); | ||
var tok = fen.split(/\s+/); | ||
var result = String(tok[0]); | ||
const tok = fen.split(/\s+/); | ||
let result = String(tok[0]); | ||
if (flag >= FenFormat.color) { | ||
@@ -98,14 +98,13 @@ if (tok.length > 1) { | ||
return result; | ||
}; | ||
FenString.toPosition = function (pos, fen, forceCastling) { | ||
if (forceCastling === void 0) { forceCastling = true; } | ||
} | ||
static toPosition(pos, fen, forceCastling = true) { | ||
fen = normalizeFen(fen); | ||
var tok = fen.split(/\s+/); | ||
var board_text = String(tok[0]); | ||
var i = 0; | ||
var sq = 0; | ||
const tok = fen.split(/\s+/); | ||
let board_text = String(tok[0]); | ||
let i = 0; | ||
let sq = 0; | ||
// replace NOPIECE square with repeated "1" string | ||
for (i = 2; i <= 8; i++) { | ||
var re = new RegExp(String(i), "g"); | ||
board_text = board_text.replace(re, repeat("1", i)); | ||
const re = new RegExp(String(i), "g"); | ||
board_text = board_text.replace(re, repeat_1.default("1", i)); | ||
} | ||
@@ -119,4 +118,4 @@ // remove slashes | ||
for (sq = 0; sq < 64; sq++) { | ||
var p = fen2Piece(board_text.charAt(sq)); | ||
if (p !== Piece.NoPiece) { | ||
const p = fen2Piece(board_text.charAt(sq)); | ||
if (p !== Piece_1.Piece.NoPiece) { | ||
pos.addPiece(p, fenToSquare(sq)); | ||
@@ -127,5 +126,5 @@ } | ||
// now the side to move: | ||
pos.WhoMove = (tok[1] === "b") ? Color.Black : Color.White; | ||
pos.WhoMove = (tok[1] === "b") ? Color_1.Color.Black : Color_1.Color.White; | ||
} | ||
var board = pos.Board; | ||
const board = pos.Board; | ||
pos.Castling = 0; | ||
@@ -140,16 +139,16 @@ if ((tok.length > 2) || forceCastling) { | ||
// still on their starting squares: | ||
if (board[4] === Piece.WKing) { | ||
if (board[0] === Piece.WRook) { | ||
pos.setCastling(Color.White, Castle.QSide, true); | ||
if (board[4] === Piece_1.Piece.WKing) { | ||
if (board[0] === Piece_1.Piece.WRook) { | ||
pos.setCastling(Color_1.Color.White, Castle_1.Castle.QSide, true); | ||
} | ||
if (board[7] === Piece.WRook) { | ||
pos.setCastling(Color.White, Castle.KSide, true); | ||
if (board[7] === Piece_1.Piece.WRook) { | ||
pos.setCastling(Color_1.Color.White, Castle_1.Castle.KSide, true); | ||
} | ||
} | ||
if (board[60] === Piece.BKing) { | ||
if (board[56] === Piece.BRook) { | ||
pos.setCastling(Color.Black, Castle.QSide, true); | ||
if (board[60] === Piece_1.Piece.BKing) { | ||
if (board[56] === Piece_1.Piece.BRook) { | ||
pos.setCastling(Color_1.Color.Black, Castle_1.Castle.QSide, true); | ||
} | ||
if (board[63] === Piece.BRook) { | ||
pos.setCastling(Color.Black, Castle.KSide, true); | ||
if (board[63] === Piece_1.Piece.BRook) { | ||
pos.setCastling(Color_1.Color.Black, Castle_1.Castle.KSide, true); | ||
} | ||
@@ -161,12 +160,12 @@ } | ||
if (tok[2].charAt(i) === "K") { | ||
pos.setCastling(Color.White, Castle.KSide, true); | ||
pos.setCastling(Color_1.Color.White, Castle_1.Castle.KSide, true); | ||
} | ||
if (tok[2].charAt(i) === "Q") { | ||
pos.setCastling(Color.White, Castle.QSide, true); | ||
pos.setCastling(Color_1.Color.White, Castle_1.Castle.QSide, true); | ||
} | ||
if (tok[2].charAt(i) === "k") { | ||
pos.setCastling(Color.Black, Castle.KSide, true); | ||
pos.setCastling(Color_1.Color.Black, Castle_1.Castle.KSide, true); | ||
} | ||
if (tok[2].charAt(i) === "q") { | ||
pos.setCastling(Color.Black, Castle.QSide, true); | ||
pos.setCastling(Color_1.Color.Black, Castle_1.Castle.QSide, true); | ||
} | ||
@@ -178,19 +177,19 @@ } | ||
if (tok[3].charAt(0) === "-") { | ||
pos.EpTarget = Square.NullSquare; | ||
pos.EpTarget = Square_1.Square.NullSquare; | ||
} | ||
else { | ||
var fylec = tok[3].charAt(0); | ||
const fylec = tok[3].charAt(0); | ||
if (fylec < "a" || fylec > "h") { | ||
return false; | ||
} | ||
var rankc = tok[3].charAt(1); | ||
const rankc = tok[3].charAt(1); | ||
if (rankc !== "3" && rankc !== "6") { | ||
return false; | ||
} | ||
pos.EpTarget = Square.create(Square.fyleFromChar(fylec), Square.rankFromChar(rankc)); | ||
pos.EpTarget = Square_1.Square.create(Square_1.Square.fyleFromChar(fylec), Square_1.Square.rankFromChar(rankc)); | ||
} | ||
} | ||
pos.HalfMoveCount = (tok.length > 4) ? toSafeInteger(tok[4]) : 0; | ||
pos.HalfMoveCount = (tok.length > 4) ? toSafeInteger_1.default(tok[4]) : 0; | ||
if (tok.length > 5) { | ||
i = toSafeInteger(tok[5]); | ||
i = toSafeInteger_1.default(tok[5]); | ||
if (i >= 1) { | ||
@@ -201,16 +200,15 @@ pos.setMoveNo(i); | ||
return true; | ||
}; | ||
FenString.fromPosition = function (pos, flag) { | ||
if (flag === void 0) { flag = FenFormat.complete; } | ||
var fen = ""; | ||
var pB; | ||
var board = pos.Board; | ||
for (var rank = 7; rank >= 0; rank--) { | ||
var NOPIECERun = 0; | ||
} | ||
static fromPosition(pos, flag = FenFormat.complete) { | ||
let fen = ""; | ||
let pB; | ||
const board = pos.Board; | ||
for (let rank = 7; rank >= 0; rank--) { | ||
let NOPIECERun = 0; | ||
if (rank !== 7) { | ||
fen += "/"; | ||
} | ||
for (var fyle = 0; fyle <= 7; fyle++) { | ||
pB = board[Square.create(fyle, rank)]; | ||
if (pB !== Piece.NoPiece) { | ||
for (let fyle = 0; fyle <= 7; fyle++) { | ||
pB = board[Square_1.Square.create(fyle, rank)]; | ||
if (pB !== Piece_1.Piece.NoPiece) { | ||
if (NOPIECERun > 0) { | ||
@@ -231,3 +229,3 @@ fen += NOPIECERun.toString(); | ||
if (flag >= FenFormat.color) { | ||
fen += (pos.WhoMove == Color.Black ? " b" : " w"); | ||
fen += (pos.WhoMove == Color_1.Color.Black ? " b" : " w"); | ||
if (flag >= FenFormat.castlingEp) { | ||
@@ -239,16 +237,16 @@ if (pos.Castling === 0) { | ||
fen += " "; | ||
if (pos.getCastling(Color.White, Castle.KSide)) { | ||
if (pos.getCastling(Color_1.Color.White, Castle_1.Castle.KSide)) { | ||
fen += "K"; | ||
} | ||
if (pos.getCastling(Color.White, Castle.QSide)) { | ||
if (pos.getCastling(Color_1.Color.White, Castle_1.Castle.QSide)) { | ||
fen += "Q"; | ||
} | ||
if (pos.getCastling(Color.Black, Castle.KSide)) { | ||
if (pos.getCastling(Color_1.Color.Black, Castle_1.Castle.KSide)) { | ||
fen += "k"; | ||
} | ||
if (pos.getCastling(Color.Black, Castle.QSide)) { | ||
if (pos.getCastling(Color_1.Color.Black, Castle_1.Castle.QSide)) { | ||
fen += "q"; | ||
} | ||
} | ||
if (pos.EpTarget === Square.NullSquare) { | ||
if (pos.EpTarget === Square_1.Square.NullSquare) { | ||
fen += " -"; | ||
@@ -258,3 +256,3 @@ } | ||
fen += " "; | ||
fen += Square.squareName(pos.EpTarget); | ||
fen += Square_1.Square.squareName(pos.EpTarget); | ||
} | ||
@@ -268,8 +266,7 @@ if (flag >= FenFormat.complete) { | ||
return fen; | ||
}; | ||
FenString.fenStandartStart = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"; | ||
FenString.fenEmptyBoard = fenEmptyBoardStd; | ||
return FenString; | ||
}()); | ||
export { FenString }; | ||
} | ||
} | ||
exports.FenString = FenString; | ||
FenString.fenStandartStart = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"; | ||
FenString.fenEmptyBoard = fenEmptyBoardStd; | ||
//# sourceMappingURL=FenString.js.map |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=IOpeningPosition.js.map |
@@ -1,13 +0,15 @@ | ||
import * as shortid from 'shortid'; | ||
import { Color } from './Color'; | ||
import { Piece } from './Piece'; | ||
import { Square } from './Square'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const shortid = require("shortid"); | ||
const Color_1 = require("./Color"); | ||
const Piece_1 = require("./Piece"); | ||
const Square_1 = require("./Square"); | ||
/** | ||
* Move in position | ||
*/ | ||
var Move = /** @class */ (function () { | ||
class Move { | ||
/** | ||
* @constructor | ||
*/ | ||
function Move() { | ||
constructor() { | ||
this.vars = []; | ||
@@ -20,10 +22,10 @@ this.varNo = 0; | ||
this.moveData = null; | ||
this.from = Square.NullSquare; | ||
this.to = Square.NullSquare; | ||
this.color = Color.NoColor; | ||
this.capturedSquare = Square.NullSquare; | ||
this.capturedPiece = Piece.NoPiece; | ||
this.promote = Piece.NoPiece; | ||
this.from = Square_1.Square.NullSquare; | ||
this.to = Square_1.Square.NullSquare; | ||
this.color = Color_1.Color.NoColor; | ||
this.capturedSquare = Square_1.Square.NullSquare; | ||
this.capturedPiece = Piece_1.Piece.NoPiece; | ||
this.promote = Piece_1.Piece.NoPiece; | ||
this.piece_num = 0; | ||
this.WhoMove = Color.White; | ||
this.WhoMove = Color_1.Color.White; | ||
this.ply = 0; | ||
@@ -38,4 +40,4 @@ this.Comments = ""; | ||
} | ||
Move.init = function (fen, parent) { | ||
var firstMove = new Move(); | ||
static init(fen, parent) { | ||
const firstMove = new Move(); | ||
firstMove.Name = "FirstMove"; | ||
@@ -61,72 +63,48 @@ firstMove.Fen = fen; | ||
return firstMove.next_move; | ||
}; | ||
Move.prototype.isFirst = function () { | ||
} | ||
isFirst() { | ||
return this.START_MARKER || this.prev_move.START_MARKER; | ||
}; | ||
Move.prototype.isBegin = function () { | ||
} | ||
isBegin() { | ||
return this.START_MARKER; | ||
}; | ||
Object.defineProperty(Move.prototype, "First", { | ||
get: function () { | ||
var move = this; | ||
while (move.prev_move) { | ||
move = move.prev_move; | ||
} | ||
return move; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Move.prototype, "Prev", { | ||
get: function () { | ||
return this.prev_move; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Move.prototype, "Next", { | ||
get: function () { | ||
return this.next_move; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Move.prototype.isLast = function () { | ||
} | ||
get First() { | ||
let move = this; | ||
while (move.prev_move) { | ||
move = move.prev_move; | ||
} | ||
return move; | ||
} | ||
get Prev() { | ||
return this.prev_move; | ||
} | ||
get Next() { | ||
return this.next_move; | ||
} | ||
isLast() { | ||
return this.END_MARKER || this.next_move.END_MARKER; | ||
}; | ||
Move.prototype.isEnd = function () { | ||
} | ||
isEnd() { | ||
return this.END_MARKER; | ||
}; | ||
Object.defineProperty(Move.prototype, "Last", { | ||
get: function () { | ||
var move = this; | ||
while (move.next_move) { | ||
move = move.next_move; | ||
} | ||
return move; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Move.prototype, "PlyCount", { | ||
get: function () { | ||
return this.ply; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Move.prototype, "numVars", { | ||
get: function () { | ||
return this.vars.length; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
} | ||
get Last() { | ||
let move = this; | ||
while (move.next_move) { | ||
move = move.next_move; | ||
} | ||
return move; | ||
} | ||
get PlyCount() { | ||
return this.ply; | ||
} | ||
get numVars() { | ||
return this.vars.length; | ||
} | ||
/** | ||
* Add and enter variation | ||
*/ | ||
Move.prototype.addVariation = function () { | ||
var varRoot = null; | ||
addVariation() { | ||
let varRoot = null; | ||
if (!this.START_MARKER) { | ||
var prev = this.Prev; | ||
const prev = this.Prev; | ||
varRoot = Move.init(prev.Fen, prev); | ||
@@ -136,8 +114,8 @@ prev.vars.push(varRoot); | ||
return varRoot; | ||
}; | ||
} | ||
/** | ||
* Enter variation | ||
*/ | ||
Move.prototype.moveIntoVariation = function (no) { | ||
var varRoot = null; | ||
moveIntoVariation(no) { | ||
let varRoot = null; | ||
if ((no > 0) && (no <= this.numVars)) { | ||
@@ -147,7 +125,7 @@ varRoot = this.vars[no].Next; | ||
return varRoot; | ||
}; | ||
} | ||
/** | ||
* Exit variation | ||
*/ | ||
Move.prototype.exitVariation = function () { | ||
exitVariation() { | ||
if (this.parent) { | ||
@@ -157,8 +135,8 @@ return parent; | ||
return this; | ||
}; | ||
Move.prototype.truncate = function () { | ||
} | ||
truncate() { | ||
this.vars = []; | ||
this.END_MARKER = true; | ||
}; | ||
Move.prototype.append = function (sm) { | ||
} | ||
append(sm) { | ||
var newMove = new Move(); | ||
@@ -176,26 +154,17 @@ newMove.parent = this.parent; | ||
return newMove; | ||
}; | ||
Object.defineProperty(Move.prototype, "moveKey", { | ||
get: function () { | ||
var pmk = this.parentMoveKey; | ||
if (pmk) { | ||
return pmk + "!" + this.varNo.toString() + "-" + this.ply.toString(); | ||
} | ||
else { | ||
return this.ply.toString(); | ||
} | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Move.prototype, "parentMoveKey", { | ||
get: function () { | ||
return (this.parent) ? this.parent.moveKey : ""; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return Move; | ||
}()); | ||
export { Move }; | ||
} | ||
get moveKey() { | ||
const pmk = this.parentMoveKey; | ||
if (pmk) { | ||
return pmk + "!" + this.varNo.toString() + "-" + this.ply.toString(); | ||
} | ||
else { | ||
return this.ply.toString(); | ||
} | ||
} | ||
get parentMoveKey() { | ||
return (this.parent) ? this.parent.moveKey : ""; | ||
} | ||
} | ||
exports.Move = Move; | ||
//# sourceMappingURL=Move.js.map |
@@ -1,21 +0,21 @@ | ||
import { Color } from './Color'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Color_1 = require("./Color"); | ||
/** | ||
* Zero (empty) piece | ||
*/ | ||
var noPiece = 0x07; | ||
var PIECE_IS_SLIDER = [false, false, true, true, true, false, false, false]; | ||
var PIECE_CHARS = ["x", "K", "Q", "R", "B", "N", "P", ".", "x", "k", "q", "r", "b", "n", "p", "x"]; | ||
var PIECE_NAMES = ["xx", "wk", "wq", "wr", "wb", "wn", "wp", "xx", "xx", "bk", "bq", "br", "bb", "bn", "bp"]; | ||
const noPiece = 0x07; | ||
const PIECE_IS_SLIDER = [false, false, true, true, true, false, false, false]; | ||
const PIECE_CHARS = ["x", "K", "Q", "R", "B", "N", "P", ".", "x", "k", "q", "r", "b", "n", "p", "x"]; | ||
const PIECE_NAMES = ["xx", "wk", "wq", "wr", "wb", "wn", "wp", "xx", "xx", "bk", "bq", "br", "bb", "bn", "bp"]; | ||
/** | ||
* Chess piece | ||
*/ | ||
var Piece = /** @class */ (function () { | ||
function Piece() { | ||
} | ||
class Piece { | ||
/** | ||
* Return piece type. | ||
*/ | ||
Piece.type = function (p) { | ||
static type(p) { | ||
return (p & 0x07); | ||
}; | ||
} | ||
/** | ||
@@ -25,11 +25,11 @@ * Return piece color. | ||
*/ | ||
Piece.color = function (p) { | ||
return (p === noPiece) ? Color.NoColor : ((p & 0x08) >> 3); | ||
}; | ||
static color(p) { | ||
return (p === noPiece) ? Color_1.Color.NoColor : ((p & 0x08) >> 3); | ||
} | ||
/** | ||
* Return piece color for valid piece | ||
*/ | ||
Piece.colorNotEmpty = function (p) { | ||
static colorNotEmpty(p) { | ||
return ((p & 0x08) >> 3); | ||
}; | ||
} | ||
/** | ||
@@ -40,15 +40,15 @@ * Make colored piece. | ||
*/ | ||
Piece.create = function (c, p) { | ||
static create(c, p) { | ||
return (p === noPiece) ? noPiece : ((c << 3) | (p & 0x07)); | ||
}; | ||
} | ||
/** | ||
* Return true, if piece can slide moves. | ||
*/ | ||
Piece.isSlider = function (p) { | ||
static isSlider(p) { | ||
return PIECE_IS_SLIDER[Piece.type(p)]; | ||
}; | ||
} | ||
/** | ||
* Return piece type from piece char. | ||
*/ | ||
Piece.typeFromChar = function (pc) { | ||
static typeFromChar(pc) { | ||
switch (pc) { | ||
@@ -63,3 +63,3 @@ case "k": return Piece.King; | ||
} | ||
}; | ||
} | ||
/** | ||
@@ -69,9 +69,9 @@ * Return piece char. | ||
*/ | ||
Piece.toChar = function (p) { | ||
static toChar(p) { | ||
return PIECE_CHARS[p]; | ||
}; | ||
} | ||
/** | ||
* Return uppercased piece char. | ||
*/ | ||
Piece.toUpperChar = function (p) { | ||
static toUpperChar(p) { | ||
var pt = Piece.type(p); | ||
@@ -87,33 +87,32 @@ switch (pt) { | ||
} | ||
}; | ||
Piece.pieceName = function (p) { | ||
} | ||
static pieceName(p) { | ||
return PIECE_NAMES[p]; | ||
}; | ||
/* tslint:disable:no-bitwise */ | ||
// Piece types (without color): ============ | ||
Piece.King = 0x01; | ||
Piece.Queen = 0x02; | ||
Piece.Rook = 0x03; | ||
Piece.Bishop = 0x04; | ||
Piece.Knight = 0x05; | ||
Piece.Pawn = 0x06; | ||
Piece.NoPiece = noPiece; | ||
// White pieces: ============ | ||
Piece.WKing = 0x01; | ||
Piece.WQueen = 0x02; | ||
Piece.WRook = 0x03; | ||
Piece.WBishop = 0x04; | ||
Piece.WKnight = 0x05; | ||
Piece.WPawn = 0x06; | ||
// Black pieces: ============ | ||
Piece.BKing = 0x09; | ||
Piece.BQueen = 0x0A; | ||
Piece.BRook = 0x0B; | ||
Piece.BBishop = 0x0C; | ||
Piece.BKnight = 0x0D; | ||
Piece.BPawn = 0x0E; | ||
Piece.Score = [9999, 10, 6, 3, 3, 1]; | ||
return Piece; | ||
}()); | ||
export { Piece }; | ||
} | ||
} | ||
exports.Piece = Piece; | ||
/* tslint:disable:no-bitwise */ | ||
// Piece types (without color): ============ | ||
Piece.King = 0x01; | ||
Piece.Queen = 0x02; | ||
Piece.Rook = 0x03; | ||
Piece.Bishop = 0x04; | ||
Piece.Knight = 0x05; | ||
Piece.Pawn = 0x06; | ||
Piece.NoPiece = noPiece; | ||
// White pieces: ============ | ||
Piece.WKing = 0x01; | ||
Piece.WQueen = 0x02; | ||
Piece.WRook = 0x03; | ||
Piece.WBishop = 0x04; | ||
Piece.WKnight = 0x05; | ||
Piece.WPawn = 0x06; | ||
// Black pieces: ============ | ||
Piece.BKing = 0x09; | ||
Piece.BQueen = 0x0A; | ||
Piece.BRook = 0x0B; | ||
Piece.BBishop = 0x0C; | ||
Piece.BKnight = 0x0D; | ||
Piece.BPawn = 0x0E; | ||
Piece.Score = [9999, 10, 6, 3, 3, 1]; | ||
//# sourceMappingURL=Piece.js.map |
@@ -1,20 +0,22 @@ | ||
import { Color } from './Color'; | ||
import { Piece } from './Piece'; | ||
import { Square } from './Square'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Color_1 = require("./Color"); | ||
const Piece_1 = require("./Piece"); | ||
const Square_1 = require("./Square"); | ||
/** | ||
* Move data. | ||
*/ | ||
var SimpleMove = /** @class */ (function () { | ||
function SimpleMove() { | ||
class SimpleMove { | ||
constructor() { | ||
this.PieceNum = 0; | ||
this.MovingPiece = Piece.NoPiece; | ||
this.From = Square.NullSquare; | ||
this.To = Square.NullSquare; | ||
this.Color = Color.NoColor; | ||
this.MovingPiece = Piece_1.Piece.NoPiece; | ||
this.From = Square_1.Square.NullSquare; | ||
this.To = Square_1.Square.NullSquare; | ||
this.Color = Color_1.Color.NoColor; | ||
this.CapturedNum = 0; | ||
this.CapturedPiece = Piece.NoPiece; | ||
this.Promote = Piece.NoPiece; | ||
this.CapturedSquare = Square.NullSquare; // only different to "to" field if this capture is an en passant capture. | ||
this.CapturedPiece = Piece_1.Piece.NoPiece; | ||
this.Promote = Piece_1.Piece.NoPiece; | ||
this.CapturedSquare = Square_1.Square.NullSquare; // only different to "to" field if this capture is an en passant capture. | ||
this.CastleFlags = 0; | ||
this.EpSquare = Square.NullSquare; | ||
this.EpSquare = Square_1.Square.NullSquare; | ||
this.OldHalfMoveClock = 0; | ||
@@ -27,8 +29,7 @@ this.PlyCount = 0; | ||
} | ||
SimpleMove.prototype.toString = function () { | ||
toString() { | ||
return this.San; | ||
}; | ||
return SimpleMove; | ||
}()); | ||
export { SimpleMove }; | ||
} | ||
} | ||
exports.SimpleMove = SimpleMove; | ||
//# sourceMappingURL=SimpleMove.js.map |
@@ -1,11 +0,13 @@ | ||
import { Color } from './Color'; | ||
import { Direction } from './Direction'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Color_1 = require("./Color"); | ||
const Direction_1 = require("./Direction"); | ||
/** | ||
* Zero (invalid) square | ||
*/ | ||
var ns = 65; | ||
const ns = 65; | ||
/** | ||
* Fyle's names | ||
*/ | ||
var hqs = ["a", "b", "c", "d", "e", "f", "g", "h"]; | ||
const hqs = ["a", "b", "c", "d", "e", "f", "g", "h"]; | ||
/** | ||
@@ -20,3 +22,3 @@ * Conver square number to name | ||
*/ | ||
var __squareLast = [ | ||
const __squareLast = [ | ||
[ns, 56, 0, ns, 0, 0, 0, ns, 7, 63, 0], | ||
@@ -92,3 +94,3 @@ [ns, 57, 1, ns, 0, 8, 1, ns, 7, 55, 1], | ||
*/ | ||
var __knightAttacks = [ | ||
const __knightAttacks = [ | ||
[10, 17, ns, ns, ns, ns, ns, ns, ns], | ||
@@ -164,3 +166,3 @@ [11, 16, 18, ns, ns, ns, ns, ns, ns], | ||
*/ | ||
var __kingAttacks = [ | ||
const __kingAttacks = [ | ||
[1, 8, 9, ns, ns, ns, ns, ns, ns], | ||
@@ -233,3 +235,3 @@ [0, 2, 8, 9, 10, ns, ns, ns, ns], | ||
]; | ||
var __rankFyleDist = [ | ||
const __rankFyleDist = [ | ||
0, 1, 2, 3, 4, 5, 6, 7, | ||
@@ -244,3 +246,3 @@ 1, 0, 1, 2, 3, 4, 5, 6, | ||
]; | ||
var squareLast = function (sq, dir) { | ||
const squareLast = (sq, dir) => { | ||
return __squareLast[sq][dir]; | ||
@@ -253,41 +255,39 @@ }; | ||
*/ | ||
var Square = /** @class */ (function () { | ||
function Square() { | ||
class Square { | ||
static fyle(sq) { | ||
return (sq & 0x7); | ||
} | ||
Square.fyle = function (sq) { | ||
return (sq & 0x7); | ||
}; | ||
Square.rank = function (sq) { | ||
static rank(sq) { | ||
return ((sq >> 3) & 0x7); | ||
}; | ||
Square.create = function (f, r) { | ||
} | ||
static create(f, r) { | ||
return ((r << 3) | f); | ||
}; | ||
Square.rankFromChar = function (c) { | ||
} | ||
static rankFromChar(c) { | ||
/* tslint:disable:no-eval */ | ||
return (c < "1" || c > "8") ? ns : (eval(c) - 1); | ||
/* tslint:enable:no-eval */ | ||
}; | ||
Square.fyleFromChar = function (c) { | ||
} | ||
static fyleFromChar(c) { | ||
return (c < "a" || c > "h") ? ns : (c.charCodeAt(0) - "a".charCodeAt(0)); | ||
}; | ||
Square.leftDiag = function (sq) { | ||
} | ||
static leftDiag(sq) { | ||
return Square.rank(sq) + Square.fyle(sq); | ||
}; | ||
Square.rightDiag = function (sq) { | ||
} | ||
static rightDiag(sq) { | ||
return (7 + Square.rank(sq) - Square.fyle(sq)); | ||
}; | ||
Square.color = function (sq) { | ||
} | ||
static color(sq) { | ||
return 1 - (Square.leftDiag(sq) & 1); | ||
}; | ||
Square.colorChar = function (sq) { | ||
return (Square.color(sq) === Color.Black) ? Color.BlackChar : Color.WhiteChar; | ||
}; | ||
Square.rankChar = function (sq) { | ||
} | ||
static colorChar(sq) { | ||
return (Square.color(sq) === Color_1.Color.Black) ? Color_1.Color.BlackChar : Color_1.Color.WhiteChar; | ||
} | ||
static rankChar(sq) { | ||
return (Square.rank(sq) + 1).toString(); | ||
}; | ||
Square.fyleChar = function (sq) { | ||
} | ||
static fyleChar(sq) { | ||
return hqs[Square.fyle(sq)]; | ||
}; | ||
Square.parse = function (sq) { | ||
} | ||
static parse(sq) { | ||
if (sq && sq.length === 2) { | ||
@@ -297,6 +297,6 @@ return Square.create(Square.fyleFromChar(sq[0]), Square.rankFromChar(sq[1])); | ||
return ns; | ||
}; | ||
Square.squareName = function (s) { | ||
} | ||
static squareName(s) { | ||
return notation_Pos2Note(s); | ||
}; | ||
} | ||
/** | ||
@@ -307,3 +307,3 @@ * returns true if the two squares are adjacent. | ||
*/ | ||
Square.adjacent = function (from, to) { | ||
static adjacent(from, to) { | ||
var fromRank = Square.rank(from); | ||
@@ -322,16 +322,16 @@ var toRank = Square.rank(to); | ||
return true; | ||
}; | ||
} | ||
/** | ||
* Get direction for move from square @fr to square @to. | ||
*/ | ||
Square.direction = function (fr, to) { | ||
return Direction.squareDirection(fr, to); | ||
}; | ||
Square.move = function (sq, dir) { | ||
return Direction.squareMove(sq, dir); | ||
}; | ||
Square.last = function (sq, dir) { | ||
static direction(fr, to) { | ||
return Direction_1.Direction.squareDirection(fr, to); | ||
} | ||
static move(sq, dir) { | ||
return Direction_1.Direction.squareMove(sq, dir); | ||
} | ||
static last(sq, dir) { | ||
return squareLast(sq, dir); | ||
}; | ||
Square.isKnightHop = function (from, to) { | ||
} | ||
static isKnightHop(from, to) { | ||
var rdist = __rankFyleDist[(Square.rank(from) << 3) | Square.rank(to)]; | ||
@@ -342,20 +342,19 @@ var fdist = __rankFyleDist[(Square.fyle(from) << 3) | Square.fyle(to)]; | ||
return ((rdist * fdist) === 2); | ||
}; | ||
Square.knightAttack = function (from, to) { | ||
} | ||
static knightAttack(from, to) { | ||
return __knightAttacks[from][to]; | ||
}; | ||
Square.knightAttacks = function (from) { | ||
} | ||
static knightAttacks(from) { | ||
return __knightAttacks[from]; | ||
}; | ||
Square.kingAttack = function (from, to) { | ||
} | ||
static kingAttack(from, to) { | ||
return __kingAttacks[from][to]; | ||
}; | ||
Square.kingAttacks = function (from) { | ||
} | ||
static kingAttacks(from) { | ||
return __kingAttacks[from]; | ||
}; | ||
/* tslint:disable:no-bitwise */ | ||
Square.NullSquare = ns; | ||
return Square; | ||
}()); | ||
export { Square }; | ||
} | ||
} | ||
exports.Square = Square; | ||
/* tslint:disable:no-bitwise */ | ||
Square.NullSquare = ns; | ||
//# sourceMappingURL=Square.js.map |
@@ -1,11 +0,24 @@ | ||
export { Intl } from './Intl'; | ||
export { Color } from './chess/Color'; | ||
export { Castle } from './chess/Castle'; | ||
export { Piece } from './chess/Piece'; | ||
export { Square } from './chess/Square'; | ||
export { Move } from './chess/Move'; | ||
export { SimpleMove } from './chess/SimpleMove'; | ||
export { FenString, FenFormat } from './chess/FenString'; | ||
export { Position } from './chess/Position'; | ||
export { Chess } from './chess/Chess'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Intl_1 = require("./Intl"); | ||
exports.Intl = Intl_1.Intl; | ||
var Color_1 = require("./chess/Color"); | ||
exports.Color = Color_1.Color; | ||
var Castle_1 = require("./chess/Castle"); | ||
exports.Castle = Castle_1.Castle; | ||
var Piece_1 = require("./chess/Piece"); | ||
exports.Piece = Piece_1.Piece; | ||
var Square_1 = require("./chess/Square"); | ||
exports.Square = Square_1.Square; | ||
var Move_1 = require("./chess/Move"); | ||
exports.Move = Move_1.Move; | ||
var SimpleMove_1 = require("./chess/SimpleMove"); | ||
exports.SimpleMove = SimpleMove_1.SimpleMove; | ||
var FenString_1 = require("./chess/FenString"); | ||
exports.FenString = FenString_1.FenString; | ||
exports.FenFormat = FenString_1.FenFormat; | ||
var Position_1 = require("./chess/Position"); | ||
exports.Position = Position_1.Position; | ||
var Chess_1 = require("./chess/Chess"); | ||
exports.Chess = Chess_1.Chess; | ||
//# sourceMappingURL=index.js.map |
@@ -1,9 +0,9 @@ | ||
import { Intl as IntlCore } from 'onix-core'; | ||
var Intl = /** @class */ (function () { | ||
function Intl() { | ||
} | ||
Intl.register = function () { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const onix_core_1 = require("onix-core"); | ||
class Intl { | ||
static register() { | ||
if (!Intl.intlInitialized) { | ||
IntlCore.register(); | ||
IntlCore.registerStrings('chess', { | ||
onix_core_1.Intl.register(); | ||
onix_core_1.Intl.registerStrings('chess', { | ||
'ru-ru': { | ||
@@ -46,7 +46,6 @@ fen: "FEN", | ||
} | ||
}; | ||
Intl.intlInitialized = false; | ||
return Intl; | ||
}()); | ||
export { Intl }; | ||
} | ||
} | ||
exports.Intl = Intl; | ||
Intl.intlInitialized = false; | ||
//# sourceMappingURL=Intl.js.map |
{ | ||
"name": "onix-chess", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"description": "Onix chess library", | ||
@@ -12,3 +12,3 @@ "main": "dist/index.js", | ||
"statsp": "webpack --profile --json --mode=production > stats.json", | ||
"test": "mocha --require esm" | ||
"test": "mocha --recursive --require @babel/register --require ./test/helpers.js" | ||
}, | ||
@@ -28,3 +28,3 @@ "keywords": [ | ||
"lodash-es": "^4.17.15", | ||
"onix-core": "^1.7.2", | ||
"onix-core": "^1.8.0", | ||
"shortid": "^2.2.15", | ||
@@ -34,7 +34,9 @@ "warning": "^4.0.3" | ||
"devDependencies": { | ||
"@babel/core": "^7.8.7", | ||
"@babel/preset-env": "^7.8.7", | ||
"@babel/register": "^7.8.6", | ||
"@types/lodash-es": "^4.17.3", | ||
"@types/node": "^13.9.0", | ||
"@types/node": "^13.9.1", | ||
"chai": "^4.2.0", | ||
"clean-webpack-plugin": "^3.0.0", | ||
"esm": "^3.2.25", | ||
"mocha": "^7.1.0", | ||
@@ -41,0 +43,0 @@ "ts-loader": "^6.2.1", |
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
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
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 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
397258
12
7478
Updatedonix-core@^1.8.0