projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Finished problems implementation. TODO: specify state for Crazyhouse,Grand. Improve...
[vchess.git]
/
public
/
javascripts
/
variants
/
Checkered.js
diff --git
a/public/javascripts/variants/Checkered.js
b/public/javascripts/variants/Checkered.js
index
2d62d4b
..
370c689
100644
(file)
--- a/
public/javascripts/variants/Checkered.js
+++ b/
public/javascripts/variants/Checkered.js
@@
-19,27
+19,45
@@
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);
}
- setFlags(fen)
+ 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(fenflags)
{
{
- super.setFlags(fen); //castleFlags
+ super.setFlags(fen
flags
); //castleFlags
this.pawnFlags =
{
this.pawnFlags =
{
- "w":
new Array(8
), //pawns can move 2 squares?
- "b":
new Array(8
)
+ "w":
_.map(_.range(8), i => true
), //pawns can move 2 squares?
+ "b":
_.map(_.range(8), i => true
)
};
};
- const flags = fen.split(" ")[1].substr(4); //skip first 4 digits, for castle
+ if (!fenflags)
+ return;
+ const flags = fenflags.substr(4); //skip first 4 digits, for castle
for (let c of ['w','b'])
{
for (let i=0; i<8; i++)
for (let c of ['w','b'])
{
for (let i=0; i<8; i++)
@@
-108,9
+126,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)
@@
-194,11
+210,12
@@
class CheckeredRules extends ChessRules
checkGameEnd()
{
const color = this.turn;
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;
}
return res;
}
@@
-223,7
+240,9
@@
class CheckeredRules extends ChessRules
static GenRandInitFen()
{
static GenRandInitFen()
{
- return ChessRules.GenRandInitFen() + "1111111111111111"; //add 16 pawns flags
+ const randFen = ChessRules.GenRandInitFen();
+ // Add 16 pawns flags:
+ return randFen.replace(" 1111 w", " 11111111111111111111 w");
}
getFlagsFen()
}
getFlagsFen()