projects
/
xogo.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Completed Checkered variant. Untested
[xogo.git]
/
base_rules.js
diff --git
a/base_rules.js
b/base_rules.js
index
162fad0
..
a0defd1
100644
(file)
--- a/
base_rules.js
+++ b/
base_rules.js
@@
-219,6
+219,7
@@
export default class ChessRules {
const s = FenUtil.setupPieces(
['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'],
{
const s = FenUtil.setupPieces(
['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'],
{
+ randomness: this.options["randomness"],
between: {p1: 'k', p2: 'r'},
diffCol: ['b'],
flags: ['r']
between: {p1: 'k', p2: 'r'},
diffCol: ['b'],
flags: ['r']
@@
-285,9
+286,9
@@
export default class ChessRules {
// Position part of the FEN string
getPosition() {
let position = "";
// Position part of the FEN string
getPosition() {
let position = "";
- for (let i = 0; i < this.size.
y
; i++) {
+ for (let i = 0; i < this.size.
x
; i++) {
let emptyCount = 0;
let emptyCount = 0;
- for (let j = 0; j < this.size.
x
; j++) {
+ for (let j = 0; j < this.size.
y
; j++) {
if (this.board[i][j] == "")
emptyCount++;
else {
if (this.board[i][j] == "")
emptyCount++;
else {
@@
-302,7
+303,7
@@
export default class ChessRules {
if (emptyCount > 0)
// "Flush remainder"
position += C.FenEmptySquares(emptyCount);
if (emptyCount > 0)
// "Flush remainder"
position += C.FenEmptySquares(emptyCount);
- if (i < this.size.
y
- 1)
+ if (i < this.size.
x
- 1)
position += "/"; //separate rows
}
return position;
position += "/"; //separate rows
}
return position;
@@
-556,7
+557,7
@@
export default class ChessRules {
chessboard.style.top = spaceTop + "px";
// Give sizes instead of recomputing them,
// because chessboard might not be drawn yet.
chessboard.style.top = spaceTop + "px";
// Give sizes instead of recomputing them,
// because chessboard might not be drawn yet.
- this.setupPieces({
+ this.setup
Visual
Pieces({
width: cbWidth,
height: cbHeight,
x: spaceLeft,
width: cbWidth,
height: cbHeight,
x: spaceLeft,
@@
-596,7
+597,7
@@
export default class ChessRules {
return board;
}
return board;
}
- setupPieces(r) {
+ setup
Visual
Pieces(r) {
let chessboard =
document.getElementById(this.containerId).querySelector(".chessboard");
if (!r)
let chessboard =
document.getElementById(this.containerId).querySelector(".chessboard");
if (!r)
@@
-1170,8
+1171,12
@@
export default class ChessRules {
////////////////////////
// PIECES SPECIFICATIONS
////////////////////////
// PIECES SPECIFICATIONS
+ getPawnShift(color) {
+ return (color == "w" ? -1 : 1);
+ }
+
pieces(color, x, y) {
pieces(color, x, y) {
- const pawnShift =
(color == "w" ? -1 : 1
);
+ const pawnShift =
this.getPawnShift(color
);
// NOTE: jump 2 squares from first rank (pawns can be here sometimes)
const initRank = ((color == 'w' && x >= 6) || (color == 'b' && x <= 1));
return {
// NOTE: jump 2 squares from first rank (pawns can be here sometimes)
const initRank = ((color == 'w' && x >= 6) || (color == 'b' && x <= 1));
return {
@@
-2101,8
+2106,10
@@
export default class ChessRules {
////////////////////
// MOVES VALIDATION
////////////////////
// MOVES VALIDATION
- // Is piece (or square) at given position attacked by "oppCol" ?
+ // Is piece (or square) at given position attacked by "oppCol
(s)
" ?
underAttack([x, y], oppCol) {
underAttack([x, y], oppCol) {
+ if (!Array.isArray(oppCol))
+ oppCol = [oppCol];
// An empty square is considered as king,
// since it's used only in getCastleMoves (TODO?)
const king = this.board[x][y] == "" || this.isKing(x, y);
// An empty square is considered as king,
// since it's used only in getCastleMoves (TODO?)
const king = this.board[x][y] == "" || this.isKing(x, y);
@@
-2112,7
+2119,7
@@
export default class ChessRules {
this.findCapturesOn(
[x, y],
{
this.findCapturesOn(
[x, y],
{
- byCol:
[oppCol]
,
+ byCol:
oppCol
,
segments: this.options["cylinder"],
one: true
}
segments: this.options["cylinder"],
one: true
}
@@
-2128,7
+2135,7
@@
export default class ChessRules {
segments: this.options["cylinder"],
one: true
},
segments: this.options["cylinder"],
one: true
},
- ([i1, j1], [i2, j2]) =>
this.getColor(i2, j2) == oppCol
+ ([i1, j1], [i2, j2]) =>
oppCol.includes(this.getColor(i2, j2))
)
)
);
)
)
);
@@
-2640,6
+2647,7
@@
export default class ChessRules {
let container = document.getElementById(this.containerId);
if (document.hidden) {
document.onvisibilitychange = () => {
let container = document.getElementById(this.containerId);
if (document.hidden) {
document.onvisibilitychange = () => {
+ // TODO here: page reload ?! (some issues if tab changed...)
document.onvisibilitychange = undefined;
checkDisplayThenAnimate(700);
};
document.onvisibilitychange = undefined;
checkDisplayThenAnimate(700);
};