projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Draft code reorganisation (+ fix Alice rules + stateless VariantRules object)
[vchess.git]
/
public
/
javascripts
/
variants
/
Crazyhouse.js
diff --git
a/public/javascripts/variants/Crazyhouse.js
b/public/javascripts/variants/Crazyhouse.js
index
afebcc3
..
3d9c743
100644
(file)
--- a/
public/javascripts/variants/Crazyhouse.js
+++ b/
public/javascripts/variants/Crazyhouse.js
@@
-11,10
+11,9
@@
class CrazyhouseRules extends ChessRules
// 6) Check promoted array
if (!fenParsed.promoted)
return false;
// 6) Check promoted array
if (!fenParsed.promoted)
return false;
- fenpromoted = fenParsed.promoted;
- if (fenpromoted == "-")
+ if (fenParsed.promoted == "-")
return true; //no promoted piece on board
return true; //no promoted piece on board
- const squares = fenpromoted.split(",");
+ const squares = fen
Parsed.
promoted.split(",");
for (let square of squares)
{
const c = V.SquareToCoords(square);
for (let square of squares)
{
const c = V.SquareToCoords(square);
@@
-24,10
+23,21
@@
class CrazyhouseRules extends ChessRules
return true;
}
return true;
}
+ static ParseFen(fen)
+ {
+ const fenParts = fen.split(" ");
+ return Object.assign(
+ ChessRules.ParseFen(fen),
+ {
+ reserve: fenParts[5],
+ promoted: fenParts[6],
+ }
+ );
+ }
+
static GenRandInitFen()
{
static GenRandInitFen()
{
- const fen = ChessRules.GenRandInitFen();
- return fen.replace(" w 1111", " w 1111 0000000000 -");
+ return ChessRules.GenRandInitFen() + " 0000000000 -";
}
getFen()
}
getFen()
@@
-37,8
+47,8
@@
class CrazyhouseRules extends ChessRules
getReserveFen()
{
getReserveFen()
{
- let counts =
_.map(_.range(10),
0);
- for (let i=0; i<V.PIECES.length
; i++)
+ let counts =
new Array(1
0);
+ for (let i=0; i<V.PIECES.length
-1; i++) //-1: no king reserve
{
counts[i] = this.reserve["w"][V.PIECES[i]];
counts[5+i] = this.reserve["b"][V.PIECES[i]];
{
counts[i] = this.reserve["w"][V.PIECES[i]];
counts[5+i] = this.reserve["b"][V.PIECES[i]];
@@
-59,6
+69,8
@@
class CrazyhouseRules extends ChessRules
}
if (res.length > 0)
res = res.slice(0,-1); //remove last comma
}
if (res.length > 0)
res = res.slice(0,-1); //remove last comma
+ else
+ res = "-";
return res;
}
return res;
}
@@
-87,10
+99,13
@@
class CrazyhouseRules extends ChessRules
}
};
this.promoted = doubleArray(V.size.x, V.size.y, false);
}
};
this.promoted = doubleArray(V.size.x, V.size.y, false);
-
for (let square of fenParsd.promoted.split(",")
)
+
if (fenParsed.promoted != "-"
)
{
{
- const [x,y] = V.SquareToCoords(square);
- promoted[x][y] = true;
+ for (let square of fenParsed.promoted.split(","))
+ {
+ const [x,y] = V.SquareToCoords(square);
+ promoted[x][y] = true;
+ }
}
}
}
}
@@
-197,7
+212,7
@@
class CrazyhouseRules extends ChessRules
super.updateVariables(move);
if (move.vanish.length == 2 && move.appear.length == 2)
return; //skip castle
super.updateVariables(move);
if (move.vanish.length == 2 && move.appear.length == 2)
return; //skip castle
- const color =
this.turn
;
+ const color =
move.appear[0].c
;
if (move.vanish.length == 0)
{
this.reserve[color][move.appear[0].p]--;
if (move.vanish.length == 0)
{
this.reserve[color][move.appear[0].p]--;