projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Almost finished problems logic. TODO: showProblem() part
[vchess.git]
/
public
/
javascripts
/
variants
/
Checkered.js
diff --git
a/public/javascripts/variants/Checkered.js
b/public/javascripts/variants/Checkered.js
index
b702018
..
585d20f
100644
(file)
--- a/
public/javascripts/variants/Checkered.js
+++ b/
public/javascripts/variants/Checkered.js
@@
-19,18
+19,34
@@
class CheckeredRules extends ChessRules
}
static fen2board(f)
{
}
static fen2board(f)
{
+ // Tolerate upper-case versions of checkered pieces (why not?)
const checkered_pieces = {
's': 'p',
const checkered_pieces = {
's': 'p',
+ 'S': 'p',
't': 'q',
't': 'q',
+ 'T': 'q',
'u': 'r',
'u': 'r',
+ 'U': 'r',
'c': 'b',
'c': 'b',
+ 'C': 'b',
'o': 'n',
'o': 'n',
+ 'O': 'n',
};
if (Object.keys(checkered_pieces).includes(f))
return 'c'+checkered_pieces[f];
return ChessRules.fen2board(f);
}
};
if (Object.keys(checkered_pieces).includes(f))
return 'c'+checkered_pieces[f];
return ChessRules.fen2board(f);
}
+ static get PIECES() {
+ return ChessRules.PIECES.concat(['s','t','u','c','o']);
+ }
+
+ static IsGoodFlags(flags)
+ {
+ // 4 for castle + 16 for pawns
+ return !!flags.match(/^[01]{20,20}$/);
+ }
+
setFlags(fen)
{
super.setFlags(fen); //castleFlags
setFlags(fen)
{
super.setFlags(fen); //castleFlags
@@
-72,14
+88,19
@@
class CheckeredRules extends ChessRules
{
let standardMoves = super.getPotentialMovesFrom([x,y]);
const lastRank = this.turn == "w" ? 0 : 7;
{
let standardMoves = super.getPotentialMovesFrom([x,y]);
const lastRank = this.turn == "w" ? 0 : 7;
- if (this.getPiece(x,y) == V
ariantRules
.KING)
+ if (this.getPiece(x,y) == V.KING)
return standardMoves; //king has to be treated differently (for castles)
let moves = [];
standardMoves.forEach(m => {
return standardMoves; //king has to be treated differently (for castles)
let moves = [];
standardMoves.forEach(m => {
- if (m.vanish[0].p == VariantRules.PAWN && Math.abs(m.end.x-m.start.x)==2
- && !this.pawnFlags[this.turn][m.start.y])
+ if (m.vanish[0].p == V.PAWN)
{
{
- return; //skip forbidden 2-squares jumps
+ if (Math.abs(m.end.x-m.start.x)==2 && !this.pawnFlags[this.turn][m.start.y])
+ return; //skip forbidden 2-squares jumps
+ if (this.board[m.end.x][m.end.y] == V.EMPTY && m.vanish.length==2
+ && this.getColor(m.start.x,m.start.y) == 'c')
+ {
+ return; //checkered pawns cannot take en-passant
+ }
}
if (m.vanish.length == 1)
moves.push(m); //no capture
}
if (m.vanish.length == 1)
moves.push(m); //no capture
@@
-89,7
+110,7
@@
class CheckeredRules extends ChessRules
m.appear[0].c = "c";
moves.push(m);
if (m.appear[0].p != m.vanish[1].p //avoid promotions (already treated):
m.appear[0].c = "c";
moves.push(m);
if (m.appear[0].p != m.vanish[1].p //avoid promotions (already treated):
- && (m.vanish[0].p != V
ariantRules
.PAWN || m.end.x != lastRank))
+ && (m.vanish[0].p != V.PAWN || m.end.x != lastRank))
{
// Add transformation into captured piece
let m2 = JSON.parse(JSON.stringify(m));
{
// Add transformation into captured piece
let m2 = JSON.parse(JSON.stringify(m));
@@
-103,8
+124,7
@@
class CheckeredRules extends ChessRules
canIplay(side, [x,y])
{
canIplay(side, [x,y])
{
- return ((side=='w' && this.moves.length%2==0) || (side=='b' && this.moves.length%2==1))
- && [side,'c'].includes(this.getColor(x,y));
+ return (side == this.turn && [side,'c'].includes(this.getColor(x,y)));
}
// Does m2 un-do m1 ? (to disallow undoing checkered moves)
}
// Does m2 un-do m1 ? (to disallow undoing checkered moves)
@@
-141,7
+161,7
@@
class CheckeredRules extends ChessRules
{
for (let i of [-1,1])
{
{
for (let i of [-1,1])
{
- if (y+i>=0 && y+i<8 && this.getPiece(x+pawnShift,y+i)==V
ariantRules
.PAWN
+ if (y+i>=0 && y+i<8 && this.getPiece(x+pawnShift,y+i)==V.PAWN
&& this.getColor(x+pawnShift,y+i)==c)
{
return true;
&& this.getColor(x+pawnShift,y+i)==c)
{
return true;
@@
-166,7
+186,8
@@
class CheckeredRules extends ChessRules
this.play(move);
const color = this.turn;
this.moves.push(move); //artifically change turn, for checkered pawns (TODO)
this.play(move);
const color = this.turn;
this.moves.push(move); //artifically change turn, for checkered pawns (TODO)
- const kingAttacked = this.isAttacked(this.kingPos[color], [this.getOppCol(color),'c']);
+ const kingAttacked = this.isAttacked(
+ this.kingPos[color], [this.getOppCol(color),'c']);
let res = kingAttacked
? [ JSON.parse(JSON.stringify(this.kingPos[color])) ] //need to duplicate!
: [ ];
let res = kingAttacked
? [ JSON.parse(JSON.stringify(this.kingPos[color])) ] //need to duplicate!
: [ ];
@@
-177,41
+198,38
@@
class CheckeredRules extends ChessRules
updateVariables(move)
{
updateVariables(move)
{
- const c = this.getColor(move.start.x,move.start.y);
- if (c != 'c') //checkered not concerned by castle flags
- super.updateVariables(move);
-
- // Does it turn off a 2-squares pawn flag?
+ super.updateVariables(move);
+ // Does this move turn off a 2-squares pawn flag?
const secondRank = [1,6];
const secondRank = [1,6];
- if (secondRank.includes(move.start.x) && move.vanish[0].p == V
ariantRules
.PAWN)
+ if (secondRank.includes(move.start.x) && move.vanish[0].p == V.PAWN)
this.pawnFlags[move.start.x==6 ? "w" : "b"][move.start.y] = false;
}
checkGameEnd()
{
const color = this.turn;
this.pawnFlags[move.start.x==6 ? "w" : "b"][move.start.y] = false;
}
checkGameEnd()
{
const color = this.turn;
- this.moves.length++; //artifically change turn, for checkered pawns (TODO)
+ // Artifically change turn, for checkered pawns
+ this.turn = this.getOppCol(this.turn);
const res = this.isAttacked(this.kingPos[color], [this.getOppCol(color),'c'])
? (color == "w" ? "0-1" : "1-0")
: "1/2";
const res = this.isAttacked(this.kingPos[color], [this.getOppCol(color),'c'])
? (color == "w" ? "0-1" : "1-0")
: "1/2";
- this.
moves.length--
;
+ this.
turn = this.getOppCol(this.turn)
;
return res;
}
evalPosition()
{
return res;
}
evalPosition()
{
- const [sizeX,sizeY] = VariantRules.size;
let evaluation = 0;
//Just count material for now, considering checkered neutral (...)
let evaluation = 0;
//Just count material for now, considering checkered neutral (...)
- for (let i=0; i<
sizeX
; i++)
+ for (let i=0; i<
V.size.x
; i++)
{
{
- for (let j=0; j<
sizeY
; j++)
+ for (let j=0; j<
V.size.y
; j++)
{
{
- if (this.board[i][j] != V
ariantRules
.EMPTY)
+ if (this.board[i][j] != V.EMPTY)
{
const sqColor = this.getColor(i,j);
const sign = sqColor == "w" ? 1 : (sqColor=="b" ? -1 : 0);
{
const sqColor = this.getColor(i,j);
const sign = sqColor == "w" ? 1 : (sqColor=="b" ? -1 : 0);
- evaluation += sign * V
ariantRules
.VALUES[this.getPiece(i,j)];
+ evaluation += sign * V.VALUES[this.getPiece(i,j)];
}
}
}
}
}
}
@@
-248,10
+266,10
@@
class CheckeredRules extends ChessRules
// Translate final square
let finalSquare =
// Translate final square
let finalSquare =
- String.fromCharCode(97 + move.end.y) + (V
ariantRules.size[0]
-move.end.x);
+ String.fromCharCode(97 + move.end.y) + (V
.size.x
-move.end.x);
let piece = this.getPiece(move.start.x, move.start.y);
let piece = this.getPiece(move.start.x, move.start.y);
- if (piece == V
ariantRules
.PAWN)
+ if (piece == V.PAWN)
{
// Pawn move
let notation = "";
{
// Pawn move
let notation = "";
@@
-259,12
+277,15
@@
class CheckeredRules extends ChessRules
{
// Capture
let startColumn = String.fromCharCode(97 + move.start.y);
{
// Capture
let startColumn = String.fromCharCode(97 + move.start.y);
- notation = startColumn + "x" + finalSquare + "=" + move.appear[0].p.toUpperCase();
+ notation = startColumn + "x" + finalSquare +
+ "=" + move.appear[0].p.toUpperCase();
}
else //no capture
}
else //no capture
+ {
notation = finalSquare;
notation = finalSquare;
- if (move.appear.length > 0 && piece != move.appear[0].p) //promotion
- notation += "=" + move.appear[0].p.toUpperCase();
+ if (move.appear.length > 0 && piece != move.appear[0].p) //promotion
+ notation += "=" + move.appear[0].p.toUpperCase();
+ }
return notation;
}
return notation;
}