shogiops 0.3.1 → 0.4.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/compat.d.ts +6 -24
- package/compat.js +13 -171
- package/compat.js.map +1 -1
- package/index.d.ts +0 -1
- package/index.js +1 -3
- package/index.js.map +1 -1
- package/package.json +1 -5
- package/src/compat.ts +17 -198
- package/src/index.ts +0 -2
- package/san.d.ts +0 -6
- package/san.js +0 -124
- package/san.js.map +0 -1
- package/src/san.ts +0 -113
package/compat.d.ts
CHANGED
|
@@ -1,26 +1,8 @@
|
|
|
1
|
-
import { Rules, SquareName, Move,
|
|
1
|
+
import { Rules, SquareName, Move, Role } from './types';
|
|
2
2
|
import { Position } from './shogi';
|
|
3
|
-
export declare
|
|
4
|
-
export declare
|
|
5
|
-
export declare const C_RANK_NAMES: readonly ["1", "2", "3", "4", "5", "6", "7", "8", "9"];
|
|
6
|
-
export declare type ChessRankName = typeof C_RANK_NAMES[number];
|
|
7
|
-
export declare type ChessSquareName = `${ChessFileName}${ChessRankName}`;
|
|
8
|
-
export declare function makeChessSquare(square: Square): ChessSquareName;
|
|
9
|
-
export declare function parseChessSquare(str: ChessSquareName): Square;
|
|
10
|
-
export declare function parseChessSquare(str: string): Square | undefined;
|
|
11
|
-
export declare function shogigroundDests(pos: Position): Map<ChessSquareName, ChessSquareName[]>;
|
|
12
|
-
export declare function shogigroundDropDests(pos: Position, role?: Role): Map<Role, ChessSquareName[]>;
|
|
3
|
+
export declare function shogigroundDests(pos: Position): Map<SquareName, SquareName[]>;
|
|
4
|
+
export declare function shogigroundDropDests(pos: Position, role?: Role): Map<Role, SquareName[]>;
|
|
13
5
|
export declare function scalashogiCharPair(move: Move): string;
|
|
14
|
-
export declare function
|
|
15
|
-
export declare function
|
|
16
|
-
export declare function
|
|
17
|
-
export declare function shogiCoordToChessCord(s: SquareName): ChessSquareName;
|
|
18
|
-
export declare function chessCoord(str: string): ChessSquareName | undefined;
|
|
19
|
-
export declare function shogiCoord(str: string): SquareName | undefined;
|
|
20
|
-
export declare function roleToLishogiChar(role: Role): string;
|
|
21
|
-
export declare function lishogiCharToRole(ch: 'p' | 'l' | 'n' | 's' | 'g' | 'b' | 'r' | 't' | 'u' | 'm' | 'a' | 'h' | 'd' | 'P' | 'L' | 'N' | 'S' | 'G' | 'B' | 'R' | 'T' | 'U' | 'M' | 'A' | 'H' | 'D'): Role;
|
|
22
|
-
export declare function lishogiCharToRole(ch: string): Role | undefined;
|
|
23
|
-
export declare function parseLishogiUci(str: string): Move | undefined;
|
|
24
|
-
export declare function makeLishogiUci(move: Move): string;
|
|
25
|
-
export declare function assureUsi(str: string): string | undefined;
|
|
26
|
-
export declare function assureLishogiUci(str: string): string | undefined;
|
|
6
|
+
export declare function usiToShogigroundMove(usi: string): SquareName[];
|
|
7
|
+
export declare function shogigroundMove(move: Move): SquareName[];
|
|
8
|
+
export declare function lishogiVariantRules(variant: string): Rules;
|
package/compat.js
CHANGED
|
@@ -1,31 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.lishogiVariantRules = exports.shogigroundMove = exports.usiToShogigroundMove = exports.scalashogiCharPair = exports.shogigroundDropDests = exports.shogigroundDests = void 0;
|
|
4
4
|
const types_1 = require("./types");
|
|
5
5
|
const util_1 = require("./util");
|
|
6
|
-
exports.C_FILE_NAMES = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'];
|
|
7
|
-
exports.C_RANK_NAMES = ['1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
|
8
|
-
function makeChessSquare(square) {
|
|
9
|
-
return (exports.C_FILE_NAMES[util_1.squareFile(square)] + exports.C_RANK_NAMES[util_1.squareRank(square)]);
|
|
10
|
-
}
|
|
11
|
-
exports.makeChessSquare = makeChessSquare;
|
|
12
|
-
function parseChessSquare(str) {
|
|
13
|
-
if (str.length !== 2)
|
|
14
|
-
return;
|
|
15
|
-
const file = Math.abs(str.charCodeAt(0) - 'a'.charCodeAt(0));
|
|
16
|
-
const rank = Math.abs(str.charCodeAt(1) - '1'.charCodeAt(0));
|
|
17
|
-
if (file < 0 || file >= 9 || rank < 0 || rank >= 9)
|
|
18
|
-
return;
|
|
19
|
-
return file + 9 * rank;
|
|
20
|
-
}
|
|
21
|
-
exports.parseChessSquare = parseChessSquare;
|
|
22
6
|
function shogigroundDests(pos) {
|
|
23
7
|
const result = new Map();
|
|
24
8
|
const ctx = pos.ctx();
|
|
25
9
|
for (const [from, squares] of pos.allDests(ctx)) {
|
|
26
10
|
if (squares.nonEmpty()) {
|
|
27
|
-
const d = Array.from(squares, s =>
|
|
28
|
-
result.set(
|
|
11
|
+
const d = Array.from(squares, s => util_1.makeSquare(s));
|
|
12
|
+
result.set(util_1.makeSquare(from), d);
|
|
29
13
|
}
|
|
30
14
|
}
|
|
31
15
|
return result;
|
|
@@ -36,7 +20,7 @@ function shogigroundDropDests(pos, role) {
|
|
|
36
20
|
if (role) {
|
|
37
21
|
const squares = pos.dropDests(role);
|
|
38
22
|
if (squares.nonEmpty()) {
|
|
39
|
-
const d = Array.from(squares, s =>
|
|
23
|
+
const d = Array.from(squares, s => util_1.makeSquare(s));
|
|
40
24
|
result.set(role, d);
|
|
41
25
|
}
|
|
42
26
|
}
|
|
@@ -44,7 +28,7 @@ function shogigroundDropDests(pos, role) {
|
|
|
44
28
|
const ctx = pos.ctx();
|
|
45
29
|
for (const [r, squares] of pos.allDropDests(ctx)) {
|
|
46
30
|
if (squares.nonEmpty()) {
|
|
47
|
-
const d = Array.from(squares, s =>
|
|
31
|
+
const d = Array.from(squares, s => util_1.makeSquare(s));
|
|
48
32
|
result.set(r, d);
|
|
49
33
|
}
|
|
50
34
|
}
|
|
@@ -59,164 +43,22 @@ function scalashogiCharPair(move) {
|
|
|
59
43
|
return String.fromCharCode(34 + move.from, move.promotion ? 34 + move.to + 128 : 34 + move.to);
|
|
60
44
|
}
|
|
61
45
|
exports.scalashogiCharPair = scalashogiCharPair;
|
|
46
|
+
function usiToShogigroundMove(usi) {
|
|
47
|
+
const move = util_1.parseUsi(usi);
|
|
48
|
+
return util_1.defined(move) ? shogigroundMove(move) : [];
|
|
49
|
+
}
|
|
50
|
+
exports.usiToShogigroundMove = usiToShogigroundMove;
|
|
62
51
|
function shogigroundMove(move) {
|
|
63
|
-
return types_1.isDrop(move) ? [
|
|
52
|
+
return types_1.isDrop(move) ? [util_1.makeSquare(move.to)] : [util_1.makeSquare(move.from), util_1.makeSquare(move.to)];
|
|
64
53
|
}
|
|
65
54
|
exports.shogigroundMove = shogigroundMove;
|
|
66
55
|
function lishogiVariantRules(variant) {
|
|
67
56
|
switch (variant) {
|
|
68
|
-
case 'standard':
|
|
69
|
-
case 'fromPosition':
|
|
70
|
-
return 'shogi';
|
|
71
57
|
case 'minishogi':
|
|
72
58
|
return 'minishogi';
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
exports.lishogiVariantRules = lishogiVariantRules;
|
|
76
|
-
function chessCoordToShogiCoord(s) {
|
|
77
|
-
return util_1.makeSquare(parseChessSquare(s));
|
|
78
|
-
}
|
|
79
|
-
exports.chessCoordToShogiCoord = chessCoordToShogiCoord;
|
|
80
|
-
function shogiCoordToChessCord(s) {
|
|
81
|
-
return makeChessSquare(util_1.parseSquare(s));
|
|
82
|
-
}
|
|
83
|
-
exports.shogiCoordToChessCord = shogiCoordToChessCord;
|
|
84
|
-
function chessCoord(str) {
|
|
85
|
-
if (str.match(/^[1-9][a-i]$/))
|
|
86
|
-
return shogiCoordToChessCord(str);
|
|
87
|
-
if (str.match(/^[a-i][1-9]$/))
|
|
88
|
-
return str;
|
|
89
|
-
return undefined;
|
|
90
|
-
}
|
|
91
|
-
exports.chessCoord = chessCoord;
|
|
92
|
-
function shogiCoord(str) {
|
|
93
|
-
if (str.match(/^[1-9][a-i]$/))
|
|
94
|
-
return str;
|
|
95
|
-
if (str.match(/^[a-i][1-9]$/))
|
|
96
|
-
return chessCoordToShogiCoord(str);
|
|
97
|
-
else
|
|
98
|
-
return undefined;
|
|
99
|
-
}
|
|
100
|
-
exports.shogiCoord = shogiCoord;
|
|
101
|
-
function roleToLishogiChar(role) {
|
|
102
|
-
switch (role) {
|
|
103
|
-
case 'pawn':
|
|
104
|
-
return 'p';
|
|
105
|
-
case 'lance':
|
|
106
|
-
return 'l';
|
|
107
|
-
case 'knight':
|
|
108
|
-
return 'n';
|
|
109
|
-
case 'silver':
|
|
110
|
-
return 's';
|
|
111
|
-
case 'gold':
|
|
112
|
-
return 'g';
|
|
113
|
-
case 'bishop':
|
|
114
|
-
return 'b';
|
|
115
|
-
case 'rook':
|
|
116
|
-
return 'r';
|
|
117
|
-
case 'tokin':
|
|
118
|
-
return 't';
|
|
119
|
-
case 'promotedlance':
|
|
120
|
-
return 'u';
|
|
121
|
-
case 'promotedknight':
|
|
122
|
-
return 'm';
|
|
123
|
-
case 'promotedsilver':
|
|
124
|
-
return 'a';
|
|
125
|
-
case 'horse':
|
|
126
|
-
return 'h';
|
|
127
|
-
case 'dragon':
|
|
128
|
-
return 'd';
|
|
129
|
-
case 'king':
|
|
130
|
-
return 'k';
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
exports.roleToLishogiChar = roleToLishogiChar;
|
|
134
|
-
function lishogiCharToRole(ch) {
|
|
135
|
-
switch (ch) {
|
|
136
|
-
case 'P':
|
|
137
|
-
case 'p':
|
|
138
|
-
return 'pawn';
|
|
139
|
-
case 'L':
|
|
140
|
-
case 'l':
|
|
141
|
-
return 'lance';
|
|
142
|
-
case 'N':
|
|
143
|
-
case 'n':
|
|
144
|
-
return 'knight';
|
|
145
|
-
case 'S':
|
|
146
|
-
case 's':
|
|
147
|
-
return 'silver';
|
|
148
|
-
case 'G':
|
|
149
|
-
case 'g':
|
|
150
|
-
return 'gold';
|
|
151
|
-
case 'B':
|
|
152
|
-
case 'b':
|
|
153
|
-
return 'bishop';
|
|
154
|
-
case 'R':
|
|
155
|
-
case 'r':
|
|
156
|
-
return 'rook';
|
|
157
|
-
case 'T':
|
|
158
|
-
case 't':
|
|
159
|
-
return 'tokin';
|
|
160
|
-
case 'U':
|
|
161
|
-
case 'u':
|
|
162
|
-
return 'promotedlance';
|
|
163
|
-
case 'M':
|
|
164
|
-
case 'm':
|
|
165
|
-
return 'promotedknight';
|
|
166
|
-
case 'A':
|
|
167
|
-
case 'a':
|
|
168
|
-
return 'promotedsilver';
|
|
169
|
-
case 'H':
|
|
170
|
-
case 'h':
|
|
171
|
-
return 'horse';
|
|
172
|
-
case 'D':
|
|
173
|
-
case 'd':
|
|
174
|
-
return 'dragon';
|
|
175
|
-
case 'K':
|
|
176
|
-
case 'k':
|
|
177
|
-
return 'king';
|
|
178
59
|
default:
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
exports.lishogiCharToRole = lishogiCharToRole;
|
|
183
|
-
function parseLishogiUci(str) {
|
|
184
|
-
if (str[1] === '*' && str.length === 4) {
|
|
185
|
-
const role = lishogiCharToRole(str[0]);
|
|
186
|
-
const to = parseChessSquare(str.slice(2));
|
|
187
|
-
if (util_1.defined(role) && util_1.defined(to))
|
|
188
|
-
return { role, to };
|
|
189
|
-
}
|
|
190
|
-
else if (str.length === 4 || str.length === 5) {
|
|
191
|
-
const from = parseChessSquare(str.slice(0, 2));
|
|
192
|
-
const to = parseChessSquare(str.slice(2, 4));
|
|
193
|
-
const promotion = str[4] === '+' ? true : false;
|
|
194
|
-
if (util_1.defined(from) && util_1.defined(to))
|
|
195
|
-
return { from, to, promotion };
|
|
60
|
+
return 'shogi';
|
|
196
61
|
}
|
|
197
|
-
return;
|
|
198
62
|
}
|
|
199
|
-
exports.
|
|
200
|
-
function makeLishogiUci(move) {
|
|
201
|
-
if (types_1.isDrop(move))
|
|
202
|
-
return `${roleToLishogiChar(move.role).toUpperCase()}*${makeChessSquare(move.to)}`;
|
|
203
|
-
return makeChessSquare(move.from) + makeChessSquare(move.to) + (move.promotion ? '+' : '');
|
|
204
|
-
}
|
|
205
|
-
exports.makeLishogiUci = makeLishogiUci;
|
|
206
|
-
function assureUsi(str) {
|
|
207
|
-
if (str.match(/^([1-9][a-i]|([RBGSNLP]\*))[1-9][a-i](\+|\=)?$/))
|
|
208
|
-
return str;
|
|
209
|
-
if (str.match(/^([a-i][1-9]|([RBGSNLP]\*))[a-i][1-9](\+|\=)?$/))
|
|
210
|
-
return util_1.makeUsi(parseLishogiUci(str));
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
exports.assureUsi = assureUsi;
|
|
214
|
-
function assureLishogiUci(str) {
|
|
215
|
-
if (str.match(/^([a-i][1-9]|([RBGSNLP]\*))[a-i][1-9](\+|\=)?$/))
|
|
216
|
-
return str;
|
|
217
|
-
if (str.match(/^([1-9][a-i]|([RBGSNLP]\*))[1-9][a-i](\+|\=)?$/))
|
|
218
|
-
return makeLishogiUci(util_1.parseUsi(str));
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
exports.assureLishogiUci = assureLishogiUci;
|
|
63
|
+
exports.lishogiVariantRules = lishogiVariantRules;
|
|
222
64
|
//# sourceMappingURL=compat.js.map
|
package/compat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compat.js","sourceRoot":"","sources":["src/compat.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"compat.js","sourceRoot":"","sources":["src/compat.ts"],"names":[],"mappings":";;;AAAA,mCAAgE;AAChE,iCAAuD;AAGvD,SAAgB,gBAAgB,CAAC,GAAa;IAC5C,MAAM,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;IACzB,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,EAAE,CAAC;IACtB,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QAC/C,IAAI,OAAO,CAAC,QAAQ,EAAE,EAA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
|
|
17
17
|
export * as csaUtil from './csaUtil';
|
|
18
|
-
export * as san from './san';
|
|
19
18
|
export * as transform from './transform';
|
|
20
19
|
export * as variant from './variant';
|
|
21
20
|
export * as variantUtil from './variantUtil';
|
package/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.variantUtil = void 0;
|
|
3
|
+
exports.variantUtil = exports.variant = exports.transform = exports.csaUtil = exports.csa = exports.kifUtil = exports.kif = exports.hash = exports.hand = exports.handicaps = exports.fen = exports.debug = exports.compat = exports.PositionError = exports.Position = exports.Shogi = exports.IllegalSetup = exports.defaultSetup = exports.Board = exports.rookAttacks = exports.ray = exports.dragonAttacks = exports.horseAttacks = exports.goldAttacks = exports.silverAttacks = exports.lanceAttacks = exports.pawnAttacks = exports.knightAttacks = exports.kingAttacks = exports.bishopAttacks = exports.between = exports.attacks = exports.SquareSet = exports.squareRank = exports.squareFile = exports.roleToChar = exports.parseUsi = exports.parseSquare = exports.opposite = exports.makeUsi = exports.makeSquare = exports.defined = exports.charToRole = exports.RULES = exports.isNormal = exports.isDrop = exports.ROLES = exports.COLORS = exports.RANK_NAMES = exports.FILE_NAMES = void 0;
|
|
5
4
|
var types_1 = require("./types");
|
|
6
5
|
Object.defineProperty(exports, "FILE_NAMES", { enumerable: true, get: function () { return types_1.FILE_NAMES; } });
|
|
7
6
|
Object.defineProperty(exports, "RANK_NAMES", { enumerable: true, get: function () { return types_1.RANK_NAMES; } });
|
|
@@ -56,7 +55,6 @@ exports.kif = require("./kif");
|
|
|
56
55
|
exports.kifUtil = require("./kifUtil");
|
|
57
56
|
exports.csa = require("./csa");
|
|
58
57
|
exports.csaUtil = require("./csaUtil");
|
|
59
|
-
exports.san = require("./san");
|
|
60
58
|
exports.transform = require("./transform");
|
|
61
59
|
exports.variant = require("./variant");
|
|
62
60
|
exports.variantUtil = require("./variantUtil");
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":";;;AAAA,iCAuBiB;AAtBf,mGAAA,UAAU,OAAA;AACV,mGAAA,UAAU,OAAA;AAOV,+FAAA,MAAM,OAAA;AAGN,8FAAA,KAAK,OAAA;AAML,+FAAA,MAAM,OAAA;AACN,iGAAA,QAAQ,OAAA;AAER,8FAAA,KAAK,OAAA;AAIP,+BAWgB;AAVd,kGAAA,UAAU,OAAA;AACV,+FAAA,OAAO,OAAA;AACP,kGAAA,UAAU,OAAA;AACV,+FAAA,OAAO,OAAA;AACP,gGAAA,QAAQ,OAAA;AACR,mGAAA,WAAW,OAAA;AACX,gGAAA,QAAQ,OAAA;AACR,kGAAA,UAAU,OAAA;AACV,kGAAA,UAAU,OAAA;AACV,kGAAA,UAAU,OAAA;AAGZ,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAElB,qCAcmB;AAbjB,kGAAA,OAAO,OAAA;AACP,kGAAA,OAAO,OAAA;AACP,wGAAA,aAAa,OAAA;AACb,sGAAA,WAAW,OAAA;AACX,wGAAA,aAAa,OAAA;AACb,sGAAA,WAAW,OAAA;AACX,uGAAA,YAAY,OAAA;AACZ,wGAAA,aAAa,OAAA;AACb,sGAAA,WAAW,OAAA;AACX,uGAAA,YAAY,OAAA;AACZ,wGAAA,aAAa,OAAA;AACb,8FAAA,GAAG,OAAA;AACH,sGAAA,WAAW,OAAA;AAGb,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AAEd,iCAA8C;AAA9B,qGAAA,YAAY,OAAA;AAE5B,iCAAgF;AAAvE,qGAAA,YAAY,OAAA;AAAE,8FAAA,KAAK,OAAA;AAAE,iGAAA,QAAQ,OAAA;AAAE,sGAAA,aAAa,OAAA;AAErD,qCAAmC;AAEnC,mCAAiC;AAEjC,+BAA6B;AAE7B,8CAA4C;AAE5C,iCAA+B;AAE/B,iCAA+B;AAE/B,+BAA6B;AAE7B,uCAAqC;AAErC,+BAA6B;AAE7B,uCAAqC;AAErC,2CAAyC;AAEzC,uCAAqC;AAErC,+CAA6C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shogiops",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Shogi rules and operations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"shogi",
|
|
@@ -51,7 +51,6 @@
|
|
|
51
51
|
"util.js",
|
|
52
52
|
"debug.js",
|
|
53
53
|
"fen.js",
|
|
54
|
-
"san.js",
|
|
55
54
|
"hand.js",
|
|
56
55
|
"hash.js",
|
|
57
56
|
"kifHandicaps.js",
|
|
@@ -73,7 +72,6 @@
|
|
|
73
72
|
"util.d.ts",
|
|
74
73
|
"debug.d.ts",
|
|
75
74
|
"fen.d.ts",
|
|
76
|
-
"san.d.ts",
|
|
77
75
|
"hand.d.ts",
|
|
78
76
|
"hash.d.ts",
|
|
79
77
|
"kifHandicaps.d.ts",
|
|
@@ -95,7 +93,6 @@
|
|
|
95
93
|
"util.js.map",
|
|
96
94
|
"debug.js.map",
|
|
97
95
|
"fen.js.map",
|
|
98
|
-
"san.js.map",
|
|
99
96
|
"hand.js.map",
|
|
100
97
|
"hash.js.map",
|
|
101
98
|
"kifHandicaps.js.map",
|
|
@@ -117,7 +114,6 @@
|
|
|
117
114
|
"src/util.ts",
|
|
118
115
|
"src/debug.ts",
|
|
119
116
|
"src/fen.ts",
|
|
120
|
-
"src/san.ts",
|
|
121
117
|
"src/hand.ts",
|
|
122
118
|
"src/hash.ts",
|
|
123
119
|
"src/kifHandicaps.ts",
|
package/src/compat.ts
CHANGED
|
@@ -1,54 +1,32 @@
|
|
|
1
|
-
import { Rules, SquareName, Move, isDrop,
|
|
2
|
-
import { defined, makeSquare,
|
|
1
|
+
import { Rules, SquareName, Move, isDrop, Role } from './types';
|
|
2
|
+
import { defined, makeSquare, parseUsi } from './util';
|
|
3
3
|
import { Position } from './shogi';
|
|
4
4
|
|
|
5
|
-
export
|
|
6
|
-
export type ChessFileName = typeof C_FILE_NAMES[number];
|
|
7
|
-
|
|
8
|
-
export const C_RANK_NAMES = ['1', '2', '3', '4', '5', '6', '7', '8', '9'] as const;
|
|
9
|
-
export type ChessRankName = typeof C_RANK_NAMES[number];
|
|
10
|
-
|
|
11
|
-
export type ChessSquareName = `${ChessFileName}${ChessRankName}`;
|
|
12
|
-
|
|
13
|
-
export function makeChessSquare(square: Square): ChessSquareName {
|
|
14
|
-
return (C_FILE_NAMES[squareFile(square)] + C_RANK_NAMES[squareRank(square)]) as ChessSquareName;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function parseChessSquare(str: ChessSquareName): Square;
|
|
18
|
-
export function parseChessSquare(str: string): Square | undefined;
|
|
19
|
-
export function parseChessSquare(str: string): Square | undefined {
|
|
20
|
-
if (str.length !== 2) return;
|
|
21
|
-
const file = Math.abs(str.charCodeAt(0) - 'a'.charCodeAt(0));
|
|
22
|
-
const rank = Math.abs(str.charCodeAt(1) - '1'.charCodeAt(0));
|
|
23
|
-
if (file < 0 || file >= 9 || rank < 0 || rank >= 9) return;
|
|
24
|
-
return file + 9 * rank;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function shogigroundDests(pos: Position): Map<ChessSquareName, ChessSquareName[]> {
|
|
5
|
+
export function shogigroundDests(pos: Position): Map<SquareName, SquareName[]> {
|
|
28
6
|
const result = new Map();
|
|
29
7
|
const ctx = pos.ctx();
|
|
30
8
|
for (const [from, squares] of pos.allDests(ctx)) {
|
|
31
9
|
if (squares.nonEmpty()) {
|
|
32
|
-
const d = Array.from(squares, s =>
|
|
33
|
-
result.set(
|
|
10
|
+
const d = Array.from(squares, s => makeSquare(s));
|
|
11
|
+
result.set(makeSquare(from), d);
|
|
34
12
|
}
|
|
35
13
|
}
|
|
36
14
|
return result;
|
|
37
15
|
}
|
|
38
16
|
|
|
39
|
-
export function shogigroundDropDests(pos: Position, role?: Role): Map<Role,
|
|
17
|
+
export function shogigroundDropDests(pos: Position, role?: Role): Map<Role, SquareName[]> {
|
|
40
18
|
const result = new Map();
|
|
41
19
|
if (role) {
|
|
42
20
|
const squares = pos.dropDests(role);
|
|
43
21
|
if (squares.nonEmpty()) {
|
|
44
|
-
const d = Array.from(squares, s =>
|
|
22
|
+
const d = Array.from(squares, s => makeSquare(s));
|
|
45
23
|
result.set(role, d);
|
|
46
24
|
}
|
|
47
25
|
} else {
|
|
48
26
|
const ctx = pos.ctx();
|
|
49
27
|
for (const [r, squares] of pos.allDropDests(ctx)) {
|
|
50
28
|
if (squares.nonEmpty()) {
|
|
51
|
-
const d = Array.from(squares, s =>
|
|
29
|
+
const d = Array.from(squares, s => makeSquare(s));
|
|
52
30
|
result.set(r, d);
|
|
53
31
|
}
|
|
54
32
|
}
|
|
@@ -65,179 +43,20 @@ export function scalashogiCharPair(move: Move): string {
|
|
|
65
43
|
else return String.fromCharCode(34 + move.from, move.promotion ? 34 + move.to + 128 : 34 + move.to);
|
|
66
44
|
}
|
|
67
45
|
|
|
68
|
-
export function
|
|
69
|
-
|
|
46
|
+
export function usiToShogigroundMove(usi: string): SquareName[] {
|
|
47
|
+
const move = parseUsi(usi);
|
|
48
|
+
return defined(move) ? shogigroundMove(move) : [];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function shogigroundMove(move: Move): SquareName[] {
|
|
52
|
+
return isDrop(move) ? [makeSquare(move.to)] : [makeSquare(move.from), makeSquare(move.to)];
|
|
70
53
|
}
|
|
71
54
|
|
|
72
|
-
export function lishogiVariantRules(variant:
|
|
55
|
+
export function lishogiVariantRules(variant: string): Rules {
|
|
73
56
|
switch (variant) {
|
|
74
|
-
case 'standard':
|
|
75
|
-
case 'fromPosition':
|
|
76
|
-
return 'shogi';
|
|
77
57
|
case 'minishogi':
|
|
78
58
|
return 'minishogi';
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function chessCoordToShogiCoord(s: ChessSquareName): SquareName {
|
|
83
|
-
return makeSquare(parseChessSquare(s));
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function shogiCoordToChessCord(s: SquareName): ChessSquareName {
|
|
87
|
-
return makeChessSquare(parseSquare(s));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function chessCoord(str: string): ChessSquareName | undefined {
|
|
91
|
-
if (str.match(/^[1-9][a-i]$/)) return shogiCoordToChessCord(str as SquareName);
|
|
92
|
-
if (str.match(/^[a-i][1-9]$/)) return str as ChessSquareName;
|
|
93
|
-
return undefined;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export function shogiCoord(str: string): SquareName | undefined {
|
|
97
|
-
if (str.match(/^[1-9][a-i]$/)) return str as SquareName;
|
|
98
|
-
if (str.match(/^[a-i][1-9]$/)) return chessCoordToShogiCoord(str as ChessSquareName);
|
|
99
|
-
else return undefined;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export function roleToLishogiChar(role: Role): string {
|
|
103
|
-
switch (role) {
|
|
104
|
-
case 'pawn':
|
|
105
|
-
return 'p';
|
|
106
|
-
case 'lance':
|
|
107
|
-
return 'l';
|
|
108
|
-
case 'knight':
|
|
109
|
-
return 'n';
|
|
110
|
-
case 'silver':
|
|
111
|
-
return 's';
|
|
112
|
-
case 'gold':
|
|
113
|
-
return 'g';
|
|
114
|
-
case 'bishop':
|
|
115
|
-
return 'b';
|
|
116
|
-
case 'rook':
|
|
117
|
-
return 'r';
|
|
118
|
-
case 'tokin':
|
|
119
|
-
return 't';
|
|
120
|
-
case 'promotedlance':
|
|
121
|
-
return 'u';
|
|
122
|
-
case 'promotedknight':
|
|
123
|
-
return 'm';
|
|
124
|
-
case 'promotedsilver':
|
|
125
|
-
return 'a';
|
|
126
|
-
case 'horse':
|
|
127
|
-
return 'h';
|
|
128
|
-
case 'dragon':
|
|
129
|
-
return 'd';
|
|
130
|
-
case 'king':
|
|
131
|
-
return 'k';
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export function lishogiCharToRole(
|
|
136
|
-
ch:
|
|
137
|
-
| 'p'
|
|
138
|
-
| 'l'
|
|
139
|
-
| 'n'
|
|
140
|
-
| 's'
|
|
141
|
-
| 'g'
|
|
142
|
-
| 'b'
|
|
143
|
-
| 'r'
|
|
144
|
-
| 't'
|
|
145
|
-
| 'u'
|
|
146
|
-
| 'm'
|
|
147
|
-
| 'a'
|
|
148
|
-
| 'h'
|
|
149
|
-
| 'd'
|
|
150
|
-
| 'P'
|
|
151
|
-
| 'L'
|
|
152
|
-
| 'N'
|
|
153
|
-
| 'S'
|
|
154
|
-
| 'G'
|
|
155
|
-
| 'B'
|
|
156
|
-
| 'R'
|
|
157
|
-
| 'T'
|
|
158
|
-
| 'U'
|
|
159
|
-
| 'M'
|
|
160
|
-
| 'A'
|
|
161
|
-
| 'H'
|
|
162
|
-
| 'D'
|
|
163
|
-
): Role;
|
|
164
|
-
export function lishogiCharToRole(ch: string): Role | undefined;
|
|
165
|
-
export function lishogiCharToRole(ch: string): Role | undefined {
|
|
166
|
-
switch (ch) {
|
|
167
|
-
case 'P':
|
|
168
|
-
case 'p':
|
|
169
|
-
return 'pawn';
|
|
170
|
-
case 'L':
|
|
171
|
-
case 'l':
|
|
172
|
-
return 'lance';
|
|
173
|
-
case 'N':
|
|
174
|
-
case 'n':
|
|
175
|
-
return 'knight';
|
|
176
|
-
case 'S':
|
|
177
|
-
case 's':
|
|
178
|
-
return 'silver';
|
|
179
|
-
case 'G':
|
|
180
|
-
case 'g':
|
|
181
|
-
return 'gold';
|
|
182
|
-
case 'B':
|
|
183
|
-
case 'b':
|
|
184
|
-
return 'bishop';
|
|
185
|
-
case 'R':
|
|
186
|
-
case 'r':
|
|
187
|
-
return 'rook';
|
|
188
|
-
case 'T':
|
|
189
|
-
case 't':
|
|
190
|
-
return 'tokin';
|
|
191
|
-
case 'U':
|
|
192
|
-
case 'u':
|
|
193
|
-
return 'promotedlance';
|
|
194
|
-
case 'M':
|
|
195
|
-
case 'm':
|
|
196
|
-
return 'promotedknight';
|
|
197
|
-
case 'A':
|
|
198
|
-
case 'a':
|
|
199
|
-
return 'promotedsilver';
|
|
200
|
-
case 'H':
|
|
201
|
-
case 'h':
|
|
202
|
-
return 'horse';
|
|
203
|
-
case 'D':
|
|
204
|
-
case 'd':
|
|
205
|
-
return 'dragon';
|
|
206
|
-
case 'K':
|
|
207
|
-
case 'k':
|
|
208
|
-
return 'king';
|
|
209
59
|
default:
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export function parseLishogiUci(str: string): Move | undefined {
|
|
215
|
-
if (str[1] === '*' && str.length === 4) {
|
|
216
|
-
const role = lishogiCharToRole(str[0]);
|
|
217
|
-
const to = parseChessSquare(str.slice(2));
|
|
218
|
-
if (defined(role) && defined(to)) return { role, to };
|
|
219
|
-
} else if (str.length === 4 || str.length === 5) {
|
|
220
|
-
const from = parseChessSquare(str.slice(0, 2));
|
|
221
|
-
const to = parseChessSquare(str.slice(2, 4));
|
|
222
|
-
const promotion = str[4] === '+' ? true : false;
|
|
223
|
-
if (defined(from) && defined(to)) return { from, to, promotion };
|
|
60
|
+
return 'shogi';
|
|
224
61
|
}
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
export function makeLishogiUci(move: Move): string {
|
|
229
|
-
if (isDrop(move)) return `${roleToLishogiChar(move.role).toUpperCase()}*${makeChessSquare(move.to)}`;
|
|
230
|
-
return makeChessSquare(move.from) + makeChessSquare(move.to) + (move.promotion ? '+' : '');
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export function assureUsi(str: string): string | undefined {
|
|
234
|
-
if (str.match(/^([1-9][a-i]|([RBGSNLP]\*))[1-9][a-i](\+|\=)?$/)) return str;
|
|
235
|
-
if (str.match(/^([a-i][1-9]|([RBGSNLP]\*))[a-i][1-9](\+|\=)?$/)) return makeUsi(parseLishogiUci(str)!);
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
export function assureLishogiUci(str: string): string | undefined {
|
|
240
|
-
if (str.match(/^([a-i][1-9]|([RBGSNLP]\*))[a-i][1-9](\+|\=)?$/)) return str;
|
|
241
|
-
if (str.match(/^([1-9][a-i]|([RBGSNLP]\*))[1-9][a-i](\+|\=)?$/)) return makeLishogiUci(parseUsi(str)!);
|
|
242
|
-
return;
|
|
243
62
|
}
|
package/src/index.ts
CHANGED
package/san.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Move } from './types';
|
|
2
|
-
import { Position } from './shogi';
|
|
3
|
-
export declare function makeSanAndPlay(pos: Position, move: Move): string;
|
|
4
|
-
export declare function makeSanVariation(pos: Position, variation: Move[]): string;
|
|
5
|
-
export declare function makeSan(pos: Position, move: Move): string;
|
|
6
|
-
export declare function parseSan(pos: Position, san: string): Move | undefined;
|
package/san.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseSan = exports.makeSan = exports.makeSanVariation = exports.makeSanAndPlay = void 0;
|
|
4
|
-
const types_1 = require("./types");
|
|
5
|
-
const util_1 = require("./util");
|
|
6
|
-
const squareSet_1 = require("./squareSet");
|
|
7
|
-
const compat_1 = require("./compat");
|
|
8
|
-
const variantUtil_1 = require("./variantUtil");
|
|
9
|
-
function makeSanWithoutSuffix(pos, move) {
|
|
10
|
-
let san = '';
|
|
11
|
-
if (types_1.isDrop(move)) {
|
|
12
|
-
san = compat_1.roleToLishogiChar(move.role).toUpperCase() + '*' + compat_1.shogiCoordToChessCord(util_1.makeSquare(move.to));
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
const piece = pos.board.get(move.from);
|
|
16
|
-
if (!piece)
|
|
17
|
-
return '--';
|
|
18
|
-
const capture = pos.board.occupied.has(move.to);
|
|
19
|
-
san = compat_1.roleToLishogiChar(piece.role).toUpperCase();
|
|
20
|
-
if (piece.role !== 'pawn' && piece.role !== 'lance' && piece.role !== 'king') {
|
|
21
|
-
// Disambiguation
|
|
22
|
-
let others = squareSet_1.SquareSet.empty();
|
|
23
|
-
for (const s of pos.board.pieces(pos.turn, piece.role)) {
|
|
24
|
-
if (pos.dests(s).has(move.to))
|
|
25
|
-
others = others.union(squareSet_1.SquareSet.fromSquare(s));
|
|
26
|
-
}
|
|
27
|
-
others = others.without(move.from);
|
|
28
|
-
if (others.nonEmpty()) {
|
|
29
|
-
san += compat_1.shogiCoordToChessCord(util_1.makeSquare(move.from));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (capture)
|
|
33
|
-
san += 'x';
|
|
34
|
-
san += compat_1.shogiCoordToChessCord(util_1.makeSquare(move.to));
|
|
35
|
-
if (move.promotion || variantUtil_1.pieceInDeadZone(pos.rules)(piece, move.to))
|
|
36
|
-
san += '+';
|
|
37
|
-
else if (variantUtil_1.pieceCanPromote(pos.rules)(piece, move.from, move.to))
|
|
38
|
-
san += '=';
|
|
39
|
-
}
|
|
40
|
-
return san;
|
|
41
|
-
}
|
|
42
|
-
function makeSanAndPlay(pos, move) {
|
|
43
|
-
const san = makeSanWithoutSuffix(pos, move);
|
|
44
|
-
pos.play(move);
|
|
45
|
-
return san;
|
|
46
|
-
}
|
|
47
|
-
exports.makeSanAndPlay = makeSanAndPlay;
|
|
48
|
-
function makeSanVariation(pos, variation) {
|
|
49
|
-
var _a;
|
|
50
|
-
pos = pos.clone();
|
|
51
|
-
const line = [];
|
|
52
|
-
for (let i = 0; i < variation.length; i++) {
|
|
53
|
-
if (i !== 0)
|
|
54
|
-
line.push(' ');
|
|
55
|
-
line.push(pos.fullmoves, '. ');
|
|
56
|
-
const san = makeSanWithoutSuffix(pos, variation[i]);
|
|
57
|
-
pos.play(variation[i]);
|
|
58
|
-
line.push(san);
|
|
59
|
-
if (san === '--')
|
|
60
|
-
return line.join('');
|
|
61
|
-
if (i === variation.length - 1 && ((_a = pos.outcome()) === null || _a === void 0 ? void 0 : _a.winner))
|
|
62
|
-
line.push('投了');
|
|
63
|
-
}
|
|
64
|
-
return line.join('');
|
|
65
|
-
}
|
|
66
|
-
exports.makeSanVariation = makeSanVariation;
|
|
67
|
-
function makeSan(pos, move) {
|
|
68
|
-
return makeSanAndPlay(pos.clone(), move);
|
|
69
|
-
}
|
|
70
|
-
exports.makeSan = makeSan;
|
|
71
|
-
function parseSan(pos, san) {
|
|
72
|
-
const ctx = pos.ctx();
|
|
73
|
-
// Normal move
|
|
74
|
-
const match = san.match(/^([PLNSGKBRTUMAHD])([a-i][1-9])?[x]?([a-i][1-9])(\+|\=)?$/);
|
|
75
|
-
if (!match) {
|
|
76
|
-
// Drop
|
|
77
|
-
const match = san.match(/^([PLNSGBRplsgbr])\*([a-i][1-9])$/);
|
|
78
|
-
if (!match)
|
|
79
|
-
return;
|
|
80
|
-
const move = {
|
|
81
|
-
role: compat_1.lishogiCharToRole(match[1]),
|
|
82
|
-
to: compat_1.parseChessSquare(match[2]),
|
|
83
|
-
};
|
|
84
|
-
return pos.isLegal(move, ctx) ? move : undefined;
|
|
85
|
-
}
|
|
86
|
-
const role = compat_1.lishogiCharToRole(match[1]);
|
|
87
|
-
const to = compat_1.parseChessSquare(match[3]);
|
|
88
|
-
const fromStr = match[2];
|
|
89
|
-
let candidates = pos.board.pieces(pos.turn, role);
|
|
90
|
-
if (fromStr)
|
|
91
|
-
candidates = candidates.intersect(squareSet_1.SquareSet.fromSquare(compat_1.parseChessSquare(fromStr)));
|
|
92
|
-
// Check uniqueness and legality
|
|
93
|
-
let from;
|
|
94
|
-
for (const candidate of candidates) {
|
|
95
|
-
if (pos.dests(candidate, ctx).has(to)) {
|
|
96
|
-
if (util_1.defined(from))
|
|
97
|
-
return; // Ambiguous
|
|
98
|
-
from = candidate;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (!util_1.defined(from))
|
|
102
|
-
return; // Illegal
|
|
103
|
-
const piece = pos.board.get(from);
|
|
104
|
-
const promotionStr = match[4];
|
|
105
|
-
let promotion;
|
|
106
|
-
if (promotionStr === '+')
|
|
107
|
-
promotion = true;
|
|
108
|
-
else
|
|
109
|
-
promotion = false;
|
|
110
|
-
// Promotion needs to be specified in san
|
|
111
|
-
if (util_1.defined(promotionStr) !== variantUtil_1.pieceCanPromote(pos.rules)(piece, from, to)) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
// force promotion
|
|
115
|
-
else if (!promotion && variantUtil_1.pieceInDeadZone(pos.rules)(piece, to))
|
|
116
|
-
return;
|
|
117
|
-
return {
|
|
118
|
-
from,
|
|
119
|
-
to,
|
|
120
|
-
promotion,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
exports.parseSan = parseSan;
|
|
124
|
-
//# sourceMappingURL=san.js.map
|
package/san.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"san.js","sourceRoot":"","sources":["src/san.ts"],"names":[],"mappings":";;;AAAA,mCAAuC;AACvC,iCAA6C;AAC7C,2CAAwC;AAExC,qCAAyG;AACzG,+CAAiE;AAEjE,SAAS,oBAAoB,CAAC,GAAa,EAAE,IAAU;IACrD,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,cAAM,CAAC,IAAI,CAAC,EAAE;QAChB,GAAG,GAAG,0BAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,GAAG,8BAAqB,CAAC,iBAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;KACrG;SAAM;QACL,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,CAAC,KAAK;YAAE,OA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,CAAC;IACT,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE;QAClC,IAAI,GAAG,CAAC,KAAK,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;YACrC,IAAI,cAAO,CAAC,IAAI,CAAC;gBAAE,OAAO,CAAC,YAAY;YACvC,IAAI,GAAG,SAAS,CAAC;SAClB;KACF;IACD,IAAI,CAAC,cAAO,CAAC,IAAI,CAAC;QAAE,OAAO,CAAC,UAAU;IACtC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC;IAEnC,MAAM,YAAY,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IAC9B,IAAI,SAAkB,CAAC;IACvB,IAAI,YAAY,KAAK,GAAG;QAAE,SAAS,GAAG,IAAI,CAAC;;QACtC,SAAS,GAAG,KAAK,CAAC;IAEvB,yCAAyC;IACzC,IAAI,cAAO,CAAC,YAAY,CAAC,KAAK,6BAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE;QACzE,OAAO;KACR;IAED,kBAAkB;SACb,IAAI,CAAC,SAAS,IAAI,6BAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC;QAAE,OAAO;IAErE,OAAO;QACL,IAAI;QACJ,EAAE;QACF,SAAS;KACV,CAAC;AACJ,CAAC;AAnDD,4BAmDC"}
|
package/src/san.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { isDrop, Move } from './types';
|
|
2
|
-
import { defined, makeSquare } from './util';
|
|
3
|
-
import { SquareSet } from './squareSet';
|
|
4
|
-
import { Position } from './shogi';
|
|
5
|
-
import { lishogiCharToRole, roleToLishogiChar, shogiCoordToChessCord, parseChessSquare } from './compat';
|
|
6
|
-
import { pieceCanPromote, pieceInDeadZone } from './variantUtil';
|
|
7
|
-
|
|
8
|
-
function makeSanWithoutSuffix(pos: Position, move: Move): string {
|
|
9
|
-
let san = '';
|
|
10
|
-
if (isDrop(move)) {
|
|
11
|
-
san = roleToLishogiChar(move.role).toUpperCase() + '*' + shogiCoordToChessCord(makeSquare(move.to));
|
|
12
|
-
} else {
|
|
13
|
-
const piece = pos.board.get(move.from);
|
|
14
|
-
if (!piece) return '--';
|
|
15
|
-
const capture = pos.board.occupied.has(move.to);
|
|
16
|
-
san = roleToLishogiChar(piece.role).toUpperCase();
|
|
17
|
-
|
|
18
|
-
if (piece.role !== 'pawn' && piece.role !== 'lance' && piece.role !== 'king') {
|
|
19
|
-
// Disambiguation
|
|
20
|
-
let others = SquareSet.empty();
|
|
21
|
-
for (const s of pos.board.pieces(pos.turn, piece.role)) {
|
|
22
|
-
if (pos.dests(s).has(move.to)) others = others.union(SquareSet.fromSquare(s));
|
|
23
|
-
}
|
|
24
|
-
others = others.without(move.from);
|
|
25
|
-
if (others.nonEmpty()) {
|
|
26
|
-
san += shogiCoordToChessCord(makeSquare(move.from));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
if (capture) san += 'x';
|
|
30
|
-
san += shogiCoordToChessCord(makeSquare(move.to));
|
|
31
|
-
if (move.promotion || pieceInDeadZone(pos.rules)(piece, move.to)) san += '+';
|
|
32
|
-
else if (pieceCanPromote(pos.rules)(piece, move.from, move.to)) san += '=';
|
|
33
|
-
}
|
|
34
|
-
return san;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function makeSanAndPlay(pos: Position, move: Move): string {
|
|
38
|
-
const san = makeSanWithoutSuffix(pos, move);
|
|
39
|
-
pos.play(move);
|
|
40
|
-
return san;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function makeSanVariation(pos: Position, variation: Move[]): string {
|
|
44
|
-
pos = pos.clone();
|
|
45
|
-
const line = [];
|
|
46
|
-
for (let i = 0; i < variation.length; i++) {
|
|
47
|
-
if (i !== 0) line.push(' ');
|
|
48
|
-
line.push(pos.fullmoves, '. ');
|
|
49
|
-
const san = makeSanWithoutSuffix(pos, variation[i]);
|
|
50
|
-
pos.play(variation[i]);
|
|
51
|
-
line.push(san);
|
|
52
|
-
if (san === '--') return line.join('');
|
|
53
|
-
if (i === variation.length - 1 && pos.outcome()?.winner) line.push('投了');
|
|
54
|
-
}
|
|
55
|
-
return line.join('');
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function makeSan(pos: Position, move: Move): string {
|
|
59
|
-
return makeSanAndPlay(pos.clone(), move);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function parseSan(pos: Position, san: string): Move | undefined {
|
|
63
|
-
const ctx = pos.ctx();
|
|
64
|
-
|
|
65
|
-
// Normal move
|
|
66
|
-
const match = san.match(/^([PLNSGKBRTUMAHD])([a-i][1-9])?[x]?([a-i][1-9])(\+|\=)?$/);
|
|
67
|
-
if (!match) {
|
|
68
|
-
// Drop
|
|
69
|
-
const match = san.match(/^([PLNSGBRplsgbr])\*([a-i][1-9])$/);
|
|
70
|
-
if (!match) return;
|
|
71
|
-
const move = {
|
|
72
|
-
role: lishogiCharToRole(match[1])!,
|
|
73
|
-
to: parseChessSquare(match[2])!,
|
|
74
|
-
};
|
|
75
|
-
return pos.isLegal(move, ctx) ? move : undefined;
|
|
76
|
-
}
|
|
77
|
-
const role = lishogiCharToRole(match[1])!;
|
|
78
|
-
const to = parseChessSquare(match[3])!;
|
|
79
|
-
const fromStr = match[2];
|
|
80
|
-
|
|
81
|
-
let candidates = pos.board.pieces(pos.turn, role);
|
|
82
|
-
if (fromStr) candidates = candidates.intersect(SquareSet.fromSquare(parseChessSquare(fromStr)!));
|
|
83
|
-
|
|
84
|
-
// Check uniqueness and legality
|
|
85
|
-
let from;
|
|
86
|
-
for (const candidate of candidates) {
|
|
87
|
-
if (pos.dests(candidate, ctx).has(to)) {
|
|
88
|
-
if (defined(from)) return; // Ambiguous
|
|
89
|
-
from = candidate;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (!defined(from)) return; // Illegal
|
|
93
|
-
const piece = pos.board.get(from)!;
|
|
94
|
-
|
|
95
|
-
const promotionStr = match[4];
|
|
96
|
-
let promotion: boolean;
|
|
97
|
-
if (promotionStr === '+') promotion = true;
|
|
98
|
-
else promotion = false;
|
|
99
|
-
|
|
100
|
-
// Promotion needs to be specified in san
|
|
101
|
-
if (defined(promotionStr) !== pieceCanPromote(pos.rules)(piece, from, to)) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// force promotion
|
|
106
|
-
else if (!promotion && pieceInDeadZone(pos.rules)(piece, to)) return;
|
|
107
|
-
|
|
108
|
-
return {
|
|
109
|
-
from,
|
|
110
|
-
to,
|
|
111
|
-
promotion,
|
|
112
|
-
};
|
|
113
|
-
}
|