Fix capture
This will probably not be needed in the near future anyway
This commit is contained in:
@@ -54,7 +54,6 @@ class Chess {
|
|||||||
this.canMoveTo = [];
|
this.canMoveTo = [];
|
||||||
this.syncBackend();
|
this.syncBackend();
|
||||||
document.onclick = (ev) => this.click(ev);
|
document.onclick = (ev) => this.click(ev);
|
||||||
console.log(this.moveSource);
|
|
||||||
}
|
}
|
||||||
syncBackend() {
|
syncBackend() {
|
||||||
let config = this.backend.getConfig();
|
let config = this.backend.getConfig();
|
||||||
@@ -67,7 +66,6 @@ class Chess {
|
|||||||
showAvailableMoves(canMoveTo) {
|
showAvailableMoves(canMoveTo) {
|
||||||
}
|
}
|
||||||
click(ev) {
|
click(ev) {
|
||||||
console.log(this);
|
|
||||||
if (this.moveSource === null) {
|
if (this.moveSource === null) {
|
||||||
this._firstClick(ev);
|
this._firstClick(ev);
|
||||||
}
|
}
|
||||||
@@ -133,13 +131,16 @@ class Configuration {
|
|||||||
return this.pieces.find(piece => piece.position === position) || null;
|
return this.pieces.find(piece => piece.position === position) || null;
|
||||||
}
|
}
|
||||||
dropAt(position) {
|
dropAt(position) {
|
||||||
return this.pieces.filter(piece => piece.position !== position);
|
return new Configuration(
|
||||||
|
this.pieces.filter(piece => piece.position !== position)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
makeMove(move) {
|
makeMove(move) {
|
||||||
const pieceToMove = this.getAt(move.from);
|
const pieceToMove = this.getAt(move.from);
|
||||||
if (pieceToMove === null) return this;
|
if (pieceToMove === null) return this;
|
||||||
else return new Configuration([
|
else return new Configuration([
|
||||||
...this.dropAt(move.from), pieceToMove.moveTo(move.to)
|
...(this.dropAt(move.from).dropAt(move.to).pieces),
|
||||||
|
pieceToMove.moveTo(move.to)
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user