projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix a detail in Loser's flags
[vchess.git]
/
public
/
javascripts
/
base_rules.js
diff --git
a/public/javascripts/base_rules.js
b/public/javascripts/base_rules.js
index
07ff715
..
172f68b
100644
(file)
--- a/
public/javascripts/base_rules.js
+++ b/
public/javascripts/base_rules.js
@@
-821,7
+821,9
@@
class ChessRules
this.shouldReturn = false;
const maxeval = VariantRules.INFINITY;
const color = this.turn;
this.shouldReturn = false;
const maxeval = VariantRules.INFINITY;
const color = this.turn;
- let moves1 = this.getAllValidMoves();
+ // Some variants may show a bigger moves list to the human (Switching),
+ // thus the argument "computer" below (which is generally ignored)
+ let moves1 = this.getAllValidMoves("computer");
// Can I mate in 1 ? (for Magnetic & Extinction)
for (let i of _.shuffle(_.range(moves1.length)))
// Can I mate in 1 ? (for Magnetic & Extinction)
for (let i of _.shuffle(_.range(moves1.length)))
@@
-843,7
+845,7
@@
class ChessRules
{
eval2 = (color=="w" ? 1 : -1) * maxeval; //initialized with checkmate value
// Second half-move:
{
eval2 = (color=="w" ? 1 : -1) * maxeval; //initialized with checkmate value
// Second half-move:
- let moves2 = this.getAllValidMoves();
+ let moves2 = this.getAllValidMoves(
"computer"
);
for (let j=0; j<moves2.length; j++)
{
this.play(moves2[j]);
for (let j=0; j<moves2.length; j++)
{
this.play(moves2[j]);
@@
-921,7
+923,7
@@
class ChessRules
}
if (depth == 0)
return this.evalPosition();
}
if (depth == 0)
return this.evalPosition();
- const moves = this.getAllValidMoves();
+ const moves = this.getAllValidMoves(
"computer"
);
let v = color=="w" ? -maxeval : maxeval;
if (color == "w")
{
let v = color=="w" ? -maxeval : maxeval;
if (color == "w")
{
@@
-1074,7
+1076,7
@@
class ChessRules
for (let i of ['w','b'])
{
for (let j=0; j<2; j++)
for (let i of ['w','b'])
{
for (let j=0; j<2; j++)
- fen +=
this.castleFlags[i][j] ? '1' : '0'
;
+ fen +=
(this.castleFlags[i][j] ? '1' : '0')
;
}
return fen;
}
}
return fen;
}
@@
-1082,14
+1084,8
@@
class ChessRules
// Context: just before move is played, turn hasn't changed
getNotation(move)
{
// Context: just before move is played, turn hasn't changed
getNotation(move)
{
- if (move.appear.length == 2 && move.appear[0].p == VariantRules.KING)
- {
- // Castle
- if (move.end.y < move.start.y)
- return "0-0-0";
- else
- return "0-0";
- }
+ if (move.appear.length == 2 && move.appear[0].p == VariantRules.KING) //castle
+ return (move.end.y < move.start.y ? "0-0-0" : "0-0");
// Translate final square
const finalSquare =
// Translate final square
const finalSquare =
@@
-1134,15
+1130,17
@@
class ChessRules
// The score is already computed when calling this function
getPGN(mycolor, score, fenStart, mode)
{
// The score is already computed when calling this function
getPGN(mycolor, score, fenStart, mode)
{
+ const zeroPad = x => { return (x<10 ? "0" : "") + x; };
let pgn = "";
pgn += '[Site "vchess.club"]<br>';
const d = new Date();
const opponent = mode=="human" ? "Anonymous" : "Computer";
pgn += '[Variant "' + variant + '"]<br>';
let pgn = "";
pgn += '[Site "vchess.club"]<br>';
const d = new Date();
const opponent = mode=="human" ? "Anonymous" : "Computer";
pgn += '[Variant "' + variant + '"]<br>';
- pgn += '[Date "' + d.getFullYear() + '-' + (d.getMonth()+1) + '-' +
d.getDate(
) + '"]<br>';
+ pgn += '[Date "' + d.getFullYear() + '-' + (d.getMonth()+1) + '-' +
zeroPad(d.getDate()
) + '"]<br>';
pgn += '[White "' + (mycolor=='w'?'Myself':opponent) + '"]<br>';
pgn += '[Black "' + (mycolor=='b'?'Myself':opponent) + '"]<br>';
pgn += '[White "' + (mycolor=='w'?'Myself':opponent) + '"]<br>';
pgn += '[Black "' + (mycolor=='b'?'Myself':opponent) + '"]<br>';
- pgn += '[Fen "' + fenStart + '"]<br>';
+ pgn += '[FenStart "' + fenStart + '"]<br>';
+ pgn += '[Fen "' + this.getFen() + '"]<br>';
pgn += '[Result "' + score + '"]<br><br>';
// Standard PGN
pgn += '[Result "' + score + '"]<br><br>';
// Standard PGN
@@
-1152,7
+1150,7
@@
class ChessRules
pgn += ((i/2)+1) + ".";
pgn += this.moves[i].notation[0] + " ";
}
pgn += ((i/2)+1) + ".";
pgn += this.moves[i].notation[0] + " ";
}
- pgn +=
score +
"<br><br>";
+ pgn += "<br><br>";
// "Complete moves" PGN (helping in ambiguous cases)
for (let i=0; i<this.moves.length; i++)
// "Complete moves" PGN (helping in ambiguous cases)
for (let i=0; i<this.moves.length; i++)
@@
-1161,7
+1159,6
@@
class ChessRules
pgn += ((i/2)+1) + ".";
pgn += this.moves[i].notation[1] + " ";
}
pgn += ((i/2)+1) + ".";
pgn += this.moves[i].notation[1] + " ";
}
- pgn += score;
return pgn;
}
return pgn;
}