b2b18ee6e981d8a1d8210ce5aba0a41b2e262dad
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 GenRandInitFen(randomness
) {
17 return ChessRules
.GenRandInitFen(randomness
).slice(0, -6) + "-";
21 return Math
.abs(3.5 - x
) <= 1.5;
24 getPotentialMovesFrom([x
, y
]) {
25 const moves
= super.getPotentialMovesFrom([x
, y
]);
26 // Eliminate moves which neither enter the arena or capture something
27 return moves
.filter(m
=> {
28 const startInArena
= V
.InArena(m
.start
.x
);
29 const endInArena
= V
.InArena(m
.end
.x
);
31 (startInArena
&& endInArena
&& m
.vanish
.length
== 2) ||
32 (!startInArena
&& endInArena
)
39 getPotentialQueenMoves(sq
) {
40 return this.getSlideNJumpMoves(
42 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
])
44 // Filter out moves longer than 3 squares
46 Math
.abs(m
.end
.x
- m
.start
.x
),
47 Math
.abs(m
.end
.y
- m
.start
.y
)) <= 3;
51 getPotentialKingMoves(sq
) {
52 return this.getSlideNJumpMoves(
54 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
])
56 // Filter out moves longer than 3 squares
58 Math
.abs(m
.end
.x
- m
.start
.x
),
59 Math
.abs(m
.end
.y
- m
.start
.y
)) <= 3;
68 // No check conditions
73 const color
= this.turn
;
74 if (!this.atLeastOneMove())
75 // I cannot move anymore
76 return color
== "w" ? "0-1" : "1-0";
77 // Win if the opponent has no more pieces left (in the Arena),
78 // (and/)or if he lost both his dukes.
79 let someUnitRemain
= false;
80 let atLeastOneDuke
= false;
81 let somethingInArena
= false;
82 outerLoop: for (let i
=0; i
<V
.size
.x
; i
++) {
83 for (let j
=0; j
<V
.size
.y
; j
++) {
84 if (this.getColor(i
,j
) == color
) {
85 someUnitRemain
= true;
86 if (this.movesCount
>= 2 && V
.InArena(i
)) {
87 somethingInArena
= true;
91 if ([V
.QUEEN
,V
.KING
].includes(this.getPiece(i
,j
))) {
92 atLeastOneDuke
= true;
93 if (this.movesCount
< 2 || somethingInArena
)
102 (this.movesCount
>= 2 && !somethingInArena
)
104 return color
== "w" ? "0-1" : "1-0";
109 static get SEARCH_DEPTH() {