lengyanyu258 / cchessboardjs

This repo will be updated in https://github.com/lengyanyu258/xiangqiboardjs
MIT License
12 stars 7 forks source link

有一个问题 #1

Open cssbee opened 5 years ago

cssbee commented 5 years ago

首先,很完美,很棒! 请问,如何能知道一个棋子正在"将军"状态<意思:对方必须做应对,否则就可以杀死对面的首领> 我找到了game.moves{},这里面只包含一方的moves,不包含另一方,如果能包含另一方,就可以从moves里找到是否包含"将 or 帅"来判断,这个棋子处于 “将军” 状态。 再次感谢伟大的工作!!

lengyanyu258 commented 5 years ago

才发现 xiangqi.js 这个 repo 没有开 Issues :man_facepalming:


现在,你可以用.moves({ verbose: true, opponent: true })去找到对手的照着:

var Xiangqi = require('./xiangqi').Xiangqi;
var xiangqi = new Xiangqi();

xiangqi.load('rnbakab1r/9/1c5c1/p1p1p3p/6p2/6P2/P1P1P1n1P/1C5C1/5K3/RNBA1ABNR r - - 0 1');
xiangqi.in_check();
// true
xiangqi.moves({ verbose: true, opponent: true });
//[ ...
//  { color: 'b',
//    from: 'g3',
//    to: 'f1',
//    flags: 'c',
//    piece: 'n',
//    captured: 'k',
//    iccs: 'g3f1' },
//  ... ]