880f0082a97f4fa10f30b4c33c12561ef1f386c4
1 import { ChessRules
} from "@/base_rules";
3 export class ArenaRules
extends ChessRules
{
12 static get HasFlags() {
16 static get PawnSpecs() {
20 { captureBackward: true }
24 static IsGoodPosition(position
) {
25 if (position
.length
== 0) return false;
26 const rows
= position
.split("/");
27 if (rows
.length
!= V
.size
.x
) return false;
28 // At most and at least one king or queen per color
29 let royals
= { "k": 0, "K": 0, "q": 0, "Q": 0 };
30 for (let row
of rows
) {
32 for (let i
= 0; i
< row
.length
; i
++) {
33 if (['K','k','Q','q'].includes(row
[i
])) royals
[row
[i
]]++;
34 if (V
.PIECES
.includes(row
[i
].toLowerCase())) sumElts
++;
36 const num
= parseInt(row
[i
], 10);
37 if (isNaN(num
)) return false;
41 if (sumElts
!= V
.size
.y
) return false;
44 Object
.values(royals
).some(v
=> v
>= 2) ||
45 royals
['K'] + royals
['Q'] == 0 ||
46 royals
['k'] + royals
['q'] == 0
55 static GenRandInitFen(options
) {
56 return ChessRules
.GenRandInitFen(options
).slice(0, -6) + "-";
60 return Math
.abs(3.5 - x
) <= 1.5;
63 getPotentialMovesFrom([x
, y
]) {
64 const moves
= super.getPotentialMovesFrom([x
, y
]);
65 // Eliminate moves which neither enter the arena or capture something
66 return moves
.filter(m
=> {
67 const startInArena
= V
.InArena(m
.start
.x
);
68 const endInArena
= V
.InArena(m
.end
.x
);
70 (startInArena
&& endInArena
&& m
.vanish
.length
== 2) ||
71 (!startInArena
&& endInArena
)
78 getPotentialQueenMoves(sq
) {
79 return super.getSlideNJumpMoves(
80 sq
, V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]), 3);
83 getPotentialKingMoves(sq
) {
84 return super.getSlideNJumpMoves(
85 sq
, V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]), 3);
93 // No check conditions
97 postPlay() {} //no kingPos no castleFlags
101 const color
= this.turn
;
102 if (!this.atLeastOneMove())
103 // I cannot move anymore
104 return color
== "w" ? "0-1" : "1-0";
105 // Win if the opponent has no more pieces left (in the Arena),
106 // (and/)or if he lost both his dukes.
107 let someUnitRemain
= false;
108 let atLeastOneDuke
= false;
109 let somethingInArena
= false;
110 outerLoop: for (let i
=0; i
<V
.size
.x
; i
++) {
111 for (let j
=0; j
<V
.size
.y
; j
++) {
112 if (this.getColor(i
,j
) == color
) {
113 someUnitRemain
= true;
114 if (this.movesCount
>= 2 && V
.InArena(i
)) {
115 somethingInArena
= true;
119 if ([V
.QUEEN
,V
.KING
].includes(this.getPiece(i
,j
))) {
120 atLeastOneDuke
= true;
121 if (this.movesCount
< 2 || somethingInArena
)
130 (this.movesCount
>= 2 && !somethingInArena
)
132 return color
== "w" ? "0-1" : "1-0";
137 static get SEARCH_DEPTH() {