diff --git a/1dchess/chess.html b/1dchess/chess.html
index 1bf4fbd..68b3e53 100644
--- a/1dchess/chess.html
+++ b/1dchess/chess.html
@@ -70,7 +70,7 @@
1D-Chess
Play as white against the AI. You might initally find it more difficult than expected, but assming optimal play, is there a forced win for white?
- Mouse over to reveal answer: Try this line: N4 N5, N6 K7, R4 K6, R2 K7, R5++
+ Mouse over to reveal answer: Try this line: N4 N5, N6 K7, R4 N3, K2 N5, N8 K8, R5++
Rules
diff --git a/1dchess/js/chess-ai.js b/1dchess/js/chess-ai.js
index 1e405c8..0c4b965 100644
--- a/1dchess/js/chess-ai.js
+++ b/1dchess/js/chess-ai.js
@@ -62,15 +62,15 @@ function minimax(gameState, a=-1, b=1, depth=0) {
switch (gameState["gameResult"]["winner"]){
case "white":
//console.log("white win");
- return 1;
+ return 1 - depth * 0.001;
case "black":
//console.log("black win");
- return -1
+ return -1 + depth * 0.001;
case "draw":
return 0;
}
}
- if (canClaimDraw(gameState["pieceList"]) && gameState["bestMove"] != "None") {
+ if (canClaimDraw(gameState["pieceList"]) && depth > 0) {
// console.log("1 knight draw");
return 0;
}
@@ -121,12 +121,8 @@ function minimax(gameState, a=-1, b=1, depth=0) {
childGameState["depth"] = gameState["depth"] + 1;
let childValue = minimax(childGameState, a, b, depth+1);
- if(childValue == 1) {
- gameState["bestMove"] = movePair;
- return childValue
- }
- value = Math.max(value, childValue);
- if (value == childValue) {
+ if (childValue > value) {
+ value = childValue;
gameState["bestMove"] = movePair;
}
a = Math.max(a, value);
@@ -173,15 +169,11 @@ function minimax(gameState, a=-1, b=1, depth=0) {
childGameState["turn"] = otherColor(childGameState["turn"]);
let childValue = minimax(childGameState, a, b, depth+1);
- if(childValue == -1) {
- gameState["bestMove"] = movePair;
- return childValue
- }
- value = Math.min(value, childValue);
- if (value == childValue) {
+ if (childValue < value) {
+ value = childValue;
gameState["bestMove"] = movePair;
}
- b = Math.max(b, value);
+ b = Math.min(b, value);
if (b <= a){
break;
}