本文整理汇总了TypeScript中chess.js.Chess.load方法的典型用法代码示例。如果您正苦于以下问题:TypeScript js.Chess.load方法的具体用法?TypeScript js.Chess.load怎么用?TypeScript js.Chess.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chess.js.Chess
的用法示例。
在下文中一共展示了js.Chess.load方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: validate
/**
* Validates the given moves, and changes them in place.
* Throws an error if a move is not valid, with an expressive error message.
* @param moves an array of PgnMove
*/
public validate(moves: PgnMove[], startPosition: string): void {
// No moves, no validation
if (moves.length === 0) return
if ( (startPosition === undefined) || (startPosition === null) ) {
startPosition = this.defaultStartPosition()
}
for(let move of moves) {
// Ensure that position before the move is setup
if ( (move.previousMove === null) || (move.previousMove === undefined) ) {
this.chess.load(startPosition)
} else {
this.chess.load(move.previousMove.fen)
}
// Try to make the move, if non-null result, it was successful
let pgnMove = this.chess.move(move.notation, {sloppy: true})
if (pgnMove) {
move.fen = this.chess.fen()
move.notation = pgnMove.san
var currentMoveNumber = PgnReader.getMoveNumberFromPosition(move.fen)
if (move.moveNumber) {
if (move.moveNumber !== currentMoveNumber) {
throw "Wrong move number for " + move.notation
}
}
move.moveNumber = currentMoveNumber
if (this.chess.in_check()) {
move.check = "+"
} else if (this.chess.in_checkmate()) {
move.check = "#"
} else {
move.check = ''
}
if ( (pgnMove.flags == 'c') || (pgnMove.flags == 'e') ) {
move.strike = 'x'
} else {
move.strike = ''
}
this.checkNAGs(move)
// let disam = this.chess.get_disambiguator(PgnMove, true)
// move.disc = disam
} else {
// This is the edge case: something went wrong with the move, so next moves will fail (no FEN)
throw "Notation: " + move.notation + " not valid."
}
}
}
示例2: constructor
/**
* Creates an instance of PgnGame. Is constructed normally be the PgnReader.
* @param config a hash with all parameters given
* @memberOf PGN
*
*/
constructor(pgnMoves: PgnMove[], startPosition: string, result: string, pgnString: string) {
this.chess = new Chess()
this.pgnString = pgnString
this.pgnMoves = pgnMoves
this.result = result
if (pgnString !== undefined) {
this.pgnString = pgnString
}
if ( (startPosition === undefined) || (startPosition === null) ) {
this.chess.reset()
this.startPosition = this.chess.fen()
} else {
this.startPosition = startPosition
this.chess.load(this.startPosition)
}
}
示例3:
// $ExpectType "k"
chess.KING;
// tslint:disable-next-line:max-line-length
// $ExpectType ["a8", "b8", "c8", "d8", "e8", "f8", "g8", "h8", "a7", "b7", "c7", "d7", "e7", "f7", "g7", "h7", "a6", "b6", "c6", "d6", "e6", "f6", "g6", "h6", "a5", "b5", "c5", "d5", "e5", "f5", "g5", "h5", "a4", "b4", "c4", "d4", "e4", "f4", "g4", "h4", "a3", "b3", "c3", "d3", "e3", "f3", "g3", "h3", "a2", "b2", "c2", "d2", "e2", "f2", "g2", "h2", "a1", "b1", "c1", "d1", "e1", "f1", "g1", "h1"]
chess.SQUARES;
// $ExpectType { NORMAL: "n"; CAPTURE: "c"; BIG_PAWN: "b"; EP_CAPTURE: "e"; PROMOTION: "p"; KSIDE_CASTLE: "k"; QSIDE_CASTLE: "q"; }
chess.FLAGS;
// $ExpectType void
chess.reset();
// $ExpectType boolean
chess.load(fen);
// -- moves -- \\
// $ExpectType Move[]
chess.moves({ verbose: true });
// $ExpectType string[]
chess.moves({ verbose: false });
// $ExpectType Move[]
chess.moves({ square: "e2", verbose: true });
// $ExpectType string[]
chess.moves({ square: "e2", verbose: false });