projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Simplify Monster + Doublemove2. Smoother example games
[vchess.git]
/
client
/
src
/
variants
/
Wildebeest.js
diff --git
a/client/src/variants/Wildebeest.js
b/client/src/variants/Wildebeest.js
index
933abbd
..
526da1a
100644
(file)
--- a/
client/src/variants/Wildebeest.js
+++ b/
client/src/variants/Wildebeest.js
@@
-2,11
+2,7
@@
import { ChessRules } from "@/base_rules";
import { ArrayFun } from "@/utils/array";
import { sample, randInt } from "@/utils/alea";
import { ArrayFun } from "@/utils/array";
import { sample, randInt } from "@/utils/alea";
-export const VariantRules = class WildebeestRules extends ChessRules {
- static getPpath(b) {
- return ([V.CAMEL, V.WILDEBEEST].includes(b[1]) ? "Wildebeest/" : "") + b;
- }
-
+export class WildebeestRules extends ChessRules {
static get size() {
return { x: 10, y: 11 };
}
static get size() {
return { x: 10, y: 11 };
}
@@
-24,7
+20,9
@@
export const VariantRules = class WildebeestRules extends ChessRules {
static get steps() {
return Object.assign(
static get steps() {
return Object.assign(
- ChessRules.steps, //add camel moves:
+ {},
+ ChessRules.steps,
+ // Add camel moves:
{
c: [
[-3, -1],
{
c: [
[-3, -1],
@@
-41,17
+39,14
@@
export const VariantRules = class WildebeestRules extends ChessRules {
}
static IsGoodEnpassant(enpassant) {
}
static IsGoodEnpassant(enpassant) {
- if (enpassant != "-") {
- const squares = enpassant.split(",");
- if (squares.length > 2) return false;
- for (let sq of squares) {
- const ep = V.SquareToCoords(sq);
- if (isNaN(ep.x) || !V.OnBoard(ep)) return false;
- }
- }
+ if (enpassant != "-") return !!enpassant.match(/^([a-j][0-9]{1,2},?)+$/);
return true;
}
return true;
}
+ getPpath(b) {
+ return ([V.CAMEL, V.WILDEBEEST].includes(b[1]) ? "Wildebeest/" : "") + b;
+ }
+
// There may be 2 enPassant squares (if pawn jump 3 squares)
getEnpassantFen() {
const L = this.epSquares.length;
// There may be 2 enPassant squares (if pawn jump 3 squares)
getEnpassantFen() {
const L = this.epSquares.length;
@@
-117,8
+112,9
@@
export const VariantRules = class WildebeestRules extends ChessRules {
const shiftX = color == "w" ? -1 : 1;
const startRanks = color == "w" ? [sizeX - 2, sizeX - 3] : [1, 2];
const lastRank = color == "w" ? 0 : sizeX - 1;
const shiftX = color == "w" ? -1 : 1;
const startRanks = color == "w" ? [sizeX - 2, sizeX - 3] : [1, 2];
const lastRank = color == "w" ? 0 : sizeX - 1;
- const finalPieces =
- x + shiftX == lastRank ? [V.ROOK, V.KNIGHT, V.BISHOP, V.QUEEN] : [V.PAWN];
+ const finalPieces = x + shiftX == lastRank
+ ? [V.WILDEBEEST, V.QUEEN]
+ : [V.PAWN];
if (this.board[x + shiftX][y] == V.EMPTY) {
// One square forward
if (this.board[x + shiftX][y] == V.EMPTY) {
// One square forward
@@
-159,7
+155,7
@@
export const VariantRules = class WildebeestRules extends ChessRules {
// En passant
const Lep = this.epSquares.length;
const epSquare = this.epSquares[Lep - 1];
// En passant
const Lep = this.epSquares.length;
const epSquare = this.epSquares[Lep - 1];
- if (epSquare) {
+ if (
!!
epSquare) {
for (let epsq of epSquare) {
// TODO: some redundant checks
if (epsq.x == x + shiftX && Math.abs(epsq.y - y) == 1) {
for (let epsq of epSquare) {
// TODO: some redundant checks
if (epsq.x == x + shiftX && Math.abs(epsq.y - y) == 1) {
@@
-195,28
+191,28
@@
export const VariantRules = class WildebeestRules extends ChessRules {
);
}
);
}
- isAttacked(sq, color
s
) {
+ isAttacked(sq, color) {
return (
return (
- super.isAttacked(sq, color
s
) ||
- this.isAttackedByCamel(sq, color
s
) ||
- this.isAttackedByWildebeest(sq, color
s
)
+ super.isAttacked(sq, color) ||
+ this.isAttackedByCamel(sq, color) ||
+ this.isAttackedByWildebeest(sq, color)
);
}
);
}
- isAttackedByCamel(sq, color
s
) {
+ isAttackedByCamel(sq, color) {
return this.isAttackedBySlideNJump(
sq,
return this.isAttackedBySlideNJump(
sq,
- color
s
,
+ color,
V.CAMEL,
V.steps[V.CAMEL],
"oneStep"
);
}
V.CAMEL,
V.steps[V.CAMEL],
"oneStep"
);
}
- isAttackedByWildebeest(sq, color
s
) {
+ isAttackedByWildebeest(sq, color) {
return this.isAttackedBySlideNJump(
sq,
return this.isAttackedBySlideNJump(
sq,
- color
s
,
+ color,
V.WILDEBEEST,
V.steps[V.KNIGHT].concat(V.steps[V.CAMEL]),
"oneStep"
V.WILDEBEEST,
V.steps[V.KNIGHT].concat(V.steps[V.CAMEL]),
"oneStep"
@@
-224,18
+220,15
@@
export const VariantRules = class WildebeestRules extends ChessRules {
}
getCurrentScore() {
}
getCurrentScore() {
- if (this.atLeastOneMove())
- // game not over
- return "*";
-
+ if (this.atLeastOneMove()) return "*";
// No valid move: game is lost (stalemate is a win)
return this.turn == "w" ? "0-1" : "1-0";
}
static get VALUES() {
return Object.assign(
// No valid move: game is lost (stalemate is a win)
return this.turn == "w" ? "0-1" : "1-0";
}
static get VALUES() {
return Object.assign(
- ChessRules.VALUES,
- { c: 3, w: 7 } //experimental
+ { c: 3, w: 7 }, //experimental
+ ChessRules.VALUES
);
}
);
}
@@
-243,9
+236,24
@@
export const VariantRules = class WildebeestRules extends ChessRules {
return 2;
}
return 2;
}
- static GenRandInitFen() {
- let pieces = { w: new Array(10), b: new Array(10) };
+ static GenRandInitFen(randomness) {
+ if (!randomness) randomness = 2;
+ if (randomness == 0) {
+ return (
+ "rnccwkqbbnr/ppppppppppp/92/92/92/92/92/92/PPPPPPPPPPP/RNBBQKWCCNR " +
+ "w 0 akak -"
+ );
+ }
+
+ let pieces = { w: new Array(11), b: new Array(11) };
+ let flags = "";
for (let c of ["w", "b"]) {
for (let c of ["w", "b"]) {
+ if (c == 'b' && randomness == 1) {
+ pieces['b'] = pieces['w'];
+ flags += flags;
+ break;
+ }
+
let positions = ArrayFun.range(11);
// Get random squares for bishops + camels (different colors)
let positions = ArrayFun.range(11);
// Get random squares for bishops + camels (different colors)
@@
-263,7
+271,7
@@
export const VariantRules = class WildebeestRules extends ChessRules {
for (let idx of randIndexes.concat(randIndexes_tmp).sort((a, b) => {
return b - a;
})) {
for (let idx of randIndexes.concat(randIndexes_tmp).sort((a, b) => {
return b - a;
})) {
- //
l
argest indices first
+ //
L
argest indices first
positions.splice(idx, 1);
}
positions.splice(idx, 1);
}
@@
-298,12
+306,13
@@
export const VariantRules = class WildebeestRules extends ChessRules {
pieces[c][bishop2Pos] = "b";
pieces[c][knight2Pos] = "n";
pieces[c][rook2Pos] = "r";
pieces[c][bishop2Pos] = "b";
pieces[c][knight2Pos] = "n";
pieces[c][rook2Pos] = "r";
+ flags += V.CoordToColumn(rook1Pos) + V.CoordToColumn(rook2Pos);
}
return (
pieces["b"].join("") +
}
return (
pieces["b"].join("") +
- "/ppppppppppp/
11/11/11/11/11/11
/PPPPPPPPPPP/" +
+ "/ppppppppppp/
92/92/92/92/92/92
/PPPPPPPPPPP/" +
pieces["w"].join("").toUpperCase() +
pieces["w"].join("").toUpperCase() +
- " w 0
1111
-"
+ " w 0
" + flags + "
-"
);
}
};
);
}
};