From ae985c5ed5cbb57d5458fca2e1fd53c07c2482ef Mon Sep 17 00:00:00 2001 From: Peter Osterlund Date: Sat, 7 Jan 2012 22:06:57 +0000 Subject: [PATCH] CuckooChess: Made strength setting between 0% and 10% even weaker. 0% now plays random legal moves, and 10% corresponds to the old 0% setting. --- CuckooChessEngine/src/chess/Search.java | 31 +++++++++++++++++++++---- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/CuckooChessEngine/src/chess/Search.java b/CuckooChessEngine/src/chess/Search.java index 5f997b6..62f4eaf 100644 --- a/CuckooChessEngine/src/chess/Search.java +++ b/CuckooChessEngine/src/chess/Search.java @@ -188,10 +188,31 @@ public class Search { totalNodes = 0; if (scMovesIn.size <= 0) return null; // No moves to search - MoveInfo[] scMoves = new MoveInfo[scMovesIn.size]; - for (int mi = 0, len = 0; mi < scMovesIn.size; mi++) { - Move m = scMovesIn.m[mi]; - scMoves[len++] = new MoveInfo(m, 0); + + MoveInfo[] scMoves; + { + // If strength is < 10%, only include a subset of the root moves. + // At least one move is always included though. + boolean[] includedMoves = new boolean[scMovesIn.size]; + long rndL = pos.zobristHash() ^ randomSeed; + includedMoves[(int)(Math.abs(rndL) % scMovesIn.size)] = true; + int nIncludedMoves = 1; + double pIncl = (strength < 100) ? strength * strength * 1e-4 : 1.0; + for (int mi = 0; mi < scMovesIn.size; mi++) { + rndL = 6364136223846793005L * rndL + 1442695040888963407L; + double rnd = ((rndL & 0x7fffffffffffffffL) % 1000000000) / 1e9; + if (!includedMoves[mi] && (rnd < pIncl)) { + includedMoves[mi] = true; + nIncludedMoves++; + } + } + scMoves = new MoveInfo[nIncludedMoves]; + for (int mi = 0, len = 0; mi < scMovesIn.size; mi++) { + if (includedMoves[mi]) { + Move m = scMovesIn.m[mi]; + scMoves[len++] = new MoveInfo(m, 0); + } + } } maxNodes = initialMaxNodes; nodesToGo = 0; @@ -873,7 +894,7 @@ public class Search { double rnd = ((rndL & 0x7fffffffffffffffL) % 1000000000) / 1e9; double s = strength * 1e-3; - double offs = 4 - 15 * s; + double offs = (17 - 50 * s) / 3; double effPly = ply * Evaluate.interpolate(pos.wMtrl + pos.bMtrl, 0, 30, Evaluate.qV * 4, 100) * 1e-2; double t = effPly + offs; double p = 1/(1+Math.exp(t)); // Probability to "see" move