- getComputerMove() {
- const moves = this.getAllValidMoves();
- if (moves.length == 0) return null;
- const color = this.turn;
- // Capture available? If yes, play it
- let captures = moves.filter(m => m.vanish.length >= 2);
- let mvArray = [];
- while (captures.length >= 1) {
- // Then just pick random captures (trying to maximize)
- let candidates = captures.filter(c => !!c.notTheEnd);
- let mv = null;
- if (candidates.length >= 1) mv = candidates[randInt(candidates.length)];
- else mv = captures[randInt(captures.length)];
- this.play(mv);
- mvArray.push(mv);
- captures = (this.turn == color ? this.getAllValidMoves() : []);
- }
- if (mvArray.length >= 1) {
- for (let i = mvArray.length - 1; i >= 0; i--) this.undo(mvArray[i]);
- return mvArray;
- }
- // Just play a random move, which if possible does not let a capture
- let candidates = [];
- for (let m of moves) {
- this.play(m);
- if (!this.atLeastOneCapture()) candidates.push(m);
- this.undo(m);
- }
- if (candidates.length >= 1) return candidates[randInt(candidates.length)];
- return moves[randInt(moves.length)];
- }
-
- getNotation(move) {
- if (move.appear.length == 0) return "stop";
- return (
- V.CoordsToSquare(move.start) +
- V.CoordsToSquare(move.end) +
- (move.vanish.length >= 2 ? "X" : "")
- );
- }
-