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
], 10);
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 // 20 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') return moves
;
51 return super.filterValid(moves
);
55 if (this.turn
== 'w') return [];
58 ? [JSON
.parse(JSON
.stringify(this.kingPos
['b']))]
64 if (this.turn
== 'w') {
65 // Do I have any unit remaining? If not, I lost.
66 // If yes and no available move, draw.
67 let somethingRemains
= false;
68 outerLoop: for (let i
=0; i
<8; i
++) {
69 for (let j
=0; j
<8; j
++) {
70 if (this.board
[i
][j
] != V
.EMPTY
&& this.getColor(i
, j
) == 'w') {
71 somethingRemains
= true;
76 if (!somethingRemains
) return "0-1";
77 if (this.atLeastOneMove()) return "*";
80 // From black side, just run usual checks:
81 return super.getCurrentScore();