shogi.js 5.0.0 → 5.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/shogi.d.ts CHANGED
@@ -99,6 +99,10 @@ export declare class Shogi {
99
99
  * keyを種類,valueを枚数とするオブジェクトとして持ち駒の枚数一覧を返す.
100
100
  */
101
101
  getHandsSummary(color: Color): HandSummary;
102
+ /**
103
+ * 現在の局面でcolorの王に王手がかかっているか?
104
+ */
105
+ isCheck(color: Color): boolean;
102
106
  /**
103
107
  * (x, y)の駒を取ってcolorの持ち駒に加える
104
108
  */
package/cjs/shogi.js CHANGED
@@ -310,6 +310,43 @@ var Shogi = /** @class */ (function () {
310
310
  }
311
311
  return ret;
312
312
  };
313
+ /**
314
+ * 現在の局面でcolorの王に王手がかかっているか?
315
+ */
316
+ Shogi.prototype.isCheck = function (color) {
317
+ // colorが違う全てのコマの効きを調べる
318
+ // MEMO: 王様の周りと飛角桂香だけを調べれば高速化できるかも
319
+ var x = null;
320
+ var y = null;
321
+ for (var i = 1; i <= 9; i++) {
322
+ for (var j = 1; j <= 9; j++) {
323
+ var piece = this.get(i, j);
324
+ if (!piece || piece.color !== color) {
325
+ continue;
326
+ }
327
+ if (piece.kind === "OU") {
328
+ x = i;
329
+ y = j;
330
+ }
331
+ }
332
+ }
333
+ if (x === null || y === null) {
334
+ return false;
335
+ }
336
+ for (var i = 1; i <= 9; i++) {
337
+ for (var j = 1; j <= 9; j++) {
338
+ var piece = this.get(i, j);
339
+ if (!piece || piece.color === color) {
340
+ continue;
341
+ }
342
+ var moves = this.getMovesFrom(i, j);
343
+ if (moves.some(function (move) { return move.to.x === x && move.to.y === y; })) {
344
+ return true;
345
+ }
346
+ }
347
+ }
348
+ return false;
349
+ };
313
350
  // 以下editModeでの関数
314
351
  /**
315
352
  * (x, y)の駒を取ってcolorの持ち駒に加える
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shogi.js",
3
- "version": "5.0.0",
3
+ "version": "5.0.2",
4
4
  "description": "simple shogi library for JavaScript",
5
5
  "main": "cjs/shogi.js",
6
6
  "types": "cjs/shogi.d.ts",
@@ -39,5 +39,5 @@
39
39
  "devDependencies": {
40
40
  "ts-jest": "^27.1.3"
41
41
  },
42
- "gitHead": "78f7c3df433b0f9718b099359768c4b149d1b724"
42
+ "gitHead": "0e68aa8bea801db23014c21285033bbcf5ed6019"
43
43
  }