+// (Orthodox) Chess rules are defined in ChessRules class.
+// Variants generally inherit from it, and modify some parts.
+
class PiPo //Piece+Position
{
// o: {piece[p], color[c], posX[x], posY[y]}
{
this.INIT_COL_KING = {'w':-1, 'b':-1};
this.INIT_COL_ROOK = {'w':[-1,-1], 'b':[-1,-1]};
- this.kingPos = {'w':[-1,-1], 'b':[-1,-1]}; //respective squares of white and black king
+ this.kingPos = {'w':[-1,-1], 'b':[-1,-1]}; //squares of white and black king
const fenParts = fen.split(" ");
const position = fenParts[0].split("/");
for (let i=0; i<position.length; i++)
// What are the knight moves from square x,y ?
getPotentialKnightMoves(sq)
{
- return this.getSlideNJumpMoves(sq, VariantRules.steps[VariantRules.KNIGHT], "oneStep");
+ return this.getSlideNJumpMoves(
+ sq, VariantRules.steps[VariantRules.KNIGHT], "oneStep");
}
// What are the bishop moves from square x,y ?
canIplay(side, [x,y])
{
- return ((side=='w' && this.moves.length%2==0) || (side=='b' && this.moves.length%2==1))
+ return ((side=='w' && this.moves.length%2==0)
+ || (side=='b' && this.moves.length%2==1))
&& this.getColor(x,y) == side;
}
return this.filterValid( this.getPotentialMovesFrom(sq) );
}
- // TODO: once a promotion is filtered, the others results are same: useless computations
+ // TODO: promotions (into R,B,N,Q) should be filtered only once
filterValid(moves)
{
if (moves.length == 0)
{
for (let j=0; j<sizeY; j++)
{
- // Next condition ... != oppCol is a little HACK to work with checkered variant
+ // Next condition "!= oppCol" = harmless hack to work with checkered variant
if (this.board[i][j] != VariantRules.EMPTY && this.getColor(i,j) != oppCol)
Array.prototype.push.apply(potentialMoves, this.getPotentialMovesFrom([i,j]));
}
const score = this.checkGameEnd();
eval2 = (score=="1/2" ? 0 : (score=="1-0" ? 1 : -1) * maxeval);
}
- if ((color=="w" && eval2 > moves1[i].eval) || (color=="b" && eval2 < moves1[i].eval))
+ if ((color=="w" && eval2 > moves1[i].eval)
+ || (color=="b" && eval2 < moves1[i].eval))
+ {
moves1[i].eval = eval2;
+ }
this.undo(moves1[i]);
}
moves1.sort( (a,b) => { return (color=="w" ? 1 : -1) * (b.eval - a.eval); });
const d = new Date();
const opponent = mode=="human" ? "Anonymous" : "Computer";
pgn += '[Variant "' + variant + '"]<br>';
- pgn += '[Date "' + d.getFullYear() + '-' + (d.getMonth()+1) + '-' + zeroPad(d.getDate()) + '"]<br>';
+ pgn += '[Date "' + d.getFullYear() + '-' + (d.getMonth()+1) +
+ '-' + zeroPad(d.getDate()) + '"]<br>';
pgn += '[White "' + (mycolor=='w'?'Myself':opponent) + '"]<br>';
pgn += '[Black "' + (mycolor=='b'?'Myself':opponent) + '"]<br>';
pgn += '[FenStart "' + fenStart + '"]<br>';