return board;
}
- // Overridable: flags can change a lot
+ // Extract (relevant) flags from fen
setFlags(fen)
{
// white a-castle, h-castle, black a-castle, h-castle
///////////////////
// GETTERS, SETTERS
- // Simple useful getters
static get size() { return [8,8]; }
// Two next functions return 'undefined' if called on empty square
getColor(i,j) { return this.board[i][j].charAt(0); }
return undefined; //default
}
- // can thing on square1 take thing on square2
+ // Can thing on square1 take thing on square2
canTake([x1,y1], [x2,y2])
{
return this.getColor(x1,y1) != this.getColor(x2,y2);
return moves;
}
- // What are the pawn moves from square x,y considering color "color" ?
+ // What are the pawn moves from square x,y ?
getPotentialPawnMoves([x,y])
{
const color = this.turn;
return false;
}
- // Check if pieces of color 'colors' are attacking square x,y
+ // Check if pieces of color in array 'colors' are attacking square x,y
isAttacked(sq, colors)
{
return (this.isAttackedByPawn(sq, colors)
|| this.isAttackedByKing(sq, colors));
}
- // Is square x,y attacked by pawns of color c ?
+ // Is square x,y attacked by 'colors' pawns ?
isAttackedByPawn([x,y], colors)
{
const [sizeX,sizeY] = VariantRules.size;
return false;
}
- // Is square x,y attacked by rooks of color c ?
+ // Is square x,y attacked by 'colors' rooks ?
isAttackedByRook(sq, colors)
{
return this.isAttackedBySlideNJump(sq, colors,
VariantRules.ROOK, VariantRules.steps[VariantRules.ROOK]);
}
- // Is square x,y attacked by knights of color c ?
+ // Is square x,y attacked by 'colors' knights ?
isAttackedByKnight(sq, colors)
{
return this.isAttackedBySlideNJump(sq, colors,
VariantRules.KNIGHT, VariantRules.steps[VariantRules.KNIGHT], "oneStep");
}
- // Is square x,y attacked by bishops of color c ?
+ // Is square x,y attacked by 'colors' bishops ?
isAttackedByBishop(sq, colors)
{
return this.isAttackedBySlideNJump(sq, colors,
VariantRules.BISHOP, VariantRules.steps[VariantRules.BISHOP]);
}
- // Is square x,y attacked by queens of color c ?
+ // Is square x,y attacked by 'colors' queens ?
isAttackedByQueen(sq, colors)
{
const V = VariantRules;
V.steps[V.ROOK].concat(V.steps[V.BISHOP]));
}
- // Is square x,y attacked by king of color c ?
+ // Is square x,y attacked by 'colors' king(s) ?
isAttackedByKing(sq, colors)
{
const V = VariantRules;
}
// Generic method for non-pawn pieces ("sliding or jumping"):
- // is x,y attacked by piece !of color in colors?
+ // is x,y attacked by a piece of color in array 'colors' ?
isAttackedBySlideNJump([x,y], colors, piece, steps, oneStep)
{
const [sizeX,sizeY] = VariantRules.size;
return false;
}
- // Is color c under check after move ?
+ // Is current player under check after his move ?
underCheck(move)
{
const color = this.turn;
return res;
}
- // On which squares is color c under check (after move) ?
+ // On which squares is opponent under check after our move ?
getCheckSquares(move)
{
this.play(move);
}
}
+ // After move is undo-ed, un-update variables (flags are reset)
+ // TODO: more symmetry, by storing flags increment in move...
unupdateVariables(move)
{
// (Potentially) Reset king position
play(move, ingame)
{
- // DEBUG:
-// if (!this.states) this.states = [];
-// if (!ingame) this.states.push(JSON.stringify(this.board));
-// if (!this.rstates) this.rstates = [];
-// if (!ingame) this.rstates.push(JSON.stringify(this.promoted)+"-"+JSON.stringify(this.reserve));
-
if (!!ingame)
move.notation = [this.getNotation(move), this.getLongNotation(move)];
this.moves.pop();
this.unupdateVariables(move);
this.parseFlags(JSON.parse(move.flags));
-
- // DEBUG:
-// let state = this.states.pop();
-// let rstate = this.rstates.pop();
-// if (JSON.stringify(this.board) != state || JSON.stringify(this.promoted)+"-"+JSON.stringify(this.reserve) != rstate)
-// debugger;
}
//////////////
// END OF GAME
+ // Basic check for 3 repetitions (in the last moves only)
checkRepetition()
{
- // Check for 3 repetitions
if (this.moves.length >= 8)
{
- // NOTE: crude detection, only moves repetition
const L = this.moves.length;
if (_.isEqual(this.moves[L-1], this.moves[L-5]) &&
_.isEqual(this.moves[L-2], this.moves[L-6]) &&
return false;
}
+ // Is game over ? And if yes, what is the score ?
checkGameOver()
{
if (this.checkRepetition())
return moves1[_.sample(candidates, 1)];
}
+ // TODO: some optimisations, understand why CH get mated in 2
alphabeta(depth, alpha, beta)
{
const maxeval = VariantRules.INFINITY;
////////////
// FEN utils
- // Overridable..
+ // Setup the initial random (assymetric) position
static GenRandInitFen()
{
let pieces = [new Array(8), new Array(8)];
return this.getBaseFen() + " " + this.getFlagsFen();
}
+ // Position part of the FEN string
getBaseFen()
{
let fen = "";
return fen;
}
- // Overridable..
+ // Flags part of the FEN string
getFlagsFen()
{
let fen = "";