1 import { ChessRules
} from "@/base_rules";
3 export class HordeRules
extends ChessRules
{
5 static get HasFlags() {
9 static IsGoodPosition() {
10 // At least one white unit, and exactly one black king:
11 if (position
.length
== 0) return false;
12 const rows
= position
.split("/");
13 if (rows
.length
!= V
.size
.x
) return false;
14 let things
= { "k": 0, "w": false };
15 for (let row
of rows
) {
17 for (let i
= 0; i
< row
.length
; i
++) {
18 if (row
[i
] == 'k') things
['k']++;
19 if (V
.PIECES
.includes(row
[i
].toLowerCase())) {
20 const rowCharCode
= row
[i
].charCodeAt(0);
21 if (rowCharCode
>= 65 && rowCharCode
<= 90) {
23 if (row
[i
] == 'K') return false;
24 if (!things
['w']) things
['w'] = true;
28 const num
= parseInt(row
[i
], 10);
29 if (isNaN(num
)) return false;
33 if (sumElts
!= V
.size
.y
) return false;
35 if (things
[''] != 1 || !things
['w']) return false;
39 static GenRandInitFen(randomness
) {
40 if (randomness
== 2) randomness
--;
41 const fen
= ChessRules
.GenRandInitFen(randomness
);
43 // 20 first chars are 3 rows + 3 slashes
45 // En passant available, but no castle:
46 .concat("1PP2PP1/PPPPPPPP/PPPPPPPP/PPPPPPPP/PPPPPPPP w 0 -")
51 if (this.turn
== 'w') return moves
;
52 return super.filterValid(moves
);
56 if (this.turn
== 'w') return [];
59 ? [JSON
.parse(JSON
.stringify(this.kingPos
['b']))]
65 if (this.turn
== 'w') {
66 // Do I have any unit remaining? If not, I lost.
67 // If yes and no available move, draw.
68 let somethingRemains
= false;
69 outerLoop: for (let i
=0; i
<8; i
++) {
70 for (let j
=0; j
<8; j
++) {
71 if (this.board
[i
][j
] != V
.EMPTY
&& this.getColor(i
, j
) == 'w') {
72 somethingRemains
= true;
77 if (!somethingRemains
) return "0-1";
78 if (this.atLeastOneMove()) return "*";
81 // From black side, just run usual checks:
82 return super.getCurrentScore();