-Issue with Dark Bario
-
Otage, Emergo, Pacosako : fonction "buildPiece(arg1, arg2)" returns HTML element with 2 SVG or SVG + number
==> plus simple : deux classes, images superposées (?)
if (o.init)
return Array(2 * V.ReserveArray.length).fill('0').join("");
return (
- ['w', 'b'].map(c => Object.values(this.reserve[c]).join("")).join("")
+ ['w', 'b'].map(c => Object.values(this.reserve[c]).map(
+ v => v.toString(36)).join("")).join("")
);
}
}
getRankInReserve(c, p) {
- const pieces = Object.keys(this.pieces(c, c, p));
+ const pieces = Object.keys(V.ReserveArray);
const lastIndex = pieces.findIndex(pp => pp == p)
let toTest = pieces.slice(0, lastIndex);
return toTest.reduce(
if (this.board[i][j] != "") {
const color = this.getColor(i, j);
const piece = this.getPiece(i, j);
- addPiece(i, j, "g_pieces", this.pieces(color, i, j)[piece]["class"]);
+ addPiece(i, j, "g_pieces",
+ this.pieceDef(piece, color, i, j)["class"]);
this.g_pieces[i][j].classList.add(V.GetColorClass(color));
if (this.enlightened && !this.enlightened[i][j])
this.g_pieces[i][j].classList.add("hidden");
r_cell.style.height = sqResSize + "px";
rcontainer.appendChild(r_cell);
let piece = document.createElement("piece");
- C.AddClass_es(piece, this.pieces(c, c, p)[p]["class"]);
+ C.AddClass_es(piece, this.pieceDef(p, c, c, p)["class"]);
piece.classList.add(V.GetColorClass(c));
piece.style.width = "100%";
piece.style.height = "100%";
const piece = document.createElement("piece");
const cdisp = moves[i].choice || moves[i].appear[0].p;
C.AddClass_es(piece,
- this.pieces(color, moves[i].end.x, moves[i].end.y)[cdisp]["class"]);
+ this.pieceDef(cdisp, color, moves[i].end.x, moves[i].end.y)["class"]);
piece.classList.add(V.GetColorClass(color));
piece.style.width = "100%";
piece.style.height = "100%";
enlightEnpassant() {
// NOTE: shortcut, pawn has only one attack type, doesn't depend on square
// TODO: (0, 0) is wrong, would need to place an attacker here...
- const steps = this.pieces(this.playerColor, 0, 0)["p"].attack[0].steps;
+ const steps = this.pieceDef('p', this.playerColor, 0, 0).attack[0].steps;
for (let step of steps) {
const x = this.epSquare.x - step[0], //NOTE: epSquare.x not on edge
y = this.getY(this.epSquare.y - step[1]);
getPieceType(x, y, p) {
if (!p)
p = this.getPiece(x, y);
- return this.pieces(this.getColor(x, y), x, y)[p].moveas || p;
+ return this.pieceDef(p, this.getColor(x, y), x, y).moveas || p;
}
isKing(x, y, p) {
return (color == 'w' && x >= 6) || (color == 'b' && x <= 1);
}
- pieces(color, x, y) {
- const pawnShift = this.getPawnShift(color || 'w');
- return {
- 'p': {
+ pieceDef(piece, color, x, y) {
+ switch (piece) {
+ case 'p': {
+ const pawnShift = this.getPawnShift(color || 'w');
+ return {
"class": "pawn",
moves: [
{
range: 1
}
]
- },
- 'r': {
+ };
+ }
+ case 'r':
+ return {
"class": "rook",
both: [
{steps: [[0, 1], [0, -1], [1, 0], [-1, 0]]}
]
- },
- 'n': {
+ };
+ case 'n':
+ return {
"class": "knight",
both: [
{
range: 1
}
]
- },
- 'b': {
+ };
+ case 'b':
+ return {
"class": "bishop",
both: [
{steps: [[1, 1], [1, -1], [-1, 1], [-1, -1]]}
]
- },
- 'q': {
+ };
+ case 'q':
+ return {
"class": "queen",
both: [
{
]
}
]
- },
- 'k': {
+ };
+ case 'k':
+ return {
"class": "king",
both: [
{
range: 1
}
]
- },
- // Cannibal kings:
- '!': {"class": "king-pawn", moveas: "p"},
- '#': {"class": "king-rook", moveas: "r"},
- '$': {"class": "king-knight", moveas: "n"},
- '%': {"class": "king-bishop", moveas: "b"},
- '*': {"class": "king-queen", moveas: "q"}
- };
+ };
+ // Cannibal kings:
+ case '!': return {"class": "king-pawn", moveas: "p"};
+ case '#': return {"class": "king-rook", moveas: "r"};
+ case '$': return {"class": "king-knight", moveas: "n"};
+ case '%': return {"class": "king-bishop", moveas: "b"};
+ case '*': return {"class": "king-queen", moveas: "q"};
+ }
}
// NOTE: using special symbols to not interfere with variants' pieces codes
}
getStepSpec(color, x, y, piece) {
- let pieceType = piece;
- let allSpecs = this.pieces(color, x, y);
- if (!piece)
- pieceType = this.getPieceType(x, y);
- else if (allSpecs[piece].moveas)
- pieceType = allSpecs[piece].moveas;
- let res = allSpecs[pieceType];
+ let pieceType =
+ !piece
+ ? this.getPieceType(x, y)
+ : this.pieceDef(piece, color, x, y).moveas || piece;
+ let res = this.pieceDef(pieceType, color, x, y);
if (!res["both"])
res.both = [];
if (!res["moves"])
move.appear.forEach(a => {
this.g_pieces[a.x][a.y] = document.createElement("piece");
C.AddClass_es(this.g_pieces[a.x][a.y],
- this.pieces(a.c, a.x, a.y)[a.p]["class"]);
+ this.pieceDef(a.p, a.c, a.x, a.y)["class"]);
this.g_pieces[a.x][a.y].classList.add(V.GetColorClass(a.c));
this.g_pieces[a.x][a.y].style.width = pieceWidth + "px";
this.g_pieces[a.x][a.y].style.height = pieceWidth + "px";
}
const maxDist = this.getMaxDistance(r);
const apparentColor = this.getColor(start.x, start.y);
- const pieces = this.pieces(apparentColor, start.x, start.y);
if (drag) {
const startCode = this.getPiece(start.x, start.y);
- C.RemoveClass_es(movingPiece, pieces[startCode]["class"]);
- C.AddClass_es(movingPiece, pieces[drag.p]["class"]);
+ C.RemoveClass_es(movingPiece,
+ this.pieceDef(startCode, apparentColor, start.x, start.y)["class"]);
+ C.AddClass_es(movingPiece,
+ this.pieceDef(drag.p, apparentColor, start.x, start.y)["class"]);
if (apparentColor != drag.c) {
movingPiece.classList.remove(V.GetColorClass(apparentColor));
movingPiece.classList.add(V.GetColorClass(drag.c));
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
-<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="230" height="230">
-<circle cx="115" cy="115" r="100" fill="crimson" stroke="darkslategray"/>
-</svg>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
-<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="230" height="230">
-<circle cx="115" cy="115" r="100" fill="crimson" stroke="darkslategray"/>
-<path d="M100,85 h30 v30 h-30 v30 h30" fill="none" stroke-width="5" stroke="black"/>
-</svg>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
-<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="230" height="230">
-<circle cx="115" cy="115" r="100" fill="crimson" stroke="darkslategray"/>
-<path d="M100,85 h30 v30 h-30 M130,115 v30 h-30" fill="none" stroke-width="5" stroke="black"/>
-</svg>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
-<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="230" height="230">
-<circle cx="115" cy="115" r="100" fill="crimson" stroke="darkslategray"/>
-<path d="M100,85 v30 h30 v30 M130,85 v30" fill="none" stroke-width="5" stroke="black"/>
-</svg>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
-<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="230" height="230">
-<circle cx="115" cy="115" r="100" fill="crimson" stroke="darkslategray"/>
-<path d="M130,85 h-30 v30 h30 v30 h-30" fill="none" stroke-width="5" stroke="black"/>
-</svg>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
-<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="230" height="230">
-<circle cx="115" cy="115" r="100" fill="gold" stroke="darkslategray"/>
-</svg>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
-<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="230" height="230">
-<circle cx="115" cy="115" r="100" fill="gold" stroke="darkslategray"/>
-<path d="M100,85 h30 v30 h-30 v30 h30" fill="none" stroke-width="5" stroke="black"/>
-</svg>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
-<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="230" height="230">
-<circle cx="115" cy="115" r="100" fill="gold" stroke="darkslategray"/>
-<path d="M100,85 h30 v30 h-30 M130,115 v30 h-30" fill="none" stroke-width="5" stroke="black"/>
-</svg>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
-<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="230" height="230">
-<circle cx="115" cy="115" r="100" fill="gold" stroke="darkslategray"/>
-<path d="M100,85 v30 h30 v30 M130,85 v30" fill="none" stroke-width="5" stroke="black"/>
-</svg>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
-<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="230" height="230">
-<circle cx="115" cy="115" r="100" fill="gold" stroke="darkslategray"/>
-<path d="M130,85 h-30 v30 h30 v30 h-30" fill="none" stroke-width="5" stroke="black"/>
-</svg>
\ No newline at end of file
# https://travishorn.com/removing-parts-of-shapes-in-svg-b539a89e5649
# https://developer.mozilla.org/fr/docs/Web/SVG/Tutoriel/Paths
-preamble = """<?xml version="1.0" encoding="UTF-8" ?>
+###############################
+# 1. Simple pieces (mono-color)
+###############################
+
+preamble_simple = """<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="230" height="230">"""
for number in range(12):
filename = chr(65 + number + chrShift) + "@.svg"
f = open(filename, "w")
- f.write(preamble)
+ f.write(preamble_simple)
f.write("\n")
f.write(white if color == "white" else black)
f.write("\n")
f.write(final)
f.close()
+################################
+# 1. Composite pieces (bi-color)
+################################
-preamble = """<?xml version="1.0" encoding="UTF-8" ?>
+preamble_composite = """<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="230" height="230">
<defs>
for bottom in range(12):
filename = chr(65 + top + chrShift) + chr(65 + bottom + chrShift) + ".svg"
f = open(filename, "w")
- f.write(preamble)
+ f.write(preamble_composite)
f.write("\n")
f.write(black_bottom if colorTop == "white" else white_bottom)
f.write("\n")
+++ /dev/null
-#!/usr/bin/env python
-
-# Compose each piece SVG with numbers
-# https://travishorn.com/removing-parts-of-shapes-in-svg-b539a89e5649
-# https://developer.mozilla.org/fr/docs/Web/SVG/Tutoriel/Paths
-
-preamble = """<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
-<svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="230" height="230">
-<defs>
- <mask id="stripe">
- <rect x="0" y="0" width="230" height="230" fill="white"/>
- <rect x="0" y="115" width="230" height="115"/>
- </mask>
-</defs>"""
-
-black_top = '<circle cx="115" cy="115" r="100" fill="black" mask="url(#stripe)"/>'
-white_bottom = '<circle cx="115" cy="115" r="100" fill="whitesmoke" stroke="saddlebrown"/>'
-white_top = '<circle cx="115" cy="115" r="100" fill="whitesmoke" stroke="saddlebrown" mask="url(#stripe)"/>'
-black_bottom = '<circle cx="115" cy="115" r="100" fill="black"/>'
-
-digits = {
- "top": [
- # 1 (unused here)
- '<path d="M130,35 v60"',
- # 2
- '<path d="M100,35 h30 v30 h-30 v30 h30"',
- # 3
- '<path d="M100,35 h30 v30 h-30 M130,65 v30 h-30"',
- # 4
- '<path d="M100,35 v30 h30 v30 M130,35 v30"',
- # 5
- '<path d="M130,35 h-30 v30 h30 v30 h-30"',
- # 6
- '<path d="M130,35 h-30 v60 h30 v-30 h-30"',
- # 7
- '<path d="M100,35 h30 v60"',
- # 8
- '<path d="M100,35 h30 v60 h-30 z M100,65 h30"',
- # 9
- '<path d="M100,95 h30 v-60 h-30 v30 h30"',
- # 10
- '<path d="M90,35 v60 M100,35 h30 v60 h-30 v-60"',
- # 11
- '<path d="M90,35 v60 M130,35 v60"',
- # 12
- '<path d="M90,35 v60 M100,35 h30 v30 h-30 v30 h30"'
- ],
- "bottom": [
- # 1 (unused here)
- '<path d="M130,135 v60"',
- # 2
- '<path d="M100,135 h30 v30 h-30 v30 h30"',
- # 3
- '<path d="M100,135 h30 v30 h-30 M130,165 v30 h-30"',
- # 4
- '<path d="M100,135 v30 h30 v30 M130,135 v30"',
- # 5
- '<path d="M130,135 h-30 v30 h30 v30 h-30"',
- # 6
- '<path d="M130,135 h-30 v60 h30 v-30 h-30"',
- # 7
- '<path d="M100,135 h30 v60"',
- # 8
- '<path d="M100,135 h30 v60 h-30 z M100,165 h30"',
- # 9
- '<path d="M100,195 h30 v-60 h-30 v30 h30"',
- # 10
- '<path d="M90,135 v60 M100,135 h30 v60 h-30 v-60"',
- # 11
- '<path d="M90,135 v60 M130,135 v60"',
- # 12
- '<path d="M90,135 v60 M100,135 h30 v30 h-30 v30 h30"'
- ]
-}
-
-final = "</svg>"
-
-for colorTop in ["white", "black"]:
- chrShift = 0 if colorTop == "white" else 32
- for top in range(12):
- for bottom in range(12):
- filename = chr(65 + top + chrShift) + chr(65 + bottom + chrShift) + ".svg"
- f = open(filename, "w")
- f.write(preamble)
- f.write("\n")
- f.write(black_bottom if colorTop == "white" else white_bottom)
- f.write("\n")
- f.write(white_top if colorTop == "white" else black_top)
- f.write("\n")
- if top >= 1:
- f.write(digits["top"][top] + ' fill="none" stroke-width="5" ' + ('stroke="red"' if colorTop == "white" else 'stroke="orange"') + '/>')
- f.write("\n")
- if bottom >= 1:
- f.write(digits["bottom"][bottom] + ' fill="none" stroke-width="5" ' + ('stroke="red"' if colorTop == "black" else 'stroke="orange"') + '/>')
- f.write("\n")
- f.write(final)
- f.close()
get hasEnpassant() {
return false;
}
+ get hasReserve() {
+ return true;
+ }
+ static get HasKing() {
+ return false;
+ }
// board element == piece class ref:
board2fen(b) {
}
getColor(x, y) {
- if (x >= this.size.x)
- return x == this.size.x ? "w" : "b";
- if (this.board[x][y].charCodeAt(0) < 97)
- return 'w';
- return 'b';
+ const sq = (typeof x == "string" ? x : this.board[x][y]);
+ return sq.charCodeAt(0) < 97 ? 'w' : 'b';
+ }
+
+ pieceDef(piece, color, x, y) {
+ //this.board[x][y]
+ // --> TODO
+ // Moving always the same, but look differs
+ // class: classUp, class: classDOwn + composition
}
getPiece(x, y) {
}
genRandInitBaseFen() {
- return { fen: "9/9/9/9/9/9/9/9/9 w 0 12,12", o: {} };
+ return { fen: "9/9/9/9/9/9/9/9/9", o: {} };
}
static get ReserveArray() {
- // Piece type doesn't matter
- return ['@']; //TODO ::
-
-
-
+ return ['a@'];
}
setOtherVariables(fenParsed) {
super.setOtherVariables(fenParsed);
- // Local stack of captures during a turn (squares + directions)
- this.captures = [ [] ];
+ // Last capture during a turn (square + direction)
+ this.lastCapture = null;
}
atLeastOneCaptureFrom([x, y], color, forbiddenStep) {
}
atLeastOneCapture(color) {
- const L0 = this.captures.length;
- const captures = this.captures[L0 - 1];
- const L = captures.length;
- if (L > 0) {
+ if (!!this.lastCapture) {
return (
this.atLeastOneCaptureFrom(
- captures[L-1].square, color, captures[L-1].step)
+ this.lastCapture.square, color, this.lastCapture.step)
);
}
for (let i = 0; i < this.size.x; i++) {
}
getAllLongestCaptures(color) {
- const L0 = this.captures.length;
- const captures = this.captures[L0 - 1];
- const L = captures.length;
let caps = [];
- if (L > 0) {
- let locSteps = [ captures[L-1].step ];
+ if (!!this.lastCapture) {
+ let locSteps = [ this.lastCapture.step ];
let res =
- this.getLongestCapturesFrom(captures[L-1].square, color, locSteps);
+ this.getLongestCapturesFrom(this.lastCapture.square, color, locSteps);
Array.prototype.push.apply(
caps,
- res.map(r => Object.assign({ square: captures[L-1].square }, r))
+ res.map(r => Object.assign({ square: this.lastCapture.square }, r))
);
}
else {
}
getPossibleMovesFrom([x, y], longestCaptures) {
- if (x >= this.size.x) {
+ if (typeof x === "string") {
if (longestCaptures.length == 0)
return this.getReserveMoves(x);
return [];
const color = this.turn;
if (!!this.reserve[color] && !this.atLeastOneCapture(color))
return [];
- const L0 = this.captures.length;
- const captures = this.captures[L0 - 1];
- const L = captures.length;
let moves = [];
if (longestCaptures.length > 0) {
if (
- L > 0 &&
- (x != captures[L-1].square[0] || y != captures[L-1].square[1])
+ !!this.lastCapture &&
+ (x != this.lastCapture.square[0] || y != this.lastCapture.square[1])
) {
return [];
}
move.turn = color; //for undo
V.PlayOnBoard(this.board, move);
if (move.vanish.length == 2) {
- const L0 = this.captures.length;
- let captures = this.captures[L0 - 1];
- captures.push({
+ this.lastCapture = {
square: [move.end.x, move.end.y],
step: [(move.end.x - move.start.x)/2, (move.end.y - move.start.y)/2]
- });
+ };
if (this.atLeastOneCapture(color))
// There could be other captures (mandatory)
move.notTheEnd = true;
if (!move.notTheEnd) {
this.turn = V.GetOppCol(color);
this.movesCount++;
- this.captures.push([]);
+ this.lastCapture = null;
}
}