public override void readFromString(string textBase) { string[] delimitter = { " " }; string[] parts = textBase.Split(delimitter, StringSplitOptions.RemoveEmptyEntries); color = new Ent_color(parts[0]); vertex = new Ent_vertex(parts[1]); }
//Ent_vertex is only really used on the last return public Ent_vertex GetBest(bool curBlack, bool blackUs, int[,] curBoard, int plyDeep, int curPly, out double bestWinRate) { if (plyDeep == curPly) //We do not go deeper, just do monte-carlo and then return { //ATTENTION, we should really keep track of capped before now, or atleast actually calculate them now! //However if we do right here it will change our parent, and we will either have to keep copying //curBoard or reverse the changes here //removeCapturesFinal(curBoard, libertyGroups, ref blackCaptured, ref whiteCaptured); int blackCaptured = 0, whiteCaptured = 0; double averageScore = 0; bestWinRate = MonteCarloForBlackMetadata(curBlack, curBoard, blackCaptured, whiteCaptured, monteCarloCount, ref averageScore); if (!blackUs) { bestWinRate = 1 - bestWinRate; averageScore *= -1; } //Bonus for having a better average score if (averageScore > 10) bestWinRate *= 1.2; else if (averageScore > 5) bestWinRate *= 1.1; else if (averageScore < -10) bestWinRate *= 0.6; else if (averageScore < -5) bestWinRate *= 0.8; else if (averageScore < 0) bestWinRate *= 0.9; return null; } //Search deeper //From curBoard split up... do all possibility for now double[,] bestWinRates = new double[9, 9]; int[,] tempNewBoard = new int[9, 9]; Array.Copy(curBoard, tempNewBoard, 9 * 9); int curColor = curBlack ? 1 : 2; int ourColor = blackUs ? 1 : 2; for (int x = 0; x < 9; x++) for (int y = 0; y < 9; y++) { if (tempNewBoard[x, y] != 0) continue; tempNewBoard[x, y] = curColor; //Place it //Test it GetBest(!curBlack, blackUs, tempNewBoard, plyDeep, curPly + 1, out bestWinRates[x, y]); //Remove it tempNewBoard[x, y] = 0; } if (curBlack == blackUs) //We just choose the best { Ent_vertex bestVertex = null; double bestRate = 0; for (int x = 0; x < 9; x++) for (int y = 0; y < 9; y++) if (bestWinRates[x, y] > bestRate) { bestRate = bestWinRates[x, y]; bestVertex = new Ent_vertex(x, y); } bestWinRate = bestRate; return bestVertex; } else //We choose the worst (as it is not our turn, and the enemy chooses their best (our worst)) { Ent_vertex bestVertex = null; double bestRate = double.MaxValue; for (int x = 0; x < 9; x++) for (int y = 0; y < 9; y++) if (bestWinRates[x, y] < bestRate && bestWinRates[x, y] != 0) { bestRate = bestWinRates[x, y]; bestVertex = new Ent_vertex(x, y); } bestWinRate = bestRate; return bestVertex; } }
public Ent_move(Ent_color _color, Ent_vertex _vertex) { color = _color; vertex = _vertex; }