Make prettier

This commit is contained in:
2021-11-08 21:55:51 +01:00
parent 28011b8f93
commit b246ba83d1
3 changed files with 64 additions and 53 deletions

View File

@@ -1,31 +1,33 @@
import * as visuals from './visuals.js';
import * as visuals from "./visuals.js";
function setupBoard() {
let pawns = [];
for (let x of 'abcdefgh') {
pawns.push(new Piece('pawn', 'black', `${x}7`),
new Piece('pawn', 'white', `${x}2`));
for (let x of "abcdefgh") {
pawns.push(
new Piece("pawn", "black", `${x}7`),
new Piece("pawn", "white", `${x}2`)
);
}
return new Configuration([
new Piece('rook', 'black', 'a8'),
new Piece('rook', 'black', 'h8'),
new Piece('knight', 'black', 'b8'),
new Piece('knight', 'black', 'g8'),
new Piece('bishop', 'black', 'c8'),
new Piece('bishop', 'black', 'f8'),
new Piece('queen', 'black', 'd8'),
new Piece('king', 'black', 'e8'),
new Piece("rook", "black", "a8"),
new Piece("rook", "black", "h8"),
new Piece("knight", "black", "b8"),
new Piece("knight", "black", "g8"),
new Piece("bishop", "black", "c8"),
new Piece("bishop", "black", "f8"),
new Piece("queen", "black", "d8"),
new Piece("king", "black", "e8"),
...pawns,
new Piece('rook', 'white', 'a1'),
new Piece('rook', 'white', 'h1'),
new Piece('knight', 'white', 'b1'),
new Piece('knight', 'white', 'g1'),
new Piece('bishop', 'white', 'c1'),
new Piece('bishop', 'white', 'f1'),
new Piece('queen', 'white', 'd1'),
new Piece('king', 'white', 'e1'),
new Piece("rook", "white", "a1"),
new Piece("rook", "white", "h1"),
new Piece("knight", "white", "b1"),
new Piece("knight", "white", "g1"),
new Piece("bishop", "white", "c1"),
new Piece("bishop", "white", "f1"),
new Piece("queen", "white", "d1"),
new Piece("king", "white", "e1"),
]);
}
@@ -41,7 +43,7 @@ class Backend {
return this.config.clone();
}
getAvailableMoves(position) {
return []
return [];
}
}
@@ -63,13 +65,11 @@ class Chess {
this.configVis = new visuals.ConfigVis(config.pieces);
this.configVis.draw(this.canvas);
}
showAvailableMoves(canMoveTo) {
}
showAvailableMoves(canMoveTo) {}
click(ev) {
if (this.moveSource === null) {
this._firstClick(ev);
}
else {
} else {
this._secondClick(ev);
}
}
@@ -86,7 +86,7 @@ class Chess {
let move = {
from: this.moveSource,
to: visuals.rowColToBoardIndex(...rcB),
}
};
this.backend.makeMove(move);
this.syncBackend();
}
@@ -118,7 +118,7 @@ class Piece {
class Configuration {
constructor(pieces) {
this.pieces = pieces
this.pieces = pieces;
}
clone() {
let pieces = [];
@@ -128,20 +128,21 @@ class Configuration {
return new Configuration(pieces);
}
getAt(position) {
return this.pieces.find(piece => piece.position === position) || null;
return this.pieces.find((piece) => piece.position === position) || null;
}
dropAt(position) {
return new Configuration(
this.pieces.filter(piece => piece.position !== position)
this.pieces.filter((piece) => piece.position !== position)
);
}
makeMove(move) {
const pieceToMove = this.getAt(move.from);
if (pieceToMove === null) return this;
else return new Configuration([
...(this.dropAt(move.from).dropAt(move.to).pieces),
pieceToMove.moveTo(move.to)
])
else
return new Configuration([
...this.dropAt(move.from).dropAt(move.to).pieces,
pieceToMove.moveTo(move.to),
]);
}
}