1 import { ChessRules
} from "@/base_rules";
3 export const VariantRules
= class ArenaRules
extends ChessRules
{
4 static get hasFlags() {
8 static GenRandInitFen(randomness
) {
10 .GenRandInitFen(randomness
)
11 .replace("w 0 1111 -", "w 0 -");
15 return Math
.abs(3.5 - x
) <= 1.5;
18 getPotentialMovesFrom([x
, y
]) {
19 const moves
= super.getPotentialMovesFrom([x
, y
]);
20 // Eliminate moves which neither enter the arena or capture something
21 return moves
.filter(m
=> {
22 const startInArena
= V
.InArena(m
.start
.x
);
23 const endInArena
= V
.InArena(m
.end
.x
);
25 (startInArena
&& endInArena
&& m
.vanish
.length
== 2) ||
26 (!startInArena
&& endInArena
)
33 getPotentialPawnMoves([x
, y
]) {
34 const color
= this.turn
;
36 const [sizeX
, sizeY
] = [V
.size
.x
, V
.size
.y
];
37 const shiftX
= color
== "w" ? -1 : 1;
38 const startRank
= color
== "w" ? sizeX
- 2 : 1;
40 if (this.board
[x
+ shiftX
][y
] == V
.EMPTY
) {
42 moves
.push(this.getBasicMove([x
, y
], [x
+ shiftX
, y
]));
43 // Next condition because pawns on 1st rank can generally jump
46 this.board
[x
+ 2 * shiftX
][y
] == V
.EMPTY
49 moves
.push(this.getBasicMove([x
, y
], [x
+ 2 * shiftX
, y
]));
52 // Captures: also possible backward
53 for (let shiftY
of [-1, 1]) {
54 if (y
+ shiftY
>= 0 && y
+ shiftY
< sizeY
) {
55 for (let direction
of [-1,1]) {
57 this.board
[x
+ direction
][y
+ shiftY
] != V
.EMPTY
&&
58 this.canTake([x
, y
], [x
+ direction
, y
+ shiftY
])
60 moves
.push(this.getBasicMove([x
, y
], [x
+ direction
, y
+ shiftY
]));
67 const Lep
= this.epSquares
.length
;
68 const epSquare
= this.epSquares
[Lep
- 1]; //always at least one element
71 epSquare
.x
== x
+ shiftX
&&
72 Math
.abs(epSquare
.y
- y
) == 1
74 let enpassantMove
= this.getBasicMove([x
, y
], [epSquare
.x
, epSquare
.y
]);
75 enpassantMove
.vanish
.push({
79 c: this.getColor(x
, epSquare
.y
)
81 moves
.push(enpassantMove
);
87 getPotentialQueenMoves(sq
) {
88 return this.getSlideNJumpMoves(
90 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
])
92 // Filter out moves longer than 3 squares
94 Math
.abs(m
.end
.x
- m
.start
.x
),
95 Math
.abs(m
.end
.y
- m
.start
.y
)) <= 3;
99 getPotentialKingMoves(sq
) {
100 return this.getSlideNJumpMoves(
102 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
])
104 // Filter out moves longer than 3 squares
106 Math
.abs(m
.end
.x
- m
.start
.x
),
107 Math
.abs(m
.end
.y
- m
.start
.y
)) <= 3;
116 // No check conditions
121 const color
= this.turn
;
122 if (!this.atLeastOneMove())
123 // I cannot move anymore
124 return color
== "w" ? "0-1" : "1-0";
125 // Win if the opponent has no more pieces left (in the Arena),
126 // (and/)or if he lost both his dukes.
127 let someUnitRemain
= false;
128 let atLeastOneDuke
= false;
129 let somethingInArena
= false;
130 outerLoop: for (let i
=0; i
<V
.size
.x
; i
++) {
131 for (let j
=0; j
<V
.size
.y
; j
++) {
132 if (this.getColor(i
,j
) == color
) {
133 someUnitRemain
= true;
134 if (this.movesCount
>= 2 && V
.InArena(i
)) {
135 somethingInArena
= true;
139 if ([V
.QUEEN
,V
.KING
].includes(this.getPiece(i
,j
))) {
140 atLeastOneDuke
= true;
141 if (this.movesCount
< 2 || somethingInArena
)
150 (this.movesCount
>= 2 && !somethingInArena
)
152 return color
== "w" ? "0-1" : "1-0";