projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Some fixes, draw lines on board, add 7 variants
[vchess.git]
/
client
/
src
/
variants
/
Shogi.js
diff --git
a/client/src/variants/Shogi.js
b/client/src/variants/Shogi.js
index
bbd3af5
..
1b2ba03
100644
(file)
--- a/
client/src/variants/Shogi.js
+++ b/
client/src/variants/Shogi.js
@@
-11,6
+11,10
@@
export class ShogiRules extends ChessRules {
return false;
}
return false;
}
+ static get Monochrome() {
+ return true;
+ }
+
static IsGoodFen(fen) {
if (!ChessRules.IsGoodFen(fen)) return false;
const fenParsed = V.ParseFen(fen);
static IsGoodFen(fen) {
if (!ChessRules.IsGoodFen(fen)) return false;
const fenParsed = V.ParseFen(fen);
@@
-35,7
+39,7
@@
export class ShogiRules extends ChessRules {
static get SILVER_G() {
return "s";
}
static get SILVER_G() {
return "s";
}
- static get LANCE
R
() {
+ static get LANCE() {
return "l";
}
return "l";
}
@@
-49,7
+53,7
@@
export class ShogiRules extends ChessRules {
static get P_SILVER() {
return 't';
}
static get P_SILVER() {
return 't';
}
- static get P_LANCE
R
() {
+ static get P_LANCE() {
return 'm';
}
static get P_ROOK() {
return 'm';
}
static get P_ROOK() {
@@
-68,11
+72,11
@@
export class ShogiRules extends ChessRules {
ChessRules.KING,
V.GOLD_G,
V.SILVER_G,
ChessRules.KING,
V.GOLD_G,
V.SILVER_G,
- V.LANCE
R
,
+ V.LANCE,
V.P_PAWN,
V.P_KNIGHT,
V.P_SILVER,
V.P_PAWN,
V.P_KNIGHT,
V.P_SILVER,
- V.P_LANCE
R
,
+ V.P_LANCE,
V.P_ROOK,
V.P_BISHOP
];
V.P_ROOK,
V.P_BISHOP
];
@@
-149,7
+153,7
@@
export class ShogiRules extends ChessRules {
[V.GOLD_G]: parseInt(fenParsed.reserve[3]),
[V.SILVER_G]: parseInt(fenParsed.reserve[4]),
[V.KNIGHT]: parseInt(fenParsed.reserve[5]),
[V.GOLD_G]: parseInt(fenParsed.reserve[3]),
[V.SILVER_G]: parseInt(fenParsed.reserve[4]),
[V.KNIGHT]: parseInt(fenParsed.reserve[5]),
- [V.LANCE
R
]: parseInt(fenParsed.reserve[6])
+ [V.LANCE]: parseInt(fenParsed.reserve[6])
},
b: {
[V.PAWN]: parseInt(fenParsed.reserve[7]),
},
b: {
[V.PAWN]: parseInt(fenParsed.reserve[7]),
@@
-158,7
+162,7
@@
export class ShogiRules extends ChessRules {
[V.GOLD_G]: parseInt(fenParsed.reserve[10]),
[V.SILVER_G]: parseInt(fenParsed.reserve[11]),
[V.KNIGHT]: parseInt(fenParsed.reserve[12]),
[V.GOLD_G]: parseInt(fenParsed.reserve[10]),
[V.SILVER_G]: parseInt(fenParsed.reserve[11]),
[V.KNIGHT]: parseInt(fenParsed.reserve[12]),
- [V.LANCE
R
]: parseInt(fenParsed.reserve[13])
+ [V.LANCE]: parseInt(fenParsed.reserve[13])
}
};
}
}
};
}
@@
-187,7
+191,7
@@
export class ShogiRules extends ChessRules {
// Ordering on reserve pieces
static get RESERVE_PIECES() {
return (
// Ordering on reserve pieces
static get RESERVE_PIECES() {
return (
- [V.PAWN, V.ROOK, V.BISHOP, V.GOLD_G, V.SILVER_G, V.KNIGHT, V.LANCE
R
]
+ [V.PAWN, V.ROOK, V.BISHOP, V.GOLD_G, V.SILVER_G, V.KNIGHT, V.LANCE]
);
}
);
}
@@
-213,7
+217,7
@@
export class ShogiRules extends ChessRules {
const lastRanks = color == 'w' ? [0, 1] : [8, 7];
for (let i = 0; i < V.size.x; i++) {
if (
const lastRanks = color == 'w' ? [0, 1] : [8, 7];
for (let i = 0; i < V.size.x; i++) {
if (
- (i == lastRanks[0] && [V.PAWN, V.KNIGHT, V.LANCE
R
].includes(p)) ||
+ (i == lastRanks[0] && [V.PAWN, V.KNIGHT, V.LANCE].includes(p)) ||
(i == lastRanks[1] && p == V.KNIGHT)
) {
continue;
(i == lastRanks[1] && p == V.KNIGHT)
) {
continue;
@@
-266,8
+270,8
@@
export class ShogiRules extends ChessRules {
return this.getPotentialBishopMoves([x, y]);
case V.SILVER_G:
return this.getPotentialSilverMoves([x, y]);
return this.getPotentialBishopMoves([x, y]);
case V.SILVER_G:
return this.getPotentialSilverMoves([x, y]);
- case V.LANCE
R
:
- return this.getPotentialLance
r
Moves([x, y]);
+ case V.LANCE:
+ return this.getPotentialLanceMoves([x, y]);
case V.KING:
return this.getPotentialKingMoves([x, y]);
case V.P_ROOK:
case V.KING:
return this.getPotentialKingMoves([x, y]);
case V.P_ROOK:
@@
-278,7
+282,7
@@
export class ShogiRules extends ChessRules {
case V.P_PAWN:
case V.P_SILVER:
case V.P_KNIGHT:
case V.P_PAWN:
case V.P_SILVER:
case V.P_KNIGHT:
- case V.P_LANCE
R
:
+ case V.P_LANCE:
return this.getPotentialGoldMoves([x, y]);
}
return []; //never reached
return this.getPotentialGoldMoves([x, y]);
}
return []; //never reached
@@
-372,6
+376,18
@@
export class ShogiRules extends ChessRules {
);
}
);
}
+ getPotentialLanceMoves(sq) {
+ const forward = (this.turn == 'w' ? -1 : 1);
+ return this.getSlideNJumpMoves(
+ sq,
+ [[forward, 0]],
+ {
+ promote: V.P_LANCE,
+ force: true
+ }
+ );
+ }
+
getPotentialRookMoves(sq) {
return this.getSlideNJumpMoves(
sq, V.steps[V.ROOK], { promote: V.P_ROOK });
getPotentialRookMoves(sq) {
return this.getSlideNJumpMoves(
sq, V.steps[V.ROOK], { promote: V.P_ROOK });
@@
-382,12
+398,6
@@
export class ShogiRules extends ChessRules {
sq, V.steps[V.BISHOP], { promote: V.P_BISHOP });
}
sq, V.steps[V.BISHOP], { promote: V.P_BISHOP });
}
- getPotentialLancerMoves(sq) {
- const forward = (this.turn == 'w' ? -1 : 1);
- return this.getSlideNJumpMoves(
- sq, [[forward, 0]], { promote: V.P_LANCER });
- }
-
getPotentialDragonMoves(sq) {
return (
this.getSlideNJumpMoves(sq, V.steps[V.ROOK]).concat(
getPotentialDragonMoves(sq) {
return (
this.getSlideNJumpMoves(sq, V.steps[V.ROOK]).concat(
@@
-418,7
+428,7
@@
export class ShogiRules extends ChessRules {
this.isAttackedByKnight(sq, color) ||
this.isAttackedByBishop(sq, color) ||
this.isAttackedByHorse(sq, color) ||
this.isAttackedByKnight(sq, color) ||
this.isAttackedByBishop(sq, color) ||
this.isAttackedByHorse(sq, color) ||
- this.isAttackedByLance
r
(sq, color) ||
+ this.isAttackedByLance(sq, color) ||
this.isAttackedBySilver(sq, color) ||
this.isAttackedByGold(sq, color) ||
this.isAttackedByKing(sq, color)
this.isAttackedBySilver(sq, color) ||
this.isAttackedByGold(sq, color) ||
this.isAttackedByKing(sq, color)
@@
-433,7
+443,7
@@
export class ShogiRules extends ChessRules {
V.OnBoard(i, j) &&
this.board[i][j] != V.EMPTY &&
this.getColor(i, j) == color &&
V.OnBoard(i, j) &&
this.board[i][j] != V.EMPTY &&
this.getColor(i, j) == color &&
- [V.GOLD_G, V.P_PAWN, V.P_SILVER, V.P_KNIGHT, V.P_LANCE
R
]
+ [V.GOLD_G, V.P_PAWN, V.P_SILVER, V.P_KNIGHT, V.P_LANCE]
.includes(this.getPiece(i, j))
) {
return true;
.includes(this.getPiece(i, j))
) {
return true;
@@
-475,9
+485,9
@@
export class ShogiRules extends ChessRules {
sq, color, V.KNIGHT, [[forward, 1], [forward, -1]], "oneStep");
}
sq, color, V.KNIGHT, [[forward, 1], [forward, -1]], "oneStep");
}
- isAttackedByLance
r
(sq, color) {
+ isAttackedByLance(sq, color) {
const forward = (color == 'w' ? 1 : -1);
const forward = (color == 'w' ? 1 : -1);
- return this.isAttackedBySlideNJump(sq, color, V.LANCE
R
, [[forward, 0]]);
+ return this.isAttackedBySlideNJump(sq, color, V.LANCE, [[forward, 0]]);
}
isAttackedByDragon(sq, color) {
}
isAttackedByDragon(sq, color) {