1 import ChessRules
from "/base_rules.js";
2 import {Random
} from "/utils/alea.js";
3 import PiPo
from "/utils/PiPo.js";
4 import Move
from "/utils/Move.js";
6 export default class AvalancheRules
extends ChessRules
{
10 select: C
.Options
.select
,
33 {promotion: o
.init
? false : this.promotion
},
38 setOtherVariables(fenParsed
) {
39 super.setOtherVariables(fenParsed
);
40 this.promotion
= (fenParsed
.promotion
== '1');
41 this.subTurn
= 1 - (this.promotion
? 1 : 0);
45 const myLastRank
= (this.turn
== 'w' ? 0 : this.size
.x
- 1);
48 coords
.x
!= myLastRank
||
49 this.getPiece(coords
.x
, coords
.y
) != 'p'
54 this.pawnPromotions
.forEach(pr
=> {
57 vanish: [new PiPo({x: coords
.x
, y: coords
.y
, c: this.turn
, p: 'p'})],
58 appear: [new PiPo({x: coords
.x
, y: coords
.y
, c: this.turn
, p: pr
})]
62 super.showChoices(moves
);
66 const pieceColor
= this.getColor(x
, y
);
68 this.playerColor
== this.turn
&&
70 (this.subTurn
<= 1 && pieceColor
== this.playerColor
) ||
73 pieceColor
!= this.playerColor
&&
74 this.getPiece(x
, y
) == 'p'
80 getPotentialMovesFrom([x
, y
]) {
81 if (this.subTurn
== 0)
83 if (this.subTurn
== 1)
85 return super.getPotentialMovesFrom([x
, y
]);
86 // subTurn == 2: only allowed to push an opponent's pawn (if possible)
87 const oppPawnShift
= (this.turn
== 'w' ? 1 : -1);
89 this.onBoard(x
+ oppPawnShift
, y
) &&
90 this.board
[x
+ oppPawnShift
][y
] == ""
92 return [this.getBasicMove([x
, y
], [x
+ oppPawnShift
, y
])];
98 if (this.subTurn
!= 1)
99 return moves
; //self-checks by pawns are allowed
100 return super.filterValid(moves
);
103 atLeastOnePawnPush(color
) {
104 const pawnShift
= (color
== 'w' ? -1 : 1);
105 for (let i
= 0; i
< 8; i
++) {
106 for (let j
= 0; j
< 8; j
++) {
108 this.board
[i
][j
] != "" &&
109 this.getColor(i
, j
) == color
&&
110 this.getPiece(i
, j
) == 'p' &&
111 this.board
[i
+ pawnShift
][j
] == ""
121 const color
= this.turn
;
122 const oppCol
= C
.GetOppCol(color
);
125 move.end
.x
== (oppCol
== 'w' ? 0 : this.size
.x
- 1) &&
126 move.vanish
[0].p
== 'p'
128 if (this.subTurn
== 0) {
130 if (!this.atLeastOneMove(color
)) {
131 move.result
= "1/2"; //avoid re-computation
135 else if (this.subTurn
== 2) {
137 this.subTurn
= this.promotion
? 0 : 1;
139 else { //subTurn == 1, usual case
140 const kingCapture
= this.searchKingPos(oppCol
).length
== 0;
142 move.result
= (color
== 'w' ? "1-0" : "0-1");
143 if (!kingCapture
&& this.atLeastOnePawnPush(oppCol
))
147 this.subTurn
= this.promotion
? 0 : 1;
152 atLeastOneMove(color
, lastMove
) {
153 if (this.subTurn
== 0)
155 return super.atLeastOneMove(color
);