'r': [ [-1,0],[1,0],[0,-1],[0,1] ],
'n': [ [-1,-2],[-1,2],[1,-2],[1,2],[-2,-1],[-2,1],[2,-1],[2,1] ],
'b': [ [-1,-1],[-1,1],[1,-1],[1,1] ],
'r': [ [-1,0],[1,0],[0,-1],[0,1] ],
'n': [ [-1,-2],[-1,2],[1,-2],[1,2],[-2,-1],[-2,1],[2,-1],[2,1] ],
'b': [ [-1,-1],[-1,1],[1,-1],[1,1] ],
- 'q': [ [-1,0],[1,0],[0,-1],[0,1],[-1,-1],[-1,1],[1,-1],[1,1] ]
- if (i>=0 && i<8 && j>=0 && j<8 && this.canTake([x,y], [i,j]))
+ if (i>=0 && i<sizeX && j>=0 && j<sizeY && this.canTake([x,y], [i,j]))
moves.push(this.getBasicMove([x,y], [i,j]));
}
return moves;
moves.push(this.getBasicMove([x,y], [i,j]));
}
return moves;
const V = VariantRules;
const [sizeX,sizeY] = VariantRules.size;
const shift = (color == "w" ? -1 : 1);
const V = VariantRules;
const [sizeX,sizeY] = VariantRules.size;
const shift = (color == "w" ? -1 : 1);
- const firstRank = (color == 'w' ? sizeY-1 : 0);
- const startRank = (color == "w" ? sizeY-2 : 1);
- const lastRank = (color == "w" ? 0 : sizeY-1);
+ const firstRank = (color == 'w' ? sizeX-1 : 0);
+ const startRank = (color == "w" ? sizeX-2 : 1);
+ const lastRank = (color == "w" ? 0 : sizeX-1);
// What are the queen moves from square x,y ?
getPotentialQueenMoves(sq)
{
// What are the queen moves from square x,y ?
getPotentialQueenMoves(sq)
{
}
// What are the king moves from square x,y ?
getPotentialKingMoves(sq)
{
}
// What are the king moves from square x,y ?
getPotentialKingMoves(sq)
{
- let moves = this.getSlideNJumpMoves(sq, VariantRules.steps[VariantRules.QUEEN], "oneStep");
+ let moves = this.getSlideNJumpMoves(sq,
+ V.steps[V.ROOK].concat(V.steps[V.BISHOP]), "oneStep");
return moves.concat(this.getCastleMoves(sq));
}
getCastleMoves([x,y])
{
const c = this.getColor(x,y);
return moves.concat(this.getCastleMoves(sq));
}
getCastleMoves([x,y])
{
const c = this.getColor(x,y);
- const finalSquares = [ [2,3], [6,5] ]; //king, then rook
+ const finalSquares = [ [2,3], [sizeY-2,sizeY-3] ]; //king, then rook
let step = finalSquares[castleSide][0] < y ? -1 : 1;
for (i=y; i!=finalSquares[castleSide][0]; i+=step)
{
let step = finalSquares[castleSide][0] < y ? -1 : 1;
for (i=y; i!=finalSquares[castleSide][0]; i+=step)
{
// NOTE: next check is enough, because of chessboard constraints
(this.getColor(x,i) != c || ![V.KING,V.ROOK].includes(this.getPiece(x,i)))))
{
// NOTE: next check is enough, because of chessboard constraints
(this.getColor(x,i) != c || ![V.KING,V.ROOK].includes(this.getPiece(x,i)))))
{
- var potentialMoves = [];
- let [sizeX,sizeY] = VariantRules.size;
+ let potentialMoves = [];
+ const [sizeX,sizeY] = VariantRules.size;
// Is square x,y attacked by pawns of color c ?
isAttackedByPawn([x,y], colors)
{
// Is square x,y attacked by pawns of color c ?
isAttackedByPawn([x,y], colors)
{
// Is square x,y attacked by queens of color c ?
isAttackedByQueen(sq, colors)
{
// Is square x,y attacked by queens of color c ?
isAttackedByQueen(sq, colors)
{
- return this.isAttackedBySlideNJump(sq, colors,
- VariantRules.QUEEN, VariantRules.steps[VariantRules.QUEEN]);
+ const V = VariantRules;
+ return this.isAttackedBySlideNJump(sq, colors, V.QUEEN,
+ V.steps[V.ROOK].concat(V.steps[V.BISHOP]));
}
// Is square x,y attacked by king of color c ?
isAttackedByKing(sq, colors)
{
}
// Is square x,y attacked by king of color c ?
isAttackedByKing(sq, colors)
{
- return this.isAttackedBySlideNJump(sq, colors,
- VariantRules.KING, VariantRules.steps[VariantRules.QUEEN], "oneStep");
+ const V = VariantRules;
+ return this.isAttackedBySlideNJump(sq, colors, V.KING,
+ V.steps[V.ROOK].concat(V.steps[V.BISHOP]), "oneStep");
}
// Generic method for non-pawn pieces ("sliding or jumping"): is x,y attacked by piece != color ?
isAttackedBySlideNJump([x,y], colors, piece, steps, oneStep)
{
}
// Generic method for non-pawn pieces ("sliding or jumping"): is x,y attacked by piece != color ?
isAttackedBySlideNJump([x,y], colors, piece, steps, oneStep)
{
{
const piece = this.getPiece(move.start.x,move.start.y);
const c = this.getColor(move.start.x,move.start.y);
{
const piece = this.getPiece(move.start.x,move.start.y);
const c = this.getColor(move.start.x,move.start.y);
// Assumption: at least one legal move
getComputerMove(moves1) //moves1 might be precomputed (Magnetic chess)
{
// Assumption: at least one legal move
getComputerMove(moves1) //moves1 might be precomputed (Magnetic chess)
{
{
// TODO: show current analyzed move for depth 3, allow stopping eval (return moves1[0])
for (let i=0; i<moves1.length; i++)
{
{
// TODO: show current analyzed move for depth 3, allow stopping eval (return moves1[0])
for (let i=0; i<moves1.length; i++)
{
- moves1[i].eval = 0.1*moves1[i].eval + this.alphabeta(2, -maxeval, maxeval);
+ moves1[i].eval = 0.1*moves1[i].eval +
+ this.alphabeta(VariantRules.SEARCH_DEPTH-1, -maxeval, maxeval);
for (let j=1; j<moves1.length && moves1[j].eval == moves1[0].eval; j++)
candidates.push(j);
// console.log(moves1.map(m => { return [this.getNotation(m), m.eval]; }));
for (let j=1; j<moves1.length && moves1[j].eval == moves1[0].eval; j++)
candidates.push(j);
// console.log(moves1.map(m => { return [this.getNotation(m), m.eval]; }));