const position = fenParts[0].split("/");
for (let i=0; i<position.length; i++)
{
- let j = 0;
- while (j < position[i].length)
+ let k = 0; //column index on board
+ for (let j=0; j<position[i].length; j++)
{
switch (position[i].charAt(j))
{
case 'k':
- this.kingPos['b'] = [i,j];
- this.INIT_COL_KING['b'] = j;
+ this.kingPos['b'] = [i,k];
+ this.INIT_COL_KING['b'] = k;
break;
case 'K':
- this.kingPos['w'] = [i,j];
- this.INIT_COL_KING['w'] = j;
+ this.kingPos['w'] = [i,k];
+ this.INIT_COL_KING['w'] = k;
break;
case 'r':
if (this.INIT_COL_ROOK['b'][0] < 0)
- this.INIT_COL_ROOK['b'][0] = j;
+ this.INIT_COL_ROOK['b'][0] = k;
else
- this.INIT_COL_ROOK['b'][1] = j;
+ this.INIT_COL_ROOK['b'][1] = k;
break;
case 'R':
if (this.INIT_COL_ROOK['w'][0] < 0)
- this.INIT_COL_ROOK['w'][0] = j;
+ this.INIT_COL_ROOK['w'][0] = k;
else
- this.INIT_COL_ROOK['w'][1] = j;
+ this.INIT_COL_ROOK['w'][1] = k;
break;
default:
let num = parseInt(position[i].charAt(j));
if (!isNaN(num))
- j += (num-1);
+ k += (num-1);
}
- j++;
+ k++;
}
}
const epSq = this.moves.length > 0 ? this.getEpSquare(this.lastMove) : undefined;
getCheckSquares(move)
{
this.play(move);
- const color = this.turn;
+ const color = this.turn; //opponent
let res = this.isAttacked(this.kingPos[color], this.getOppCol(color))
? [ JSON.parse(JSON.stringify(this.kingPos[color])) ] //need to duplicate!
: [ ];
//////////////
// END OF GAME
- checkGameOver()
+ checkRepetition()
{
// Check for 3 repetitions
if (this.moves.length >= 8)
_.isEqual(this.moves[L-3], this.moves[L-7]) &&
_.isEqual(this.moves[L-4], this.moves[L-8]))
{
- return "1/2 (repetition)";
+ return true;
}
}
+ return false;
+ }
- if (this.atLeastOneMove())
- {
- // game not over
+ checkGameOver()
+ {
+ if (this.checkRepetition())
+ return "1/2";
+
+ if (this.atLeastOneMove()) // game not over
return "*";
- }
// Game over
return this.checkGameEnd();
let pgn = "";
pgn += '[Site "vchess.club"]<br>';
const d = new Date();
- const opponent = this.mode=="human" ? "Anonymous" : "Computer";
+ const opponent = mode=="human" ? "Anonymous" : "Computer";
pgn += '[Date "' + d.getFullYear() + '-' + (d.getMonth()+1) + '-' + d.getDate() + '"]<br>';
pgn += '[White "' + (mycolor=='w'?'Myself':opponent) + '"]<br>';
pgn += '[Black "' + (mycolor=='b'?'Myself':opponent) + '"]<br>';