1 import { ChessRules
} from "@/base_rules";
3 export const VariantRules
= class ArenaRules
extends ChessRules
{
4 static get hasFlags() {
8 static GenRandInitFen() {
9 return ChessRules
.GenRandInitFen().replace("w 1111 -", "w -");
13 return Math
.abs(3.5 - x
) <= 1.5;
16 getPotentialMovesFrom([x
, y
]) {
17 const moves
= super.getPotentialMovesFrom([x
, y
]);
18 // Eliminate moves which neither enter the arena or capture something
19 return moves
.filter(m
=> {
20 const startInArena
= V
.InArena(m
.start
.x
);
21 const endInArena
= V
.InArena(m
.end
.x
);
23 (startInArena
&& endInArena
&& m
.vanish
.length
== 2) ||
24 (!startInArena
&& endInArena
)
31 getPotentialPawnMoves([x
, y
]) {
32 const color
= this.turn
;
34 const [sizeX
, sizeY
] = [V
.size
.x
, V
.size
.y
];
35 const shiftX
= color
== "w" ? -1 : 1;
36 const startRank
= color
== "w" ? sizeX
- 2 : 1;
38 if (this.board
[x
+ shiftX
][y
] == V
.EMPTY
) {
40 moves
.push(this.getBasicMove([x
, y
], [x
+ shiftX
, y
]));
41 // Next condition because pawns on 1st rank can generally jump
44 this.board
[x
+ 2 * shiftX
][y
] == V
.EMPTY
47 moves
.push(this.getBasicMove([x
, y
], [x
+ 2 * shiftX
, y
]));
51 for (let shiftY
of [-1, 1]) {
55 this.board
[x
+ shiftX
][y
+ shiftY
] != V
.EMPTY
&&
56 this.canTake([x
, y
], [x
+ shiftX
, y
+ shiftY
])
58 moves
.push(this.getBasicMove([x
, y
], [x
+ shiftX
, y
+ shiftY
]));
63 const Lep
= this.epSquares
.length
;
64 const epSquare
= this.epSquares
[Lep
- 1]; //always at least one element
67 epSquare
.x
== x
+ shiftX
&&
68 Math
.abs(epSquare
.y
- y
) == 1
70 let enpassantMove
= this.getBasicMove([x
, y
], [epSquare
.x
, epSquare
.y
]);
71 enpassantMove
.vanish
.push({
75 c: this.getColor(x
, epSquare
.y
)
77 moves
.push(enpassantMove
);
83 getPotentialQueenMoves(sq
) {
84 return this.getSlideNJumpMoves(
86 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
])
88 // Filter out moves longer than 3 squares
90 Math
.abs(m
.end
.x
- m
.start
.x
),
91 Math
.abs(m
.end
.y
- m
.start
.y
)) <= 3;
95 getPotentialKingMoves(sq
) {
96 return this.getSlideNJumpMoves(
98 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
])
100 // Filter out moves longer than 3 squares
102 Math
.abs(m
.end
.x
- m
.start
.x
),
103 Math
.abs(m
.end
.y
- m
.start
.y
)) <= 3;
112 // No check conditions
117 const color
= this.turn
;
118 if (!this.atLeastOneMove())
119 // I cannot move anymore
120 return color
== "w" ? "0-1" : "1-0";
121 // Win if the opponent has no more pieces left (in the Arena),
122 // (and/)or if he lost both his dukes.
123 let someUnitRemain
= false;
124 let atLeastOneDuke
= false;
125 let somethingInArena
= false;
126 outerLoop: for (let i
=0; i
<V
.size
.x
; i
++) {
127 for (let j
=0; j
<V
.size
.y
; j
++) {
128 if (this.getColor(i
,j
) == color
) {
129 someUnitRemain
= true;
130 if (this.movesCount
>= 2 && V
.InArena(i
)) {
131 somethingInArena
= true;
135 if ([V
.QUEEN
,V
.KING
].includes(this.getPiece(i
,j
))) {
136 atLeastOneDuke
= true;
137 if (this.movesCount
< 2 || somethingInArena
)
146 (this.movesCount
>= 2 && !somethingInArena
)
148 return color
== "w" ? "0-1" : "1-0";