1 import { ChessRules
} from "@/base_rules";
3 export class ArenaRules
extends ChessRules
{
4 static get HasFlags() {
8 static get PawnSpecs() {
12 { captureBackward: true }
16 static IsGoodPosition(position
) {
17 if (position
.length
== 0) return false;
18 const rows
= position
.split("/");
19 if (rows
.length
!= V
.size
.x
) return false;
20 // At most and at least one king or queen per color
21 let royals
= { "k": 0, "K": 0, "q": 0, "Q": 0 };
22 for (let row
of rows
) {
24 for (let i
= 0; i
< row
.length
; i
++) {
25 if (['K','k','Q','q'].includes(row
[i
])) royals
[row
[i
]]++;
26 if (V
.PIECES
.includes(row
[i
].toLowerCase())) sumElts
++;
28 const num
= parseInt(row
[i
]);
29 if (isNaN(num
)) return false;
33 if (sumElts
!= V
.size
.y
) return false;
36 Object
.values(royals
).some(v
=> v
>= 2) ||
37 royals
['K'] + royals
['Q'] == 0 ||
38 royals
['k'] + royals
['q'] == 0
47 static GenRandInitFen(randomness
) {
48 return ChessRules
.GenRandInitFen(randomness
).slice(0, -6) + "-";
52 return Math
.abs(3.5 - x
) <= 1.5;
55 getPotentialMovesFrom([x
, y
]) {
56 const moves
= super.getPotentialMovesFrom([x
, y
]);
57 // Eliminate moves which neither enter the arena or capture something
58 return moves
.filter(m
=> {
59 const startInArena
= V
.InArena(m
.start
.x
);
60 const endInArena
= V
.InArena(m
.end
.x
);
62 (startInArena
&& endInArena
&& m
.vanish
.length
== 2) ||
63 (!startInArena
&& endInArena
)
70 getPotentialQueenMoves(sq
) {
71 return this.getSlideNJumpMoves(
73 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
])
75 // Filter out moves longer than 3 squares
77 Math
.abs(m
.end
.x
- m
.start
.x
),
78 Math
.abs(m
.end
.y
- m
.start
.y
)) <= 3;
82 getPotentialKingMoves(sq
) {
83 return this.getSlideNJumpMoves(
85 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
])
87 // Filter out moves longer than 3 squares
89 Math
.abs(m
.end
.x
- m
.start
.x
),
90 Math
.abs(m
.end
.y
- m
.start
.y
)) <= 3;
99 // No check conditions
103 postPlay() {} //no kingPos no castleFlags
107 const color
= this.turn
;
108 if (!this.atLeastOneMove())
109 // I cannot move anymore
110 return color
== "w" ? "0-1" : "1-0";
111 // Win if the opponent has no more pieces left (in the Arena),
112 // (and/)or if he lost both his dukes.
113 let someUnitRemain
= false;
114 let atLeastOneDuke
= false;
115 let somethingInArena
= false;
116 outerLoop: for (let i
=0; i
<V
.size
.x
; i
++) {
117 for (let j
=0; j
<V
.size
.y
; j
++) {
118 if (this.getColor(i
,j
) == color
) {
119 someUnitRemain
= true;
120 if (this.movesCount
>= 2 && V
.InArena(i
)) {
121 somethingInArena
= true;
125 if ([V
.QUEEN
,V
.KING
].includes(this.getPiece(i
,j
))) {
126 atLeastOneDuke
= true;
127 if (this.movesCount
< 2 || somethingInArena
)
136 (this.movesCount
>= 2 && !somethingInArena
)
138 return color
== "w" ? "0-1" : "1-0";
143 static get SEARCH_DEPTH() {