- // Search best (half) move for opponent turn
- const getBestMoveEval = () => {
- let score = this.getCurrentScore();
- if (score != "*") {
- if (score == "1/2") return 0;
- return maxeval * (score == "1-0" ? 1 : -1);
- }
- let moves = this.getAllValidMoves();
- let res = oppCol == "w" ? -maxeval : maxeval;
- for (let m of moves) {
- this.play(m);
- score = this.getCurrentScore();
- // Now turn is oppCol,2
- if (score != "*") {
- if (score == "1/2")
- res = oppCol == "w" ? Math.max(res, 0) : Math.min(res, 0);
- else {
- // King captured
- this.undo(m);
- return maxeval * (score == "1-0" ? 1 : -1);
- }
- }
- const evalPos = this.evalPosition();
- res = oppCol == "w" ? Math.max(res, evalPos) : Math.min(res, evalPos);
- this.undo(m);
- }
- return res;
- };
-
- let moves11 = this.getAllValidMoves();