1 import { ChessRules
} from "@/base_rules";
3 export class HordeRules
extends ChessRules
{
4 static get HasFlags() {
8 static IsGoodPosition() {
9 // At least one white unit, and exactly one black king:
10 if (position
.length
== 0) return false;
11 const rows
= position
.split("/");
12 if (rows
.length
!= V
.size
.x
) return false;
13 let things
= { "k": 0, "w": false };
14 for (let row
of rows
) {
16 for (let i
= 0; i
< row
.length
; i
++) {
17 if (row
[i
] == 'k') things
['k']++;
18 if (V
.PIECES
.includes(row
[i
].toLowerCase())) {
19 const rowCharCode
= row
[i
].charCodeAt(0);
20 if (rowCharCode
>= 65 && rowCharCode
<= 90) {
22 if (row
[i
] == 'K') return false;
23 if (!things
['w']) things
['w'] = true;
27 const num
= parseInt(row
[i
]);
28 if (isNaN(num
)) return false;
32 if (sumElts
!= V
.size
.y
) return false;
34 if (things
[''] != 1 || !things
['w']) return false;
38 static GenRandInitFen(randomness
) {
39 if (randomness
== 2) randomness
--;
40 const fen
= ChessRules
.GenRandInitFen(randomness
);
42 // 27 first chars are 3 rows + 3 slashes
44 // En passant available, but no castle:
45 .concat("1PP2PP1/PPPPPPPP/PPPPPPPP/PPPPPPPP/PPPPPPPP w 0 -")
50 if (this.turn
== 'w') {
51 // Do I have any unit remaining? If not, I lost.
52 // If yes and no available move, draw.
53 let somethingRemains
= false;
54 outerLoop: for (let i
=0; i
<8; i
++) {
55 for (let j
=0; j
<8; j
++) {
56 if (this.board
[i
][j
] != V
.EMPTY
&& this.getColor(i
, j
) == 'w') {
57 somethingRemains
= true;
62 if (!somethingRemains
) return "0-1";
63 if (this.atLeastOneMove()) return "*";
66 // From black side, just run usual checks:
67 return super.getCurrentScore();