shogi.js 2.0.5 → 3.2.0

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/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # Shogi.js (Ver. 2.0) ![Build Status](https://github.com/na2hiro/Shogi.js/actions/workflows/main.yml/badge.svg)
1
+ # Shogi.js ![Build Status](https://github.com/na2hiro/Kifu-for-JS/actions/workflows/main.yml/badge.svg) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/shogi.js.svg)](https://badge.fury.io/js/shogi.js)
2
+
2
3
  将棋の盤駒をモデルとするシンプルなJavaScriptライブラリ.TypeScript.
3
4
 
4
5
  ## インストール
@@ -28,66 +29,14 @@ npm install shogi.js
28
29
 
29
30
  ## Docs
30
31
 
31
- [TypeDoc ドキュメンテーション](http://apps.81.la/Shogi.js/docs/modules.html) を参照のこと。
32
+ [TypeDoc ドキュメンテーション](https://apps.81.la/Kifu-for-JS/shogi.js/docs/) を参照のこと。
32
33
  また,`test`ディレクトリ以下のテストで実際の挙動を確認されたい.
33
34
 
34
- ## TODO
35
- https://github.com/na2hiro/Shogi.js/issues
35
+ ## バグ・要望等
36
+ https://github.com/na2hiro/Kifu-for-JS/issues へお寄せください
36
37
 
37
38
  ## 開発
38
-
39
- ### 準備
40
-
41
- ```shell
42
- $ nvm i && nvm use && npm install
43
- ```
44
-
45
- 上記コマンドを実行することで開発に必要なパッケージをインストールできます.
46
-
47
- * TypeScript
48
- * Webpack (バンドルツール)
49
- * Jest (テストフレームワーク,カバレッジ計測)
50
- * TSLint (Linter)
51
-
52
- ### コマンド
53
-
54
-
55
- ```shell
56
- $ npm run build
57
- $ npm run build:watch
58
- ```
59
-
60
- ビルドが走ります.`build:watch`の場合,変更されるたびにビルドが走ります.
61
-
62
- ```shell
63
- $ npm run test:watch
64
- ```
65
-
66
- コンソールでテスト結果が表示されます.コードの変更が保存されるたびに必要なテストが再実行されるため,実装が既存の有効なテストを壊してないか簡単に確認できます.
67
-
68
- ```shell
69
- $ npm run test
70
- ```
71
-
72
- 全てのテストが走るとともにカバレッジレポートが表示されます.`coverage/lcov-report/index.html`では,行ごとのカバレッジを確認できます.追加されたコードのブランチカバレッジが100%になるようにしてください.push時にチェックされ満たしていなければ却下されるはずです.
73
-
74
- ```shell
75
- $ npm run lint
76
- ```
77
-
78
- コードの品質が検査されます.エラーがあればそれに従い直してください.push前にもチェックされます.
79
-
80
- ```shell
81
- $ npm run lint:fix
82
- ```
83
-
84
- 自動的に修正可能な問題(インデント等)を直してくれます.
85
-
86
- ```shell
87
- $ npm run docs
88
- ```
89
-
90
- `docs/` 以下にドキュメントを生成します.
39
+ [monorepoトップのREADME](../../README.md#開発)をご覧ください。
91
40
 
92
41
  ## license
93
42
 
@@ -14,6 +14,6 @@ declare enum KindEnum {
14
14
  UM = 12,
15
15
  RY = 13
16
16
  }
17
- export declare type Kind = keyof typeof KindEnum;
17
+ export type Kind = keyof typeof KindEnum;
18
18
  export declare const values: Kind[];
19
19
  export {};
@@ -68,7 +68,7 @@ declare const presetDefinitions: {
68
68
  turn: Color;
69
69
  };
70
70
  };
71
- export declare type IPreset = keyof typeof presetDefinitions;
71
+ export type IPreset = keyof typeof presetDefinitions;
72
72
  export declare const getInitialFromPreset: (preset: string) => any;
73
73
  declare const presets: string[];
74
74
  export default presets;
@@ -141,7 +141,7 @@ export declare class Shogi {
141
141
  */
142
142
  private checkTurn;
143
143
  }
144
- declare type HandSummary = {
144
+ type HandSummary = {
145
145
  [K in Extract<Kind, "FU" | "KY" | "KE" | "GI" | "KI" | "KA" | "HI">]: number;
146
146
  };
147
147
  export interface ISettingType {
@@ -167,4 +167,4 @@ export interface IMove {
167
167
  kind?: Kind;
168
168
  color?: Color;
169
169
  }
170
- export { Color, Piece, IMoveDefinition };
170
+ export { Color, Piece, Kind, IMoveDefinition };
package/dist/shogi.js CHANGED
@@ -1,8 +1,2 @@
1
- module.exports=function(t){var o={};function r(e){if(o[e])return o[e].exports;var n=o[e]={i:e,l:!1,exports:{}};return t[e].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=t,r.c=o,r.d=function(t,o,e){r.o(t,o)||Object.defineProperty(t,o,{enumerable:!0,get:e})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,o){if(1&o&&(t=r(t)),8&o)return t;if(4&o&&"object"==typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:t}),2&o&&"string"!=typeof t)for(var n in t)r.d(e,n,function(o){return t[o]}.bind(null,n));return e},r.n=function(t){var o=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(o,"a",o),o},r.o=function(t,o){return Object.prototype.hasOwnProperty.call(t,o)},r.p="",r(r.s=2)}([function(t,o,r){"use strict";var e;o.__esModule=!0,function(t){t[t.Black=0]="Black",t[t.White=1]="White"}(e||(e={})),o.default=e},function(t,o,r){"use strict";o.__esModule=!0;var e=r(0),n=function(){function t(t){this.color="+"===t.slice(0,1)?e.default.Black:e.default.White,this.kind=t.slice(1)}return t.promote=function(t){return{FU:"TO",KY:"NY",KE:"NK",GI:"NG",KA:"UM",HI:"RY"}[t]||t},t.unpromote=function(t){return{TO:"FU",NY:"KY",NK:"KE",NG:"GI",KI:"KI",UM:"KA",RY:"HI",OU:"OU"}[t]||t},t.canPromote=function(o){return t.promote(o)!==o},t.isPromoted=function(t){return["TO","NY","NK","NG","UM","RY"].indexOf(t)>=0},t.oppositeColor=function(t){return t===e.default.Black?e.default.White:e.default.Black},t.fromSFENString=function(o){var r="+"===o[0];r&&(o=o.slice(1));var e=new t((o.match(/[A-Z]/)?"+":"-")+{P:"FU",L:"KY",N:"KE",S:"GI",G:"KI",B:"KA",R:"HI",K:"OU"}[o.toUpperCase()]);return r&&e.promote(),e},t.prototype.promote=function(){this.kind=t.promote(this.kind)},t.prototype.unpromote=function(){this.kind=t.unpromote(this.kind)},t.prototype.inverse=function(){this.color=this.color===e.default.Black?e.default.White:e.default.Black},t.prototype.toCSAString=function(){return(this.color===e.default.Black?"+":"-")+this.kind},t.prototype.toSFENString=function(){var o={FU:"P",KY:"L",KE:"N",GI:"S",KI:"G",KA:"B",HI:"R",OU:"K"}[t.unpromote(this.kind)];return(t.isPromoted(this.kind)?"+":"")+(this.color===e.default.Black?o:o.toLowerCase())},t}();o.default=n},function(t,o,r){"use strict";o.__esModule=!0,o.Piece=o.Color=o.Shogi=void 0;
2
- /** @license
3
- * Shogi.js
4
- * Copyright (c) 2014 na2hiro (https://github.com/na2hiro)
5
- * This software is released under the MIT License.
6
- * http://opensource.org/licenses/mit-license.php
7
- */
8
- var e=r(0);o.Color=e.default;var n=r(3),i=r(1);o.Piece=i.default,r(4);var u=r(5),a=function(){function t(t){this.initialize(t)}return t.getIllegalUnpromotedRow=function(t){switch(t){case"FU":case"KY":return 1;case"KE":return 2;default:return 0}},t.getRowToOppositeEnd=function(t,o){return o===e.default.Black?t:10-t},t.prototype.initialize=function(t){void 0===t&&(t={preset:"HIRATE"}),u.fromPreset(this,t),this.flagEditMode=!1},t.prototype.initializeFromSFENString=function(t){u.fromSfen(this,t)},t.prototype.toCSAString=function(){return u.toCSA(this)},t.prototype.toSFENString=function(t){return void 0===t&&(t=1),u.toSfen(this,t)},t.prototype.editMode=function(t){this.flagEditMode=t},t.prototype.move=function(o,r,e,n,i){void 0===i&&(i=!1);var u=this.get(o,r);if(null==u)throw new Error("no piece found at "+o+", "+r);if(this.checkTurn(u.color),!this.flagEditMode&&!this.getMovesFrom(o,r).some((function(t){return t.to.x===e&&t.to.y===n})))throw new Error("cannot move from "+o+", "+r+" to "+e+", "+n);null!=this.get(e,n)&&this.capture(e,n);var a=t.getIllegalUnpromotedRow(u.kind)>=t.getRowToOppositeEnd(n,u.color);(i||a)&&u.promote(),this.set(e,n,u),this.set(o,r,null),this.nextTurn()},t.prototype.unmove=function(t,o,r,e,n,u){void 0===n&&(n=!1);var a,f=this.get(r,e);if(null==f)throw new Error("no piece found at "+r+", "+e);this.checkTurn(i.default.oppositeColor(f.color)),u&&(a=this.popFromHand(i.default.unpromote(u),f.color)).inverse();var s=this.flagEditMode;this.editMode(!0),this.move(r,e,t,o),n&&f.unpromote(),u&&(i.default.isPromoted(u)&&a.promote(),this.set(r,e,a)),this.editMode(s),this.prevTurn()},t.prototype.drop=function(t,o,r,e){if(void 0===e&&(e=this.turn),this.checkTurn(e),null!=this.get(t,o))throw new Error("there is a piece at "+t+", "+o);if(!this.getDropsBy(e).some((function(e){return e.to.x===t&&e.to.y===o&&e.kind===r})))throw new Error("Cannot move");var n=this.popFromHand(r,e);this.set(t,o,n),this.nextTurn()},t.prototype.undrop=function(t,o){var r=this.get(t,o);if(null==r)throw new Error("there is no piece at "+t+", "+o);this.checkTurn(i.default.oppositeColor(r.color)),this.pushToHand(r),this.set(t,o,null),this.prevTurn()},t.prototype.getMovesFrom=function(t,o){var r=function(t,o,r){if(t<1||9<t||o<1||9<o)return!1;var e=this.get(t,o);return null==e||e.color!==r}.bind(this),i=function(t,o,r){var e=this.get(t,o);return null!=e&&e.color!==r}.bind(this),u=this.get(t,o);if(null==u)return[];var a=n.getMoveDefinitions(u.kind),f=[],s={x:t,y:o},l=u.color===e.default.Black?1:-1;if(a.just)for(var d=0,c=a.just;d<c.length;d++){var h=c[d];r((K={x:s.x+h[0]*l,y:s.y+h[1]*l}).x,K.y,u.color)&&f.push({from:s,to:K})}if(a.fly)for(var p=0,v=a.fly;p<v.length;p++){h=v[p];for(var K={x:s.x+h[0]*l,y:s.y+h[1]*l};r(K.x,K.y,u.color)&&(f.push({from:s,to:{x:K.x,y:K.y}}),!i(K.x,K.y,u.color));)K.x+=h[0]*l,K.y+=h[1]*l}return f},t.prototype.getDropsBy=function(o){for(var r=[],e=[],n=[],i=1;i<=9;i++){for(var u=!1,a=1;a<=9;a++){var f=this.get(i,a);null==f?e.push({x:i,y:a}):f.color===o&&"FU"===f.kind&&(u=!0)}n.push(u)}for(var s={},l=0,d=this.hands[o];l<d.length;l++){var c=d[l].kind;if(!s[c]){s[c]=!0;for(var h=t.getIllegalUnpromotedRow(c),p=0,v=e;p<v.length;p++){var K=v[p];"FU"===c&&n[K.x-1]||(h>=t.getRowToOppositeEnd(K.y,o)||r.push({to:K,color:o,kind:c}))}}}return r},t.prototype.getMovesTo=function(t,o,r,e){void 0===e&&(e=this.turn);for(var n={x:t,y:o},i=[],u=1;u<=9;u++)for(var a=1;a<=9;a++){var f=this.get(u,a);if(f&&f.kind===r&&f.color===e)this.getMovesFrom(u,a).some((function(r){return r.to.x===t&&r.to.y===o}))&&i.push({from:{x:u,y:a},to:n})}return i},t.prototype.get=function(t,o){return this.board[t-1][o-1]},t.prototype.getHandsSummary=function(t){for(var o={FU:0,KY:0,KE:0,GI:0,KI:0,KA:0,HI:0},r=0,e=this.hands[t];r<e.length;r++){o[e[r].kind]++}return o},t.prototype.captureByColor=function(t,o,r){if(!this.flagEditMode)throw new Error("cannot edit board without editMode");var e=this.get(t,o);this.set(t,o,null),e.unpromote(),e.color!==r&&e.inverse(),this.pushToHand(e)},t.prototype.flip=function(t,o){if(!this.flagEditMode)throw new Error("cannot edit board without editMode");var r=this.get(t,o);return!!r&&(i.default.isPromoted(r.kind)?(r.unpromote(),r.inverse()):i.default.canPromote(r.kind)?r.promote():r.inverse(),!0)},t.prototype.setTurn=function(t){if(!this.flagEditMode)throw new Error("cannot set turn without editMode");this.turn=t},t.prototype.set=function(t,o,r){this.board[t-1][o-1]=r},t.prototype.capture=function(t,o){var r=this.get(t,o);this.set(t,o,null),r.unpromote(),r.inverse(),this.pushToHand(r)},t.prototype.pushToHand=function(t){this.hands[t.color].push(t)},t.prototype.popFromHand=function(t,o){for(var r=this.hands[o],e=0;e<r.length;e++)if(r[e].kind===t){var n=r[e];return r.splice(e,1),n}throw new Error(o+" has no "+t)},t.prototype.nextTurn=function(){this.flagEditMode||(this.turn=this.turn===e.default.Black?e.default.White:e.default.Black)},t.prototype.prevTurn=function(){this.flagEditMode||this.nextTurn()},t.prototype.checkTurn=function(t){if(!this.flagEditMode&&t!==this.turn)throw new Error("cannot move opposite piece")},t}();o.Shogi=a},function(t,o,r){"use strict";o.__esModule=!0,o.getMoveDefinitions=void 0;var e=[0,-1],n=[0,1],i=[1,0],u=[-1,0],a=[-1,-1],f=[1,-1],s=[-1,1],l=[1,1],d={just:[a,e,f,u,i,n]},c={FU:{just:[e]},KY:{fly:[e]},KE:{just:[[-1,-2],[1,-2]]},GI:{just:[a,e,f,s,l]},KI:d,TO:d,NY:d,NK:d,NG:d,KA:{fly:[a,f,s,l]},HI:{fly:[e,u,i,n]},OU:{just:[a,e,f,u,i,s,n,l]},UM:{fly:[a,f,s,l],just:[e,u,i,n]},RY:{fly:[e,u,i,n],just:[a,f,s,l]}};o.getMoveDefinitions=function(t){return c[t]}},function(t,o,r){"use strict";o.__esModule=!0,Array.prototype.some||(Array.prototype.some=function(t){if(null==this)throw new TypeError;var o=Object(this),r=o.length>>>0;if("function"!=typeof t)throw new TypeError;for(var e=arguments[1],n=0;n<r;n++)if(n in o&&t.call(e,o[n],n,o))return!0;return!1})},function(t,o,r){"use strict";o.__esModule=!0,o.toSfen=o.fromSfen=o.toCSA=o.fromPreset=void 0;var e=r(0),n=r(6),i=r(1);o.fromPreset=function(t,o){var r,u=[],a=[[],[]];if("OTHER"!==o.preset){for(var f=n.getInitialFromPreset(o.preset),s=0;s<9;s++){u[s]=[];for(var l=0;l<9;l++){var d=f.board[l].slice(24-3*s,24-3*s+3);u[s][l]=" * "===d?null:new i.default(d)}}r=f.turn}else{for(s=0;s<9;s++){u[s]=[];for(l=0;l<9;l++){var c=o.data.board[s][l];u[s][l]=c.kind?new i.default((c.color===e.default.Black?"+":"-")+c.kind):null}}r=o.data.color;for(var h=0;h<2;h++)for(var p in o.data.hands[h])if(o.data.hands[h].hasOwnProperty(p))for(d=(0===h?"+":"-")+p,s=0;s<o.data.hands[h][p];s++)a[h].push(new i.default(d))}t.board=u,t.turn=r,t.hands=a},o.toCSA=function(t){for(var o=[],r=0;r<9;r++){for(var n="P"+(r+1),i=8;i>=0;i--){var u=t.board[i][r];n+=null==u?" * ":u.toCSAString()}o.push(n)}for(var a=0;a<2;a++){n="P"+"+-"[a];for(var f=0,s=t.hands[a];f<s.length;f++){n+="00"+s[f].kind}o.push(n)}return o.push(t.turn===e.default.Black?"+":"-"),o.join("\n")},o.fromSfen=function(t,o){for(var r=[],n=0;n<9;n++){r[n]=[];for(var u=0;u<9;u++)r[n][u]=null}var a=o.split(" "),f=a[0],s=8,l=0;for(n=0;n<f.length;n++){var d=f[n];"+"===d&&(d+=f[++n]),d.match(/^[1-9]$/)?s-=Number(d):"/"===d?(l++,s=8):(r[s][l]=i.default.fromSFENString(d),s--)}t.board=r,t.turn="b"===a[1]?e.default.Black:e.default.White;var c=[[],[]],h=a[2];if("-"!==h)for(;h.length>0;){var p=1,v=h.match(/^[0-9]+/);v&&(p=Number(v[0]),h=h.slice(v[0].length));for(n=0;n<p;n++){var K=i.default.fromSFENString(h[0]);c[K.color].push(K)}h=h.slice(1)}t.hands=c},o.toSfen=function(t,o){for(var r=[],n=[],i=0;i<9;i++){for(var u="",a=0,f=8;f>=0;f--){var s=t.board[f][i];null==s?a++:(a>0&&(u+=""+a,a=0),u+=s.toSFENString())}a>0&&(u+=""+a),n.push(u)}if(r.push(n.join("/")),r.push(t.turn===e.default.Black?"b":"w"),0===t.hands[0].length&&0===t.hands[1].length)r.push("-");else{for(var l="",d={},c=0;c<2;c++)for(var h=0,p=t.hands[c];h<p.length;h++){var v=p[h].toSFENString();d[v]=(d[v]||0)+1}for(var K=0,I=["R","B","G","S","N","L","P","r","b","g","s","n","l","p"];K<I.length;K++){var g=I[K];d[g]>0&&(l+=(d[g]>1?d[g]:"")+g)}r.push(l)}return r.push(""+o),r.join(" ")}},function(t,o,r){"use strict";o.__esModule=!0,o.getInitialFromPreset=void 0;var e=r(0),n=" * * * * * * * * * ",i=["-FU-FU-FU-FU-FU-FU-FU-FU-FU",n,n,n,"+FU+FU+FU+FU+FU+FU+FU+FU+FU"," * +KA * * * * * +HI * ","+KY+KE+GI+KI+OU+KI+GI+KE+KY"],u=[n].concat(i),a={HIRATE:{board:["-KY-KE-GI-KI-OU-KI-GI-KE-KY"," * -HI * * * * * -KA * "].concat(i),turn:e.default.Black},KY:{board:["-KY-KE-GI-KI-OU-KI-GI-KE * "," * -HI * * * * * -KA * "].concat(i),turn:e.default.White},KY_R:{board:[" * -KE-GI-KI-OU-KI-GI-KE-KY"," * -HI * * * * * -KA * "].concat(i),turn:e.default.White},KA:{board:["-KY-KE-GI-KI-OU-KI-GI-KE-KY"," * -HI * * * * * * * "].concat(i),turn:e.default.White},HI:{board:["-KY-KE-GI-KI-OU-KI-GI-KE-KY"," * * * * * * * -KA * "].concat(i),turn:e.default.White},HIKY:{board:["-KY-KE-GI-KI-OU-KI-GI-KE * "," * * * * * * * -KA * "].concat(i),turn:e.default.White},2:{board:["-KY-KE-GI-KI-OU-KI-GI-KE-KY"].concat(u),turn:e.default.White},3:{board:["-KY-KE-GI-KI-OU-KI-GI-KE * "].concat(u),turn:e.default.White},4:{board:[" * -KE-GI-KI-OU-KI-GI-KE * "].concat(u),turn:e.default.White},5:{board:[" * * -GI-KI-OU-KI-GI-KE * "].concat(u),turn:e.default.White},"5_L":{board:[" * -KE-GI-KI-OU-KI-GI * * "].concat(u),turn:e.default.White},6:{board:[" * * -GI-KI-OU-KI-GI * * "].concat(u),turn:e.default.White},"7_R":{board:[" * * * -KI-OU-KI-GI * * "].concat(u),turn:e.default.White},"7_L":{board:[" * * -GI-KI-OU-KI * * * "].concat(u),turn:e.default.White},8:{board:[" * * * -KI-OU-KI * * * "].concat(u),turn:e.default.White},10:{board:[" * * * * -OU * * * * "].concat(u),turn:e.default.White}};o.getInitialFromPreset=function(t){var o=a[t];if(!o)throw new Error("Unknown preset: "+t);return o};var f=Object.keys(a);o.default=f}]);
1
+ /*! For license information please see shogi.js.LICENSE.txt */
2
+ (()=>{"use strict";var t={371:(t,o)=>{var r;Object.defineProperty(o,"__esModule",{value:!0}),function(t){t[t.Black=0]="Black",t[t.White=1]="White"}(r||(r={})),o.default=r},51:(t,o,r)=>{Object.defineProperty(o,"__esModule",{value:!0});var e=r(371),n=function(){function t(t){this.color="+"===t.slice(0,1)?e.default.Black:e.default.White,this.kind=t.slice(1)}return t.promote=function(t){return{FU:"TO",KY:"NY",KE:"NK",GI:"NG",KA:"UM",HI:"RY"}[t]||t},t.unpromote=function(t){return{TO:"FU",NY:"KY",NK:"KE",NG:"GI",KI:"KI",UM:"KA",RY:"HI",OU:"OU"}[t]||t},t.canPromote=function(o){return t.promote(o)!==o},t.isPromoted=function(t){return["TO","NY","NK","NG","UM","RY"].indexOf(t)>=0},t.oppositeColor=function(t){return t===e.default.Black?e.default.White:e.default.Black},t.fromSFENString=function(o){var r="+"===o[0];r&&(o=o.slice(1));var e=new t((o.match(/[A-Z]/)?"+":"-")+{P:"FU",L:"KY",N:"KE",S:"GI",G:"KI",B:"KA",R:"HI",K:"OU"}[o.toUpperCase()]);return r&&e.promote(),e},t.prototype.promote=function(){this.kind=t.promote(this.kind)},t.prototype.unpromote=function(){this.kind=t.unpromote(this.kind)},t.prototype.inverse=function(){this.color=this.color===e.default.Black?e.default.White:e.default.Black},t.prototype.toCSAString=function(){return(this.color===e.default.Black?"+":"-")+this.kind},t.prototype.toSFENString=function(){var o={FU:"P",KY:"L",KE:"N",GI:"S",KI:"G",KA:"B",HI:"R",OU:"K"}[t.unpromote(this.kind)];return(t.isPromoted(this.kind)?"+":"")+(this.color===e.default.Black?o:o.toLowerCase())},t}();o.default=n},297:(t,o,r)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.toSfen=o.fromSfen=o.toCSA=o.fromPreset=void 0;var e=r(371),n=r(446),i=r(51);o.fromPreset=function(t,o){var r,a=[],u=[[],[]];if("OTHER"!==o.preset){for(var f=(0,n.getInitialFromPreset)(o.preset),s=0;s<9;s++){a[s]=[];for(var l=0;l<9;l++){var d=f.board[l].slice(24-3*s,24-3*s+3);a[s][l]=" * "===d?null:new i.default(d)}}r=f.turn}else{for(s=0;s<9;s++)for(a[s]=[],l=0;l<9;l++){var h=o.data.board[s][l];a[s][l]=h.kind?new i.default((h.color===e.default.Black?"+":"-")+h.kind):null}r=o.data.color;for(var c=0;c<2;c++)for(var p in o.data.hands[c])if(o.data.hands[c].hasOwnProperty(p))for(d=(0===c?"+":"-")+p,s=0;s<o.data.hands[c][p];s++)u[c].push(new i.default(d))}t.board=a,t.turn=r,t.hands=u},o.toCSA=function(t){for(var o=[],r=0;r<9;r++){for(var n="P"+(r+1),i=8;i>=0;i--){var a=t.board[i][r];n+=null==a?" * ":a.toCSAString()}o.push(n)}for(var u=0;u<2;u++){n="P"+"+-"[u];for(var f=0,s=t.hands[u];f<s.length;f++)n+="00"+s[f].kind;o.push(n)}return o.push(t.turn===e.default.Black?"+":"-"),o.join("\n")},o.fromSfen=function(t,o){for(var r=[],n=0;n<9;n++){r[n]=[];for(var a=0;a<9;a++)r[n][a]=null}var u=o.split(" "),f=u[0],s=8,l=0;for(n=0;n<f.length;n++){var d=f[n];"+"===d&&(d+=f[++n]),d.match(/^[1-9]$/)?s-=Number(d):"/"===d?(l++,s=8):(r[s][l]=i.default.fromSFENString(d),s--)}t.board=r,t.turn="b"===u[1]?e.default.Black:e.default.White;var h=[[],[]],c=u[2];if("-"!==c)for(;c.length>0;){var p=1,v=c.match(/^[0-9]+/);for(v&&(p=Number(v[0]),c=c.slice(v[0].length)),n=0;n<p;n++){var K=i.default.fromSFENString(c[0]);h[K.color].push(K)}c=c.slice(1)}t.hands=h},o.toSfen=function(t,o){for(var r=[],n=[],i=0;i<9;i++){for(var a="",u=0,f=8;f>=0;f--){var s=t.board[f][i];null==s?u++:(u>0&&(a+=""+u,u=0),a+=s.toSFENString())}u>0&&(a+=""+u),n.push(a)}if(r.push(n.join("/")),r.push(t.turn===e.default.Black?"b":"w"),0===t.hands[0].length&&0===t.hands[1].length)r.push("-");else{for(var l="",d={},h=0;h<2;h++)for(var c=0,p=t.hands[h];c<p.length;c++){var v=p[c].toSFENString();d[v]=(d[v]||0)+1}for(var K=0,I=["R","B","G","S","N","L","P","r","b","g","s","n","l","p"];K<I.length;K++){var g=I[K];d[g]>0&&(l+=(d[g]>1?d[g]:"")+g)}r.push(l)}return r.push(""+o),r.join(" ")}},333:(t,o)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.getMoveDefinitions=void 0;var r=[0,-1],e=[0,1],n=[1,0],i=[-1,0],a=[-1,-1],u=[1,-1],f=[-1,1],s=[1,1],l={just:[a,r,u,i,n,e]},d={FU:{just:[r]},KY:{fly:[r]},KE:{just:[[-1,-2],[1,-2]]},GI:{just:[a,r,u,f,s]},KI:l,TO:l,NY:l,NK:l,NG:l,KA:{fly:[a,u,f,s]},HI:{fly:[r,i,n,e]},OU:{just:[a,r,u,i,n,f,e,s]},UM:{fly:[a,u,f,s],just:[r,i,n,e]},RY:{fly:[r,i,n,e],just:[a,u,f,s]}};o.getMoveDefinitions=function(t){return d[t]}},31:(t,o)=>{Object.defineProperty(o,"__esModule",{value:!0}),Array.prototype.some||(Array.prototype.some=function(t){if(null==this)throw new TypeError;var o=Object(this),r=o.length>>>0;if("function"!=typeof t)throw new TypeError;for(var e=arguments[1],n=0;n<r;n++)if(n in o&&t.call(e,o[n],n,o))return!0;return!1})},446:(t,o,r)=>{Object.defineProperty(o,"__esModule",{value:!0}),o.getInitialFromPreset=void 0;var e=r(371),n=" * * * * * * * * * ",i=["-FU-FU-FU-FU-FU-FU-FU-FU-FU",n,n,n,"+FU+FU+FU+FU+FU+FU+FU+FU+FU"," * +KA * * * * * +HI * ","+KY+KE+GI+KI+OU+KI+GI+KE+KY"],a=[n].concat(i),u={HIRATE:{board:["-KY-KE-GI-KI-OU-KI-GI-KE-KY"," * -HI * * * * * -KA * "].concat(i),turn:e.default.Black},KY:{board:["-KY-KE-GI-KI-OU-KI-GI-KE * "," * -HI * * * * * -KA * "].concat(i),turn:e.default.White},KY_R:{board:[" * -KE-GI-KI-OU-KI-GI-KE-KY"," * -HI * * * * * -KA * "].concat(i),turn:e.default.White},KA:{board:["-KY-KE-GI-KI-OU-KI-GI-KE-KY"," * -HI * * * * * * * "].concat(i),turn:e.default.White},HI:{board:["-KY-KE-GI-KI-OU-KI-GI-KE-KY"," * * * * * * * -KA * "].concat(i),turn:e.default.White},HIKY:{board:["-KY-KE-GI-KI-OU-KI-GI-KE * "," * * * * * * * -KA * "].concat(i),turn:e.default.White},2:{board:["-KY-KE-GI-KI-OU-KI-GI-KE-KY"].concat(a),turn:e.default.White},3:{board:["-KY-KE-GI-KI-OU-KI-GI-KE * "].concat(a),turn:e.default.White},4:{board:[" * -KE-GI-KI-OU-KI-GI-KE * "].concat(a),turn:e.default.White},5:{board:[" * * -GI-KI-OU-KI-GI-KE * "].concat(a),turn:e.default.White},"5_L":{board:[" * -KE-GI-KI-OU-KI-GI * * "].concat(a),turn:e.default.White},6:{board:[" * * -GI-KI-OU-KI-GI * * "].concat(a),turn:e.default.White},"7_R":{board:[" * * * -KI-OU-KI-GI * * "].concat(a),turn:e.default.White},"7_L":{board:[" * * -GI-KI-OU-KI * * * "].concat(a),turn:e.default.White},8:{board:[" * * * -KI-OU-KI * * * "].concat(a),turn:e.default.White},10:{board:[" * * * * -OU * * * * "].concat(a),turn:e.default.White}};o.getInitialFromPreset=function(t){var o=u[t];if(!o)throw new Error("Unknown preset: ".concat(t));return o};var f=Object.keys(u);o.default=f}},o={};function r(e){var n=o[e];if(void 0!==n)return n.exports;var i=o[e]={exports:{}};return t[e](i,i.exports,r),i.exports}var e={};(()=>{var t=e;Object.defineProperty(t,"__esModule",{value:!0}),t.Piece=t.Color=t.Shogi=void 0;var o=r(371);t.Color=o.default;var n=r(333),i=r(51);t.Piece=i.default,r(31);var a=r(297),u=function(){function t(t){this.initialize(t)}return t.getIllegalUnpromotedRow=function(t){switch(t){case"FU":case"KY":return 1;case"KE":return 2;default:return 0}},t.getRowToOppositeEnd=function(t,r){return r===o.default.Black?t:10-t},t.prototype.initialize=function(t){void 0===t&&(t={preset:"HIRATE"}),(0,a.fromPreset)(this,t),this.flagEditMode=!1},t.prototype.initializeFromSFENString=function(t){(0,a.fromSfen)(this,t)},t.prototype.toCSAString=function(){return(0,a.toCSA)(this)},t.prototype.toSFENString=function(t){return void 0===t&&(t=1),(0,a.toSfen)(this,t)},t.prototype.editMode=function(t){this.flagEditMode=t},t.prototype.move=function(o,r,e,n,i){void 0===i&&(i=!1);var a=this.get(o,r);if(null==a)throw new Error("no piece found at "+o+", "+r);if(this.checkTurn(a.color),!this.flagEditMode&&!this.getMovesFrom(o,r).some((function(t){return t.to.x===e&&t.to.y===n})))throw new Error("cannot move from "+o+", "+r+" to "+e+", "+n);null!=this.get(e,n)&&this.capture(e,n);var u=t.getIllegalUnpromotedRow(a.kind)>=t.getRowToOppositeEnd(n,a.color);(i||u)&&a.promote(),this.set(e,n,a),this.set(o,r,null),this.nextTurn()},t.prototype.unmove=function(t,o,r,e,n,a){void 0===n&&(n=!1);var u,f=this.get(r,e);if(null==f)throw new Error("no piece found at "+r+", "+e);this.checkTurn(i.default.oppositeColor(f.color)),a&&(u=this.popFromHand(i.default.unpromote(a),f.color)).inverse();var s=this.flagEditMode;this.editMode(!0),this.move(r,e,t,o),n&&f.unpromote(),a&&(i.default.isPromoted(a)&&u.promote(),this.set(r,e,u)),this.editMode(s),this.prevTurn()},t.prototype.drop=function(t,o,r,e){if(void 0===e&&(e=this.turn),this.checkTurn(e),null!=this.get(t,o))throw new Error("there is a piece at "+t+", "+o);if(!this.getDropsBy(e).some((function(e){return e.to.x===t&&e.to.y===o&&e.kind===r})))throw new Error("Cannot move");var n=this.popFromHand(r,e);this.set(t,o,n),this.nextTurn()},t.prototype.undrop=function(t,o){var r=this.get(t,o);if(null==r)throw new Error("there is no piece at "+t+", "+o);this.checkTurn(i.default.oppositeColor(r.color)),this.pushToHand(r),this.set(t,o,null),this.prevTurn()},t.prototype.getMovesFrom=function(t,r){var e=function(t,o,r){if(t<1||9<t||o<1||9<o)return!1;var e=this.get(t,o);return null==e||e.color!==r}.bind(this),i=function(t,o,r){var e=this.get(t,o);return null!=e&&e.color!==r}.bind(this),a=this.get(t,r);if(null==a)return[];var u=(0,n.getMoveDefinitions)(a.kind),f=[],s={x:t,y:r},l=a.color===o.default.Black?1:-1;if(u.just)for(var d=0,h=u.just;d<h.length;d++){var c=h[d];e((K={x:s.x+c[0]*l,y:s.y+c[1]*l}).x,K.y,a.color)&&f.push({from:s,to:K})}if(u.fly)for(var p=0,v=u.fly;p<v.length;p++){c=v[p];for(var K={x:s.x+c[0]*l,y:s.y+c[1]*l};e(K.x,K.y,a.color)&&(f.push({from:s,to:{x:K.x,y:K.y}}),!i(K.x,K.y,a.color));)K.x+=c[0]*l,K.y+=c[1]*l}return f},t.prototype.getDropsBy=function(o){for(var r=[],e=[],n=[],i=1;i<=9;i++){for(var a=!1,u=1;u<=9;u++){var f=this.get(i,u);null==f?e.push({x:i,y:u}):f.color===o&&"FU"===f.kind&&(a=!0)}n.push(a)}for(var s={},l=0,d=this.hands[o];l<d.length;l++){var h=d[l].kind;if(!s[h]){s[h]=!0;for(var c=t.getIllegalUnpromotedRow(h),p=0,v=e;p<v.length;p++){var K=v[p];"FU"===h&&n[K.x-1]||c>=t.getRowToOppositeEnd(K.y,o)||r.push({to:K,color:o,kind:h})}}}return r},t.prototype.getMovesTo=function(t,o,r,e){void 0===e&&(e=this.turn);for(var n={x:t,y:o},i=[],a=1;a<=9;a++)for(var u=1;u<=9;u++){var f=this.get(a,u);f&&f.kind===r&&f.color===e&&this.getMovesFrom(a,u).some((function(r){return r.to.x===t&&r.to.y===o}))&&i.push({from:{x:a,y:u},to:n})}return i},t.prototype.get=function(t,o){return this.board[t-1][o-1]},t.prototype.getHandsSummary=function(t){for(var o={FU:0,KY:0,KE:0,GI:0,KI:0,KA:0,HI:0},r=0,e=this.hands[t];r<e.length;r++)o[e[r].kind]++;return o},t.prototype.captureByColor=function(t,o,r){if(!this.flagEditMode)throw new Error("cannot edit board without editMode");var e=this.get(t,o);this.set(t,o,null),e.unpromote(),e.color!==r&&e.inverse(),this.pushToHand(e)},t.prototype.flip=function(t,o){if(!this.flagEditMode)throw new Error("cannot edit board without editMode");var r=this.get(t,o);return!!r&&(i.default.isPromoted(r.kind)?(r.unpromote(),r.inverse()):i.default.canPromote(r.kind)?r.promote():r.inverse(),!0)},t.prototype.setTurn=function(t){if(!this.flagEditMode)throw new Error("cannot set turn without editMode");this.turn=t},t.prototype.set=function(t,o,r){this.board[t-1][o-1]=r},t.prototype.capture=function(t,o){var r=this.get(t,o);this.set(t,o,null),r.unpromote(),r.inverse(),this.pushToHand(r)},t.prototype.pushToHand=function(t){this.hands[t.color].push(t)},t.prototype.popFromHand=function(t,o){for(var r=this.hands[o],e=0;e<r.length;e++)if(r[e].kind===t){var n=r[e];return r.splice(e,1),n}throw new Error(o+" has no "+t)},t.prototype.nextTurn=function(){this.flagEditMode||(this.turn=this.turn===o.default.Black?o.default.White:o.default.Black)},t.prototype.prevTurn=function(){this.flagEditMode||this.nextTurn()},t.prototype.checkTurn=function(t){if(!this.flagEditMode&&t!==this.turn)throw new Error("cannot move opposite piece")},t}();t.Shogi=u})(),module.exports=e})();
@@ -0,0 +1,6 @@
1
+ /** @license
2
+ * Shogi.js
3
+ * Copyright (c) 2014 na2hiro (https://github.com/na2hiro)
4
+ * This software is released under the MIT License.
5
+ * http://opensource.org/licenses/mit-license.php
6
+ */
package/package.json CHANGED
@@ -1,61 +1,41 @@
1
1
  {
2
- "name": "shogi.js",
3
- "version": "2.0.5",
4
- "description": "simple shogi library for JavaScript",
5
- "main": "dist/shogi.js",
6
- "types": "dist/src/shogi.d.ts",
7
- "directories": {
8
- "test": "test"
9
- },
10
- "scripts": {
11
- "build": "webpack --mode=production -p",
12
- "build:analyze": "webpack --mode=production -p --env.analyze",
13
- "build:watch": "webpack --mode=development --watch",
14
- "lint": "eslint ./ && prettier --check .",
15
- "lint:fix": "eslint ./ --fix && prettier --write .",
16
- "test": "jest",
17
- "test:watch": "jest --watch",
18
- "typecheck": "tsc --project tsconfig.json --noEmit",
19
- "prepublishOnly": "npm run build",
20
- "docs": "typedoc --exclude '**/__tests__/**/*' ./src/shogi.ts",
21
- "deploy:ghpages": "rm -rf ./public && mkdir -p ./public && npm run docs && mv ./docs ./public/"
22
- },
23
- "repository": {
24
- "type": "git",
25
- "url": "git+https://github.com/na2hiro/Shogi.js.git"
26
- },
27
- "keywords": [
28
- "shogi",
29
- "library"
30
- ],
31
- "author": "na2hiro",
32
- "license": "MIT",
33
- "bugs": {
34
- "url": "https://github.com/na2hiro/Shogi.js/issues"
35
- },
36
- "homepage": "https://github.com/na2hiro/Shogi.js#readme",
37
- "devDependencies": {
38
- "@types/jest": "^22.2.0",
39
- "@typescript-eslint/eslint-plugin": "^5.9.0",
40
- "@typescript-eslint/parser": "^5.9.0",
41
- "clean-webpack-plugin": "^0.1.19",
42
- "eslint": "^8.6.0",
43
- "eslint-config-prettier": "^8.3.0",
44
- "eslint-plugin-jest": "^25.3.4",
45
- "jest": "^26.1.0",
46
- "pre-push": "^0.1.1",
47
- "prettier": "^2.5.1",
48
- "ts-jest": "^26.4.3",
49
- "ts-loader": "^4.3.1",
50
- "typedoc": "^0.20.35",
51
- "typescript": "^4.0.5",
52
- "webpack": "^4.43.0",
53
- "webpack-bundle-analyzer": "^3.8.0",
54
- "webpack-cli": "^3.3.11",
55
- "webpack-merge": "^4.1.2"
56
- },
57
- "pre-push": [
58
- "lint",
59
- "test"
60
- ]
2
+ "name": "shogi.js",
3
+ "version": "3.2.0",
4
+ "description": "simple shogi library for JavaScript",
5
+ "main": "dist/shogi.js",
6
+ "types": "dist/src/shogi.d.ts",
7
+ "directories": {
8
+ "test": "test"
9
+ },
10
+ "scripts": {
11
+ "clean": "rm -rf ./dist ./bundle",
12
+ "build": "webpack --mode=production",
13
+ "build:analyze": "webpack --mode=production --env analyze=1",
14
+ "build:watch": "webpack --mode=development --watch",
15
+ "lint": "eslint ./ && prettier --check .",
16
+ "lint:fix": "eslint ./ --fix && prettier --write .",
17
+ "test": "jest",
18
+ "test:watch": "jest --watch",
19
+ "typecheck": "tsc --project tsconfig.typecheck.json",
20
+ "docs": "typedoc --exclude '**/__tests__/**/*' ./src/shogi.ts",
21
+ "ghpages": "rm -rf ./public && mkdir -p ./public && npm run docs && mv ./docs ./public/"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/na2hiro/Shogi.js.git"
26
+ },
27
+ "keywords": [
28
+ "shogi",
29
+ "library"
30
+ ],
31
+ "author": "na2hiro",
32
+ "license": "MIT",
33
+ "bugs": {
34
+ "url": "https://github.com/na2hiro/Shogi.js/issues"
35
+ },
36
+ "homepage": "https://github.com/na2hiro/Kifu-for-JS/tree/master/packages/shogi.js#readme",
37
+ "devDependencies": {
38
+ "ts-jest": "^27.1.3"
39
+ },
40
+ "gitHead": "860fe96a8510c946576f8bb984f4d98a81eba1fe"
61
41
  }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "declaration": false,
5
+ "module": "commonjs",
6
+ "noEmit": true,
7
+ "skipLibCheck": true
8
+ }
9
+ }
package/.nvmrc DELETED
@@ -1 +0,0 @@
1
- lts/gallium
package/.travis.yml DELETED
@@ -1,3 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - 16
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes