@cocacola-lover/knight_path_finder
Version:
Iterative path finding Algorithms for knight on a chessboard
39 lines • 1.59 kB
JavaScript
import ChessPointer from "./chess_pointer.js";
function createEmptySquare() {
return { isPassable: true, weight: 1 };
}
export default class Board {
constructor(height, width) {
this.createBasicPointer = (x, y) => new ChessPointer.BasicPointer(x, y, this.squares);
this.createKnightPointer = (x, y) => new ChessPointer.KnightPointer(x, y, this.squares);
this.createKingPointer = (x, y) => new ChessPointer.KingPointer(x, y, this.squares);
this.createBishopPointer = (x, y) => new ChessPointer.BishopPointer(x, y, this.squares);
this.createRookPointer = (x, y) => new ChessPointer.RookPointer(x, y, this.squares);
this.createPawnPointer = (x, y) => new ChessPointer.PawnPointer(x, y, this.squares);
this.createQueenPointer = (x, y) => new ChessPointer.QueenPointer(x, y, this.squares);
this.squares = [];
for (let i = 0; i < width; i++) {
this.squares.push([]);
for (let j = 0; j < height; j++)
this.squares[i].push(createEmptySquare());
}
}
forEach(func) {
for (let i = 0; i < this.squares.length; i++) {
for (let j = 0; j < this.squares[0].length; j++) {
func(this.squares[i][j], i, j);
}
}
}
setPassability(arr) {
this.forEach((value, x, y) => {
this.squares[x][y].isPassable = arr[x][y];
});
}
setWeight(arr) {
this.forEach((value, x, y) => {
this.squares[x][y].weight = arr[x][y];
});
}
}
//# sourceMappingURL=board.js.map