projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add Knightmate2: two kings, as in Spartan Chess
[vchess.git]
/
client
/
src
/
variants
/
Hidden.js
diff --git
a/client/src/variants/Hidden.js
b/client/src/variants/Hidden.js
index
c79267a
..
280062c
100644
(file)
--- a/
client/src/variants/Hidden.js
+++ b/
client/src/variants/Hidden.js
@@
-2,7
+2,8
@@
import { ChessRules, PiPo, Move } from "@/base_rules";
import { ArrayFun } from "@/utils/array";
import { randInt } from "@/utils/alea";
import { ArrayFun } from "@/utils/array";
import { randInt } from "@/utils/alea";
-export const VariantRules = class HiddenRules extends ChessRules {
+export class HiddenRules extends ChessRules {
+
static get HasFlags() {
return false;
}
static get HasFlags() {
return false;
}
@@
-11,14
+12,18
@@
export const VariantRules = class HiddenRules extends ChessRules {
return false;
}
return false;
}
+ static get SomeHiddenMoves() {
+ return true;
+ }
+
// Analyse in Hidden mode makes no sense
static get CanAnalyze() {
return false;
}
// Analyse in Hidden mode makes no sense
static get CanAnalyze() {
return false;
}
- // Moves are revealed only when game ends
+ // Moves are revealed only when game ends
, but are highlighted on board
static get ShowMoves() {
static get ShowMoves() {
- return "
none
";
+ return "
highlight
";
}
static get HIDDEN_DECODE() {
}
static get HIDDEN_DECODE() {
@@
-50,7
+55,7
@@
export const VariantRules = class HiddenRules extends ChessRules {
}
static get PIECES() {
}
static get PIECES() {
- return ChessRules.PIECES.concat(Object.
values(V.HIDDEN_
CODE));
+ return ChessRules.PIECES.concat(Object.
keys(V.HIDDEN_DE
CODE));
}
// Pieces can be hidden :)
}
// Pieces can be hidden :)
@@
-74,7
+79,7
@@
export const VariantRules = class HiddenRules extends ChessRules {
}
// Scan board for kings positions (no castling)
}
// Scan board for kings positions (no castling)
- scanKings
Rooks
(fen) {
+ scanKings(fen) {
this.kingPos = { w: [-1, -1], b: [-1, -1] };
const fenRows = V.ParseFen(fen).position.split("/");
for (let i = 0; i < fenRows.length; i++) {
this.kingPos = { w: [-1, -1], b: [-1, -1] };
const fenRows = V.ParseFen(fen).position.split("/");
for (let i = 0; i < fenRows.length; i++) {
@@
-90,7
+95,7
@@
export const VariantRules = class HiddenRules extends ChessRules {
this.kingPos["w"] = [i, k];
break;
default: {
this.kingPos["w"] = [i, k];
break;
default: {
- const num = parseInt(fenRows[i].charAt(j));
+ const num = parseInt(fenRows[i].charAt(j)
, 10
);
if (!isNaN(num)) k += num - 1;
}
}
if (!isNaN(num)) k += num - 1;
}
}
@@
-143,20
+148,11
@@
export const VariantRules = class HiddenRules extends ChessRules {
return mv;
}
return mv;
}
- // What are the king moves from square x,y ?
- getPotentialKingMoves(sq) {
- // No castling:
- return this.getSlideNJumpMoves(
- sq,
- V.steps[V.ROOK].concat(V.steps[V.BISHOP]),
- "oneStep"
- );
- }
-
filterValid(moves) {
return moves;
}
filterValid(moves) {
return moves;
}
+ // Ignore randomness here: placement is always random asymmetric
static GenRandInitFen() {
let pieces = { w: new Array(8), b: new Array(8) };
// Shuffle pieces + pawns on two first ranks
static GenRandInitFen() {
let pieces = { w: new Array(8), b: new Array(8) };
// Shuffle pieces + pawns on two first ranks
@@
-214,9
+210,11
@@
export const VariantRules = class HiddenRules extends ChessRules {
pieces[c][rook2Pos] = "u";
}
let upFen = pieces["b"].join("");
pieces[c][rook2Pos] = "u";
}
let upFen = pieces["b"].join("");
- upFen = upFen.substr(0,8) + "/" + upFen.substr(8).split("").reverse().join("");
+ upFen = upFen.substr(0,8) + "/" +
+ upFen.substr(8).split("").reverse().join("");
let downFen = pieces["b"].join("").toUpperCase();
let downFen = pieces["b"].join("").toUpperCase();
- downFen = downFen.substr(0,8) + "/" + downFen.substr(8).split("").reverse().join("");
+ downFen = downFen.substr(0,8) + "/" +
+ downFen.substr(8).split("").reverse().join("");
return upFen + "/8/8/8/8/" + downFen + " w 0";
}
return upFen + "/8/8/8/8/" + downFen + " w 0";
}
@@
-224,8
+222,8
@@
export const VariantRules = class HiddenRules extends ChessRules {
return [];
}
return [];
}
-
updateVariables
(move) {
- super.
updateVariables
(move);
+
postPlay
(move) {
+ super.
postPlay
(move);
if (
move.vanish.length >= 2 &&
[V.KING,V.HIDDEN_CODE[V.KING]].includes(move.vanish[1].p)
if (
move.vanish.length >= 2 &&
[V.KING,V.HIDDEN_CODE[V.KING]].includes(move.vanish[1].p)
@@
-235,8
+233,8
@@
export const VariantRules = class HiddenRules extends ChessRules {
}
}
}
}
-
unupdateVariables
(move) {
- super.
unupdateVariables
(move);
+
postUndo
(move) {
+ super.
postUndo
(move);
const c = move.vanish[0].c;
const oppCol = V.GetOppCol(c);
if (this.kingPos[oppCol][0] < 0)
const c = move.vanish[0].c;
const oppCol = V.GetOppCol(c);
if (this.kingPos[oppCol][0] < 0)
@@
-264,9
+262,10
@@
export const VariantRules = class HiddenRules extends ChessRules {
if (move.vanish.length == 2 && move.vanish[1].c != color) {
// OK this isn't a castling move
const myPieceVal = V.VALUES[move.appear[0].p];
if (move.vanish.length == 2 && move.vanish[1].c != color) {
// OK this isn't a castling move
const myPieceVal = V.VALUES[move.appear[0].p];
- const hisPieceVal = Object.keys(V.HIDDEN_DECODE).includes(move.vanish[1].p)
- ? undefined
- : V.VALUES[move.vanish[1].p];
+ const hisPieceVal =
+ Object.keys(V.HIDDEN_DECODE).includes(move.vanish[1].p)
+ ? undefined
+ : V.VALUES[move.vanish[1].p];
if (!hisPieceVal) {
// Opponent's piece is unknown: do not take too much risk
move.eval = -myPieceVal + 1.5; //so that pawns always take
if (!hisPieceVal) {
// Opponent's piece is unknown: do not take too much risk
move.eval = -myPieceVal + 1.5; //so that pawns always take
@@
-285,7
+284,8
@@
export const VariantRules = class HiddenRules extends ChessRules {
// If no capture, favor small step moves,
// but sometimes move the knight anyway
const penalty = V.Decode(move.vanish[0].p) != V.KNIGHT
// If no capture, favor small step moves,
// but sometimes move the knight anyway
const penalty = V.Decode(move.vanish[0].p) != V.KNIGHT
- ? Math.abs(move.end.x - move.start.x) + Math.abs(move.end.y - move.start.y)
+ ? Math.abs(move.end.x - move.start.x) +
+ Math.abs(move.end.y - move.start.y)
: (Math.random() < 0.5 ? 3 : 1);
move.eval -= penalty / (V.size.x + V.size.y - 1);
}
: (Math.random() < 0.5 ? 3 : 1);
move.eval -= penalty / (V.size.x + V.size.y - 1);
}
@@
-328,4
+328,5
@@
export const VariantRules = class HiddenRules extends ChessRules {
finalSquare
);
}
finalSquare
);
}
+
};
};