1 import ChessRules
from "/base_rules.js";
3 export default class ArenaRules
extends ChessRules
{
14 let board
= super.getSvgChessboard().slice(0, -6);
15 // Add lines to delimitate the central area
17 <line x1="0" y1="20" x2="80" y2="20" stroke="black" stroke-width="0.15"/>
18 <line x1="0" y1="60" x2="80" y2="60" stroke="black" stroke-width="0.15"/>
24 let allSpecs
= super.pieces(color
, x
, y
);
25 let pawnSpec
= allSpecs
['p'],
26 queenSpec
= allSpecs
['q'],
27 kingSpec
= allSpecs
['k'];
28 const pawnShift
= (color
== "w" ? -1 : 1);
29 Array
.prototype.push
.apply(pawnSpec
.attack
[0].steps
,
30 [[-pawnShift
, 1], [-pawnShift
, -1]]);
31 queenSpec
.both
[0].range
= 3;
32 kingSpec
.both
[0].range
= 3;
33 return Object
.assign({},
44 return Math
.abs(3.5 - x
) <= 1.5;
47 getPotentialMovesFrom([x
, y
]) {
48 const moves
= super.getPotentialMovesFrom([x
, y
]);
49 // Eliminate moves which neither enter the arena or capture something
50 return moves
.filter(m
=> {
51 const startInArena
= V
.InArena(m
.start
.x
);
52 const endInArena
= V
.InArena(m
.end
.x
);
54 (startInArena
&& endInArena
&& m
.vanish
.length
== 2) ||
55 (!startInArena
&& endInArena
)
61 // No check conditions
66 const color
= this.turn
;
67 if (!this.atLeastOneMove(color
))
68 // I cannot move anymore
69 return color
== 'w' ? "0-1" : "1-0";
70 // Win if the opponent has no more pieces left (in the Arena),
71 // (and/)or if he lost both his dukes.
72 let someUnitRemain
= false,
73 atLeastOneDuke
= false,
74 somethingInArena
= false;
75 outerLoop: for (let i
=0; i
<this.size
.x
; i
++) {
76 for (let j
=0; j
<this.size
.y
; j
++) {
77 if (this.getColor(i
,j
) == color
) {
78 someUnitRemain
= true;
79 if (this.movesCount
>= 2 && V
.InArena(i
)) {
80 somethingInArena
= true;
84 if (['q', 'k'].includes(this.getPiece(i
, j
))) {
85 atLeastOneDuke
= true;
86 if (this.movesCount
< 2 || somethingInArena
)
95 (this.movesCount
>= 2 && !somethingInArena
)
97 return color
== 'w' ? "0-1" : "1-0";