private bool doRandomatk(simap board, int currentside) { List <Move> atklist = AI_tools.getallatk(board); if (atklist.Count == 0) { return(false); } int tmp = rand.Next(atklist.Count); board.executemove(board, atklist[tmp]); return(true); }
public nodes alpha_Beta(Map map) { //start rootnode; nodes rootnode = new nodes(); simap board = new simap(); nodes bestnode = new nodes(); List <Move> atkmovtion = new List <Move>(); List <Move> allmovtion = new List <Move>(); double maxscore = -1000; board = board.createDeepClone(map); rootnode.board = board; rootnode.depth = 0;//根节点的深度为零 currentside = rootnode.board.currentside; atkmovtion = AI_tools.getallatk(board); allmovtion = AI_tools.getallmove(board); alphabeta(rootnode); Console.WriteLine("CUT:" + cut + "\r\n\r\n\r\n"); foreach (nodes child in rootnode.child) { if (child.visit == 0) { continue; } else if (maxscore <= child.beta) { maxscore = child.beta; bestnode = child; } } if (deloop(bestnode, map) == true)//6步里2步以上重复 且为bestnode 则跳出 { rootnode.child.Remove(bestnode); if (map.unflipped > 0) { bestnode = smartflipping(rootnode, map); } else if (map.unflipped == 0 && rootnode.child.Count != 0) { foreach (nodes achild in rootnode.child) { if (maxscore <= achild.beta) { maxscore = achild.beta; bestnode = achild; } } } else if (map.unflipped == 0 && rootnode.child.Count == 0) { bestnode = subAI_Evaluate(map); } } if (bestnode.movtion.desX == -1 && bestnode.movtion.desY == -1) { bestnode = smartflipping(rootnode, map); } return(bestnode); }