当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript js.Chess.load方法代码示例

本文整理汇总了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."
            }
        }
    }
开发者ID:mliebelt,项目名称:PgnViewerTS,代码行数:52,代码来源:reader.ts

示例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)
     }
 }
开发者ID:mliebelt,项目名称:PgnViewerTS,代码行数:22,代码来源:Game.ts

示例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 });
开发者ID:AlexGalays,项目名称:DefinitelyTyped,代码行数:29,代码来源:chess.js-tests.ts


注:本文中的chess.js.Chess.load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。