1 class LoserRules
extends ChessRules
5 // No castling, hence no flags
6 const epSq
= this.moves
.length
> 0 ? this.getEpSquare(this.lastMove
) : undefined;
7 this.epSquares
= [ epSq
];
12 getPotentialPawnMoves([x
,y
])
14 let moves
= super.getPotentialPawnMoves([x
,y
]);
16 // Complete with promotion(s) into king, if possible
17 const color
= this.turn
;
18 const V
= VariantRules
;
19 const [sizeX
,sizeY
] = VariantRules
.size
;
20 const shift
= (color
== "w" ? -1 : 1);
21 const lastRank
= (color
== "w" ? 0 : sizeX
-1);
22 if (x
+shift
== lastRank
)
26 if (this.board
[x
+shift
][y
] == V
.EMPTY
)
27 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
], {c:color
,p:p
}));
29 if (y
>0 && this.canTake([x
,y
], [x
+shift
,y
-1]) && this.board
[x
+shift
][y
-1] != V
.EMPTY
)
30 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
-1], {c:color
,p:p
}));
31 if (y
<sizeY
-1 && this.canTake([x
,y
], [x
+shift
,y
+1]) && this.board
[x
+shift
][y
+1] != V
.EMPTY
)
32 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
+1], {c:color
,p:p
}));
38 getPotentialKingMoves(sq
)
40 const V
= VariantRules
;
41 return this.getSlideNJumpMoves(sq
,
42 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]), "oneStep");
45 // Stop at the first capture found (if any)
48 const color
= this.turn
;
49 const oppCol
= this.getOppCol(color
);
50 const [sizeX
,sizeY
] = VariantRules
.size
;
51 for (let i
=0; i
<sizeX
; i
++)
53 for (let j
=0; j
<sizeY
; j
++)
55 if (this.board
[i
][j
] != VariantRules
.EMPTY
&& this.getColor(i
,j
) != oppCol
)
57 const moves
= this.getPotentialMovesFrom([i
,j
]);
60 for (let k
=0; k
<moves
.length
; k
++)
62 if (moves
[k
].vanish
.length
==2 && this.filterValid([moves
[k
]]).length
> 0)
72 // Trim all non-capturing moves
73 static KeepCaptures(moves
)
75 return moves
.filter(m
=> { return m
.vanish
.length
== 2; });
78 getPossibleMovesFrom(sq
)
80 let moves
= this.filterValid( this.getPotentialMovesFrom(sq
) );
81 // This is called from interface: we need to know if a capture is possible
82 if (this.atLeastOneCapture())
83 moves
= VariantRules
.KeepCaptures(moves
);
89 let moves
= super.getAllValidMoves();
90 if (moves
.some(m
=> { return m
.vanish
.length
== 2; }))
91 moves
= VariantRules
.KeepCaptures(moves
);
97 return false; //No notion of check
100 getCheckSquares(move)
108 move.notation
= this.getNotation(move);
109 this.moves
.push(move);
110 this.epSquares
.push( this.getEpSquare(move) );
111 VariantRules
.PlayOnBoard(this.board
, move);
116 VariantRules
.UndoOnBoard(this.board
, move);
117 this.epSquares
.pop();
123 // No valid move: you win!
124 return this.turn
== "w" ? "1-0" : "0-1";
127 static get VALUES() { //experimental...
138 static get SEARCH_DEPTH() { return 4; }
142 return - super.evalPosition(); //better with less material