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); }
private void cal_Proba(Map map) { int unflip_blue_che = map.blueche; int unflip_blue_ma = map.bluema; int unflip_blue_jiang = map.bluejiang; int unflip_blue_shi = map.blueshi; int unflip_blue_xiang = map.bluexiang; int unflip_blue_zu = map.bluezu; int unflip_blue_pao = map.bluepao; int unflip_red_che = map.redche; int unflip_red_ma = map.redma; int unflip_red_jiang = map.redjiang; int unflip_red_shi = map.redshi; int unflip_red_xiang = map.redxiang; int unflip_red_zu = map.redzu; int unflip_red_pao = map.redpao; simap sim_map = new simap(); sim_map = sim_map.createDeepClone(map); List <Move> flipping = new List <Move>(); flipping = AI_tools.getallfliplist(sim_map); int all_unflip = flipping.Count; for (int i = 0; i < 4; i++) { for (int j = 0; j < 8; j++) { if ((map.Matrix[i, j].item.side == 1) && (map.Matrix[i, j].flip == 1))//蓝方 { switch (map.Matrix[i, j].item.type) { case chesstype.che: unflip_blue_che -= 1; break; case chesstype.ma: unflip_blue_ma -= 1; break; case chesstype.jiang: unflip_blue_jiang -= 1; break; case chesstype.pao: unflip_blue_pao -= 1; break; case chesstype.zu: unflip_blue_zu -= 1; break; case chesstype.shi: unflip_blue_shi -= 1; break; case chesstype.xiang: unflip_blue_xiang -= 1; break; } } if (map.Matrix[i, j].item.side == 0)//红方 { switch (map.Matrix[i, j].item.type) { case chesstype.che: unflip_red_che -= 1; break; case chesstype.ma: unflip_red_ma -= 1; break; case chesstype.jiang: unflip_red_jiang -= 1; break; case chesstype.pao: unflip_red_pao -= 1; break; case chesstype.zu: unflip_red_zu -= 1; break; case chesstype.shi: unflip_red_shi -= 1; break; case chesstype.xiang: unflip_red_xiang -= 1; break; } } } } map.Pbche = unflip_blue_che / all_unflip; map.Pbjiang = unflip_blue_jiang / all_unflip; map.Pbma = unflip_blue_ma / all_unflip; map.Pbxiang = unflip_blue_xiang / all_unflip; map.Pbshi = unflip_blue_shi / all_unflip; map.Pbzu = unflip_blue_zu / all_unflip; map.Pbpao = unflip_blue_pao / all_unflip; map.Prche = unflip_red_che / all_unflip; map.Prjiang = unflip_red_jiang / all_unflip; map.Prma = unflip_red_ma / all_unflip; map.Prxiang = unflip_red_xiang / all_unflip; map.Prshi = unflip_red_shi / all_unflip; map.Przu = unflip_red_zu / all_unflip; map.Prpao = unflip_red_pao / all_unflip; }