1 import { ChessRules
} from "@/base_rules";
3 export class HordeRules
extends ChessRules
{
17 static get HasFlags() {
21 static IsGoodPosition() {
22 // At least one white unit, and exactly one black king:
23 if (position
.length
== 0) return false;
24 const rows
= position
.split("/");
25 if (rows
.length
!= V
.size
.x
) return false;
26 let things
= { "k": 0, "w": false };
27 for (let row
of rows
) {
29 for (let i
= 0; i
< row
.length
; i
++) {
30 if (row
[i
] == 'k') things
['k']++;
31 if (V
.PIECES
.includes(row
[i
].toLowerCase())) {
32 const rowCharCode
= row
[i
].charCodeAt(0);
33 if (rowCharCode
>= 65 && rowCharCode
<= 90) {
35 if (row
[i
] == 'K') return false;
36 if (!things
['w']) things
['w'] = true;
40 const num
= parseInt(row
[i
], 10);
41 if (isNaN(num
)) return false;
45 if (sumElts
!= V
.size
.y
) return false;
47 if (things
[''] != 1 || !things
['w']) return false;
51 static GenRandInitFen(options
) {
53 ChessRules
.GenRandInitFen({ randomness: (options
.random
? 1 : 0) });
55 // 20 first chars are 3 rows + 3 slashes
57 // En passant available, but no castle:
58 .concat("1PP2PP1/PPPPPPPP/PPPPPPPP/PPPPPPPP/PPPPPPPP w 0 -")
63 if (this.turn
== 'w') return moves
;
64 return super.filterValid(moves
);
68 if (this.turn
== 'w') return [];
71 ? [JSON
.parse(JSON
.stringify(this.kingPos
['b']))]
77 if (this.turn
== 'w') {
78 // Do I have any unit remaining? If not, I lost.
79 // If yes and no available move, draw.
80 let somethingRemains
= false;
81 outerLoop: for (let i
=0; i
<8; i
++) {
82 for (let j
=0; j
<8; j
++) {
83 if (this.board
[i
][j
] != V
.EMPTY
&& this.getColor(i
, j
) == 'w') {
84 somethingRemains
= true;
89 if (!somethingRemains
) return "0-1";
90 if (this.atLeastOneMove()) return "*";
93 // From black side, just run usual checks:
94 return super.getCurrentScore();