shogi.js 2.0.4 → 2.0.5
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/.eslintrc.js +27 -0
- package/.nvmrc +1 -1
- package/.prettierignore +10 -0
- package/.prettierrc.json +5 -0
- package/.travis.yml +1 -1
- package/README.md +12 -13
- package/dist/shogi.js +2 -2
- package/dist/src/Kind.d.ts +19 -0
- package/dist/src/Piece.d.ts +6 -5
- package/dist/src/moveDefinitions.d.ts +3 -0
- package/dist/src/presets.d.ts +74 -0
- package/dist/src/shogi.d.ts +11 -11
- package/package.json +11 -7
- package/.github/workflows/gh-pages.yml +0 -33
- package/.idea/codeStyles/Project.xml +0 -21
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/dist/src/Constants.d.ts +0 -14
- package/docs/assets/css/main.css +0 -1
- package/docs/assets/images/icons.png +0 -0
- package/docs/assets/images/icons@2x.png +0 -0
- package/docs/assets/images/widgets.png +0 -0
- package/docs/assets/images/widgets@2x.png +0 -0
- package/docs/assets/js/main.js +0 -51
- package/docs/assets/js/search.js +0 -1
- package/docs/classes/piece.html +0 -563
- package/docs/classes/shogi.html +0 -1187
- package/docs/enums/color.html +0 -186
- package/docs/index.html +0 -204
- package/docs/interfaces/imove.html +0 -236
- package/docs/interfaces/imovedefinition.html +0 -186
- package/docs/interfaces/isettingtype.html +0 -200
- package/docs/modules.html +0 -149
- package/public/docs/assets/css/main.css +0 -1
- package/public/docs/assets/images/icons.png +0 -0
- package/public/docs/assets/images/icons@2x.png +0 -0
- package/public/docs/assets/images/widgets.png +0 -0
- package/public/docs/assets/images/widgets@2x.png +0 -0
- package/public/docs/assets/js/main.js +0 -51
- package/public/docs/assets/js/search.json +0 -1
- package/public/docs/classes/_piece_.piece.html +0 -576
- package/public/docs/classes/_shogi_.shogi.html +0 -1206
- package/public/docs/enums/_color_.color.html +0 -193
- package/public/docs/globals.html +0 -146
- package/public/docs/index.html +0 -227
- package/public/docs/interfaces/_imovedefinition_.imovedefinition.html +0 -194
- package/public/docs/interfaces/_shogi_.imove.html +0 -250
- package/public/docs/interfaces/_shogi_.isettingtype.html +0 -214
- package/public/docs/modules/_color_.html +0 -146
- package/public/docs/modules/_constants_.html +0 -1074
- package/public/docs/modules/_imovedefinition_.html +0 -146
- package/public/docs/modules/_piece_.html +0 -146
- package/public/docs/modules/_polyfills_.html +0 -112
- package/public/docs/modules/_serialization_.html +0 -262
- package/public/docs/modules/_shogi_.html +0 -159
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
env: {
|
|
3
|
+
browser: true,
|
|
4
|
+
es2021: true,
|
|
5
|
+
},
|
|
6
|
+
extends: [
|
|
7
|
+
"eslint:recommended",
|
|
8
|
+
"plugin:@typescript-eslint/recommended",
|
|
9
|
+
"plugin:jest/recommended",
|
|
10
|
+
"prettier",
|
|
11
|
+
],
|
|
12
|
+
parser: "@typescript-eslint/parser",
|
|
13
|
+
parserOptions: {
|
|
14
|
+
ecmaVersion: 13,
|
|
15
|
+
sourceType: "module",
|
|
16
|
+
},
|
|
17
|
+
plugins: ["@typescript-eslint", "jest"],
|
|
18
|
+
ignorePatterns: [
|
|
19
|
+
".eslintrc.js",
|
|
20
|
+
"jest.config.js",
|
|
21
|
+
"webpack.config.js",
|
|
22
|
+
"docs/",
|
|
23
|
+
"bundle/",
|
|
24
|
+
"dist/",
|
|
25
|
+
],
|
|
26
|
+
rules: {},
|
|
27
|
+
};
|
package/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
lts/gallium
|
package/.prettierignore
ADDED
package/.prettierrc.json
ADDED
package/.travis.yml
CHANGED
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
# Shogi.js (Ver. 2.0)
|
|
1
|
+
# Shogi.js (Ver. 2.0) 
|
|
2
2
|
将棋の盤駒をモデルとするシンプルなJavaScriptライブラリ.TypeScript.
|
|
3
3
|
|
|
4
4
|
## インストール
|
|
5
5
|
|
|
6
|
-
```
|
|
6
|
+
```shell
|
|
7
7
|
npm install shogi.js
|
|
8
8
|
```
|
|
9
9
|
|
|
@@ -38,53 +38,52 @@ https://github.com/na2hiro/Shogi.js/issues
|
|
|
38
38
|
|
|
39
39
|
### 準備
|
|
40
40
|
|
|
41
|
-
```
|
|
42
|
-
$ npm install
|
|
41
|
+
```shell
|
|
42
|
+
$ nvm i && nvm use && npm install
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
上記コマンドを実行することで開発に必要なパッケージをインストールできます.
|
|
46
46
|
|
|
47
|
-
* TypeScript
|
|
48
|
-
* Webpack
|
|
49
|
-
* Browserify (JSバンドルツール)
|
|
47
|
+
* TypeScript
|
|
48
|
+
* Webpack (バンドルツール)
|
|
50
49
|
* Jest (テストフレームワーク,カバレッジ計測)
|
|
51
50
|
* TSLint (Linter)
|
|
52
51
|
|
|
53
52
|
### コマンド
|
|
54
53
|
|
|
55
54
|
|
|
56
|
-
```
|
|
55
|
+
```shell
|
|
57
56
|
$ npm run build
|
|
58
57
|
$ npm run build:watch
|
|
59
58
|
```
|
|
60
59
|
|
|
61
60
|
ビルドが走ります.`build:watch`の場合,変更されるたびにビルドが走ります.
|
|
62
61
|
|
|
63
|
-
```
|
|
62
|
+
```shell
|
|
64
63
|
$ npm run test:watch
|
|
65
64
|
```
|
|
66
65
|
|
|
67
66
|
コンソールでテスト結果が表示されます.コードの変更が保存されるたびに必要なテストが再実行されるため,実装が既存の有効なテストを壊してないか簡単に確認できます.
|
|
68
67
|
|
|
69
|
-
```
|
|
68
|
+
```shell
|
|
70
69
|
$ npm run test
|
|
71
70
|
```
|
|
72
71
|
|
|
73
72
|
全てのテストが走るとともにカバレッジレポートが表示されます.`coverage/lcov-report/index.html`では,行ごとのカバレッジを確認できます.追加されたコードのブランチカバレッジが100%になるようにしてください.push時にチェックされ満たしていなければ却下されるはずです.
|
|
74
73
|
|
|
75
|
-
```
|
|
74
|
+
```shell
|
|
76
75
|
$ npm run lint
|
|
77
76
|
```
|
|
78
77
|
|
|
79
78
|
コードの品質が検査されます.エラーがあればそれに従い直してください.push前にもチェックされます.
|
|
80
79
|
|
|
81
|
-
```
|
|
80
|
+
```shell
|
|
82
81
|
$ npm run lint:fix
|
|
83
82
|
```
|
|
84
83
|
|
|
85
84
|
自動的に修正可能な問題(インデント等)を直してくれます.
|
|
86
85
|
|
|
87
|
-
```
|
|
86
|
+
```shell
|
|
88
87
|
$ npm run docs
|
|
89
88
|
```
|
|
90
89
|
|
package/dist/shogi.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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=
|
|
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
2
|
/** @license
|
|
3
3
|
* Shogi.js
|
|
4
4
|
* Copyright (c) 2014 na2hiro (https://github.com/na2hiro)
|
|
5
5
|
* This software is released under the MIT License.
|
|
6
6
|
* http://opensource.org/licenses/mit-license.php
|
|
7
7
|
*/
|
|
8
|
-
var e=r(0);o.Color=e.default;var n=r(
|
|
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}]);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare enum KindEnum {
|
|
2
|
+
FU = 0,
|
|
3
|
+
KY = 1,
|
|
4
|
+
KE = 2,
|
|
5
|
+
GI = 3,
|
|
6
|
+
KI = 4,
|
|
7
|
+
KA = 5,
|
|
8
|
+
HI = 6,
|
|
9
|
+
OU = 7,
|
|
10
|
+
TO = 8,
|
|
11
|
+
NY = 9,
|
|
12
|
+
NK = 10,
|
|
13
|
+
NG = 11,
|
|
14
|
+
UM = 12,
|
|
15
|
+
RY = 13
|
|
16
|
+
}
|
|
17
|
+
export declare type Kind = keyof typeof KindEnum;
|
|
18
|
+
export declare const values: Kind[];
|
|
19
|
+
export {};
|
package/dist/src/Piece.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Color from "./Color";
|
|
2
|
+
import { Kind } from "./Kind";
|
|
2
3
|
/**
|
|
3
4
|
* 駒を表すクラス
|
|
4
5
|
*/
|
|
@@ -6,16 +7,16 @@ export default class Piece {
|
|
|
6
7
|
/**
|
|
7
8
|
* 成った時の種類を返す.なければそのまま.
|
|
8
9
|
*/
|
|
9
|
-
static promote(kind:
|
|
10
|
+
static promote(kind: Kind): Kind;
|
|
10
11
|
/**
|
|
11
12
|
* 表に返した時の種類を返す.表の場合はそのまま.
|
|
12
13
|
*/
|
|
13
|
-
static unpromote(kind:
|
|
14
|
+
static unpromote(kind: Kind): Kind;
|
|
14
15
|
/**
|
|
15
16
|
* 成れる駒かどうかを返す
|
|
16
17
|
*/
|
|
17
|
-
static canPromote(kind:
|
|
18
|
-
static isPromoted(kind:
|
|
18
|
+
static canPromote(kind: Kind): boolean;
|
|
19
|
+
static isPromoted(kind: Kind): boolean;
|
|
19
20
|
static oppositeColor(color: Color): Color;
|
|
20
21
|
/**
|
|
21
22
|
* SFENによる文字列表現から駒オブジェクトを作成
|
|
@@ -28,7 +29,7 @@ export default class Piece {
|
|
|
28
29
|
/**
|
|
29
30
|
* 駒の種類
|
|
30
31
|
*/
|
|
31
|
-
kind:
|
|
32
|
+
kind: Kind;
|
|
32
33
|
/**
|
|
33
34
|
* "+FU"などのCSAによる駒表現から駒オブジェクトを作成
|
|
34
35
|
*/
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import Color from "./Color";
|
|
2
|
+
/**
|
|
3
|
+
* 既定の初期局面
|
|
4
|
+
*/
|
|
5
|
+
declare const presetDefinitions: {
|
|
6
|
+
HIRATE: {
|
|
7
|
+
board: string[];
|
|
8
|
+
turn: Color;
|
|
9
|
+
};
|
|
10
|
+
KY: {
|
|
11
|
+
board: string[];
|
|
12
|
+
turn: Color;
|
|
13
|
+
};
|
|
14
|
+
KY_R: {
|
|
15
|
+
board: string[];
|
|
16
|
+
turn: Color;
|
|
17
|
+
};
|
|
18
|
+
KA: {
|
|
19
|
+
board: string[];
|
|
20
|
+
turn: Color;
|
|
21
|
+
};
|
|
22
|
+
HI: {
|
|
23
|
+
board: string[];
|
|
24
|
+
turn: Color;
|
|
25
|
+
};
|
|
26
|
+
HIKY: {
|
|
27
|
+
board: string[];
|
|
28
|
+
turn: Color;
|
|
29
|
+
};
|
|
30
|
+
"2": {
|
|
31
|
+
board: string[];
|
|
32
|
+
turn: Color;
|
|
33
|
+
};
|
|
34
|
+
"3": {
|
|
35
|
+
board: string[];
|
|
36
|
+
turn: Color;
|
|
37
|
+
};
|
|
38
|
+
"4": {
|
|
39
|
+
board: string[];
|
|
40
|
+
turn: Color;
|
|
41
|
+
};
|
|
42
|
+
"5": {
|
|
43
|
+
board: string[];
|
|
44
|
+
turn: Color;
|
|
45
|
+
};
|
|
46
|
+
"5_L": {
|
|
47
|
+
board: string[];
|
|
48
|
+
turn: Color;
|
|
49
|
+
};
|
|
50
|
+
"6": {
|
|
51
|
+
board: string[];
|
|
52
|
+
turn: Color;
|
|
53
|
+
};
|
|
54
|
+
"7_R": {
|
|
55
|
+
board: string[];
|
|
56
|
+
turn: Color;
|
|
57
|
+
};
|
|
58
|
+
"7_L": {
|
|
59
|
+
board: string[];
|
|
60
|
+
turn: Color;
|
|
61
|
+
};
|
|
62
|
+
"8": {
|
|
63
|
+
board: string[];
|
|
64
|
+
turn: Color;
|
|
65
|
+
};
|
|
66
|
+
"10": {
|
|
67
|
+
board: string[];
|
|
68
|
+
turn: Color;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
export declare type IPreset = keyof typeof presetDefinitions;
|
|
72
|
+
export declare const getInitialFromPreset: (preset: string) => any;
|
|
73
|
+
declare const presets: string[];
|
|
74
|
+
export default presets;
|
package/dist/src/shogi.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import Color from "./Color";
|
|
8
8
|
import IMoveDefinition from "./IMoveDefinition";
|
|
9
|
+
import { Kind } from "./Kind";
|
|
9
10
|
import Piece from "./Piece";
|
|
10
11
|
import "./polyfills";
|
|
11
12
|
/**
|
|
@@ -68,11 +69,11 @@ export declare class Shogi {
|
|
|
68
69
|
/**
|
|
69
70
|
* moveの逆を行う.つまり(tox, toy)から(fromx, fromy)へ移動し,駒を取っていたら戻し,promoteなら成りを戻す.
|
|
70
71
|
*/
|
|
71
|
-
unmove(fromx: number, fromy: number, tox: number, toy: number, promote?: boolean, capture?:
|
|
72
|
+
unmove(fromx: number, fromy: number, tox: number, toy: number, promote?: boolean, capture?: Kind): void;
|
|
72
73
|
/**
|
|
73
74
|
* (tox, toy)へcolorの持ち駒のkindを打つ.
|
|
74
75
|
*/
|
|
75
|
-
drop(tox: number, toy: number, kind:
|
|
76
|
+
drop(tox: number, toy: number, kind: Kind, color?: Color): void;
|
|
76
77
|
/**
|
|
77
78
|
* dropの逆を行う,つまり(tox, toy)の駒を駒台に戻す.
|
|
78
79
|
*/
|
|
@@ -89,7 +90,7 @@ export declare class Shogi {
|
|
|
89
90
|
/**
|
|
90
91
|
* (x, y)に行けるcolor側のkindの駒の動きを得る
|
|
91
92
|
*/
|
|
92
|
-
getMovesTo(x: number, y: number, kind:
|
|
93
|
+
getMovesTo(x: number, y: number, kind: Kind, color?: Color): IMove[];
|
|
93
94
|
/**
|
|
94
95
|
* (x, y)の駒を得る
|
|
95
96
|
*/
|
|
@@ -97,9 +98,7 @@ export declare class Shogi {
|
|
|
97
98
|
/**
|
|
98
99
|
* keyを種類,valueを枚数とするオブジェクトとして持ち駒の枚数一覧を返す.
|
|
99
100
|
*/
|
|
100
|
-
getHandsSummary(color: Color):
|
|
101
|
-
[index: string]: number;
|
|
102
|
-
};
|
|
101
|
+
getHandsSummary(color: Color): HandSummary;
|
|
103
102
|
/**
|
|
104
103
|
* (x, y)の駒を取ってcolorの持ち駒に加える
|
|
105
104
|
*/
|
|
@@ -142,17 +141,18 @@ export declare class Shogi {
|
|
|
142
141
|
*/
|
|
143
142
|
private checkTurn;
|
|
144
143
|
}
|
|
144
|
+
declare type HandSummary = {
|
|
145
|
+
[K in Extract<Kind, "FU" | "KY" | "KE" | "GI" | "KI" | "KA" | "HI">]: number;
|
|
146
|
+
};
|
|
145
147
|
export interface ISettingType {
|
|
146
148
|
preset: string;
|
|
147
149
|
data?: {
|
|
148
150
|
color: Color;
|
|
149
151
|
board: Array<Array<{
|
|
150
152
|
color?: Color;
|
|
151
|
-
kind?:
|
|
153
|
+
kind?: Kind;
|
|
152
154
|
}>>;
|
|
153
|
-
hands:
|
|
154
|
-
[index: string]: number;
|
|
155
|
-
}>;
|
|
155
|
+
hands: HandSummary[];
|
|
156
156
|
};
|
|
157
157
|
}
|
|
158
158
|
export interface IMove {
|
|
@@ -164,7 +164,7 @@ export interface IMove {
|
|
|
164
164
|
x: number;
|
|
165
165
|
y: number;
|
|
166
166
|
};
|
|
167
|
-
kind?:
|
|
167
|
+
kind?: Kind;
|
|
168
168
|
color?: Color;
|
|
169
169
|
}
|
|
170
170
|
export { Color, Piece, IMoveDefinition };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shogi.js",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "simple shogi library for JavaScript",
|
|
5
5
|
"main": "dist/shogi.js",
|
|
6
6
|
"types": "dist/src/shogi.d.ts",
|
|
@@ -11,10 +11,11 @@
|
|
|
11
11
|
"build": "webpack --mode=production -p",
|
|
12
12
|
"build:analyze": "webpack --mode=production -p --env.analyze",
|
|
13
13
|
"build:watch": "webpack --mode=development --watch",
|
|
14
|
-
"lint": "
|
|
15
|
-
"lint:fix": "
|
|
14
|
+
"lint": "eslint ./ && prettier --check .",
|
|
15
|
+
"lint:fix": "eslint ./ --fix && prettier --write .",
|
|
16
16
|
"test": "jest",
|
|
17
17
|
"test:watch": "jest --watch",
|
|
18
|
+
"typecheck": "tsc --project tsconfig.json --noEmit",
|
|
18
19
|
"prepublishOnly": "npm run build",
|
|
19
20
|
"docs": "typedoc --exclude '**/__tests__/**/*' ./src/shogi.ts",
|
|
20
21
|
"deploy:ghpages": "rm -rf ./public && mkdir -p ./public && npm run docs && mv ./docs ./public/"
|
|
@@ -35,13 +36,17 @@
|
|
|
35
36
|
"homepage": "https://github.com/na2hiro/Shogi.js#readme",
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"@types/jest": "^22.2.0",
|
|
38
|
-
"
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "^5.9.0",
|
|
40
|
+
"@typescript-eslint/parser": "^5.9.0",
|
|
39
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",
|
|
40
45
|
"jest": "^26.1.0",
|
|
41
46
|
"pre-push": "^0.1.1",
|
|
47
|
+
"prettier": "^2.5.1",
|
|
42
48
|
"ts-jest": "^26.4.3",
|
|
43
49
|
"ts-loader": "^4.3.1",
|
|
44
|
-
"tslint": "^5.9.1",
|
|
45
50
|
"typedoc": "^0.20.35",
|
|
46
51
|
"typescript": "^4.0.5",
|
|
47
52
|
"webpack": "^4.43.0",
|
|
@@ -52,6 +57,5 @@
|
|
|
52
57
|
"pre-push": [
|
|
53
58
|
"lint",
|
|
54
59
|
"test"
|
|
55
|
-
]
|
|
56
|
-
"dependencies": {}
|
|
60
|
+
]
|
|
57
61
|
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
name: github pages
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- master
|
|
7
|
-
|
|
8
|
-
jobs:
|
|
9
|
-
deploy:
|
|
10
|
-
runs-on: ubuntu-18.04
|
|
11
|
-
steps:
|
|
12
|
-
- uses: actions/checkout@v2
|
|
13
|
-
|
|
14
|
-
- name: Setup Node
|
|
15
|
-
uses: actions/setup-node@v2.1.3
|
|
16
|
-
with:
|
|
17
|
-
node-version: '12.x'
|
|
18
|
-
|
|
19
|
-
- name: Cache dependencies
|
|
20
|
-
uses: actions/cache@v2
|
|
21
|
-
with:
|
|
22
|
-
path: ~/.npm
|
|
23
|
-
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
|
24
|
-
restore-keys: |
|
|
25
|
-
${{ runner.os }}-node-
|
|
26
|
-
- run: npm ci
|
|
27
|
-
- run: npm run deploy:ghpages
|
|
28
|
-
|
|
29
|
-
- name: Deploy
|
|
30
|
-
uses: peaceiris/actions-gh-pages@v3
|
|
31
|
-
with:
|
|
32
|
-
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
33
|
-
publish_dir: ./public
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
<component name="ProjectCodeStyleConfiguration">
|
|
2
|
-
<code_scheme name="Project" version="173">
|
|
3
|
-
<H2CodeStyleSettings version="5">
|
|
4
|
-
<option name="USE_GENERAL_STYLE" value="false" />
|
|
5
|
-
</H2CodeStyleSettings>
|
|
6
|
-
<TypeScriptCodeStyleSettings version="0">
|
|
7
|
-
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
|
8
|
-
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
|
9
|
-
<option name="SPACE_WITHIN_TYPE_ASSERTION" value="true" />
|
|
10
|
-
<option name="IMPORT_SORT_MODULE_NAME" value="true" />
|
|
11
|
-
</TypeScriptCodeStyleSettings>
|
|
12
|
-
<codeStyleSettings language="TypeScript">
|
|
13
|
-
<option name="RIGHT_MARGIN" value="120" />
|
|
14
|
-
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
|
|
15
|
-
<option name="IF_BRACE_FORCE" value="3" />
|
|
16
|
-
<option name="DOWHILE_BRACE_FORCE" value="3" />
|
|
17
|
-
<option name="WHILE_BRACE_FORCE" value="3" />
|
|
18
|
-
<option name="FOR_BRACE_FORCE" value="3" />
|
|
19
|
-
</codeStyleSettings>
|
|
20
|
-
</code_scheme>
|
|
21
|
-
</component>
|
package/.idea/misc.xml
DELETED
package/.idea/modules.xml
DELETED
package/.idea/vcs.xml
DELETED
package/dist/src/Constants.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import Color from "./Color";
|
|
2
|
-
import IMoveDefinition from "./IMoveDefinition";
|
|
3
|
-
/**
|
|
4
|
-
* 既定の初期局面
|
|
5
|
-
*/
|
|
6
|
-
export declare const PRESET: Readonly<{
|
|
7
|
-
[index: string]: Readonly<{
|
|
8
|
-
readonly board: string[];
|
|
9
|
-
readonly turn: Color;
|
|
10
|
-
}>;
|
|
11
|
-
}>;
|
|
12
|
-
export declare const MOVE_DEF: Readonly<{
|
|
13
|
-
[index: string]: Readonly<IMoveDefinition>;
|
|
14
|
-
}>;
|