a1d4d541a49cf5fc761c08cbc3cb6ecd864fc380
1 import ChessRules
from "/base_rules.js";
2 import PiPo
from "/utils/PiPo.js";
3 import Move
from "/utils/Move.js";
5 export default class AvalancheRules
extends ChessRules
{
9 select: C
.Options
.select
,
32 {promotion: o
.init
? false : this.promotion
},
37 setOtherVariables(fenParsed
) {
38 super.setOtherVariables(fenParsed
);
39 this.promotion
= (fenParsed
.promotion
== '1');
40 this.subTurn
= 1 - (this.promotion
? 1 : 0);
44 const myLastRank
= (this.turn
== 'w' ? 0 : this.size
.x
- 1);
47 coords
.x
!= myLastRank
||
48 this.getPiece(coords
.x
, coords
.y
) != 'p'
53 this.pawnPromotions
.forEach(pr
=> {
56 vanish: [new PiPo({x: coords
.x
, y: coords
.y
, c: this.turn
, p: 'p'})],
57 appear: [new PiPo({x: coords
.x
, y: coords
.y
, c: this.turn
, p: pr
})]
61 super.showChoices(moves
);
65 const pieceColor
= this.getColor(x
, y
);
67 this.playerColor
== this.turn
&&
69 (this.subTurn
<= 1 && pieceColor
== this.playerColor
) ||
72 pieceColor
!= this.playerColor
&&
73 this.getPiece(x
, y
) == 'p'
79 getPotentialMovesFrom([x
, y
]) {
80 if (this.subTurn
== 0)
82 if (this.subTurn
== 1)
84 return super.getPotentialMovesFrom([x
, y
]);
85 // subTurn == 2: only allowed to push an opponent's pawn (if possible)
86 const oppPawnShift
= (this.turn
== 'w' ? 1 : -1);
88 this.onBoard(x
+ oppPawnShift
, y
) &&
89 this.board
[x
+ oppPawnShift
][y
] == ""
91 return [this.getBasicMove([x
, y
], [x
+ oppPawnShift
, y
])];
97 if (this.subTurn
!= 1)
98 return moves
; //self-checks by pawns are allowed
99 return super.filterValid(moves
);
102 atLeastOnePawnPush(color
) {
103 const pawnShift
= (color
== 'w' ? -1 : 1);
104 for (let i
= 0; i
< 8; i
++) {
105 for (let j
= 0; j
< 8; j
++) {
107 this.board
[i
][j
] != "" &&
108 this.getColor(i
, j
) == color
&&
109 this.getPiece(i
, j
) == 'p' &&
110 this.board
[i
+ pawnShift
][j
] == ""
120 const color
= this.turn
;
121 const oppCol
= C
.GetOppCol(color
);
124 move.end
.x
== (oppCol
== 'w' ? 0 : this.size
.x
- 1) &&
125 move.vanish
[0].p
== 'p'
127 if (this.subTurn
== 0) {
129 if (!this.atLeastOneMove(color
)) {
130 move.result
= "1/2"; //avoid re-computation
134 else if (this.subTurn
== 2) {
136 this.subTurn
= this.promotion
? 0 : 1;
138 else { //subTurn == 1, usual case
139 const kingCapture
= this.searchKingPos(oppCol
).length
== 0;
141 move.result
= (color
== 'w' ? "1-0" : "0-1");
142 if (!kingCapture
&& this.atLeastOnePawnPush(oppCol
))
146 this.subTurn
= this.promotion
? 0 : 1;
151 atLeastOneMove(color
, lastMove
) {
152 if (this.subTurn
== 0)
154 return super.atLeastOneMove(color
);