import { ChessRules, Move, PiPo } from "@/base_rules";
+import { randInt } from "@/utils/alea";
export class KonaneRules extends ChessRules {
return true;
}
- static get PIECES() {
- return V.PAWN;
- }
-
getPiece() {
return V.PAWN;
}
for (let row of rows) {
let sumElts = 0;
for (let i = 0; i < row.length; i++) {
- if (V.PIECES.includes(row[i].toLowerCase())) sumElts++;
+ if (row[i].toLowerCase() == V.PAWN) sumElts++;
else {
const num = parseInt(row[i], 10);
if (isNaN(num) || num <= 0) return false;
this.captures = []; //reinit for each move
}
- hoverHighlight(x, y) {
- if (this.movesCount >= 2) return false;
+ hoverHighlight([x, y], side) {
const c = this.turn;
+ if (this.movesCount >= 2 || (!!side && side != c)) return false;
if (c == 'w') return (x == y && [0, 3, 4, 7].includes(x));
// "Black": search for empty square and allow nearby
for (let i of [0, 3, 4, 7]) {
else this.captures.pop();
}
- static get SEARCH_DEPTH() {
- return 4;
+ getComputerMove() {
+ const color = this.turn;
+ let mvArray = [];
+ let mv = null;
+ const undoAll = () => {
+ for (let i = mvArray.length - 1; i >= 0; i--) this.undo(mvArray[i]);
+ };
+ // Just play random moves (for now at least. TODO?)
+ while (this.turn == color) {
+ let moves = super.getAllValidMoves();
+ if (moves.length == 0) {
+ // Shouldn't happen, but...
+ undoAll();
+ return null;
+ }
+ mv = moves[randInt(moves.length)];
+ mvArray.push(mv);
+ this.play(mv);
+ }
+ undoAll();
+ return (mvArray.length > 1 ? mvArray : mvArray[0]);
}
getNotation(move) {