private void button2_Click(object sender, EventArgs e) { AI ai = new AI(); nodes movnod = new CDC.nodes(); movnod = ai.alpha_Beta(vmap); atkandmove(vmap, movnod);//调用先手AI score(vmap); if (checkboard(movnod, vmap) != 0) { AI_tools.resetground(vmap); MessageBox.Show("Game End!"); } }
private void button3_Click(object sender, EventArgs e) { nodes movnod = new CDC.nodes(); AI ai = new AI(); movnod = ai.alpha_Beta(vmap); if (onedice == 0)//先手为评估函数AI { click(sender, e); onedice = (onedice + 1) % 2;//交换骰子 } else { atkandmove(vmap, movnod); onedice = (onedice + 1) % 2;//交换骰子 } }
private void button1_Click(object sender, EventArgs e) //AI battle { int game_limit = 25; //进行试验的游戏局数 int game_noli_limit = game_limit; int games = 1; //初始化为1 double firstAIwin = 0; //先手AI胜利数 double secondAIwin = 0; //后手AI胜利数 double draw = 0; double draw_3 = 0; double draw_4 = 0; double totalturn = 0;//本次模拟总长度 double totalB = 0; AI ai = new AI(); ai2 ai2 = new ai2(); while (games <= game_limit)//没有执行完规定次数时 { List <double> scoreit = new List <double>(); while (vmap.flag == 0)//循环直到游戏结束 { nodes movnod = new CDC.nodes(); if (vmap.currentside == 0)//先手 { movnod = ai.alpha_Beta(vmap); atkandmove(vmap, movnod); //调用先手AI } else if (vmap.currentside == 1) //后手 { movnod = ai2.alpha_Beta(vmap); atkandmove(vmap, movnod);//调用后手AI } textBox1.AppendText("Experiment Game: " + games + "\r\n"); Console.WriteLine("+++++++++++++++++++++++++++++++++++++" + score(vmap)); double temp = score(vmap); scoreit.Add(temp); vmap.flag = checkboard(movnod, vmap); } Console.WriteLine("One Game Finished"); if ((vmap.firstplayer == 0 && vmap.flag == 2) || (vmap.firstplayer == 1 && vmap.flag == 1))//先手AI胜 { Console.WriteLine("First AI win!"); gameresult.Add(scoreit); firstAIwin++; Allturn.Add(vmap.turncount); //记录每局长度 } else if ((vmap.firstplayer == 0 && vmap.flag == 1) || (vmap.firstplayer == 1 && vmap.flag == 2)) //后手AI胜 { Console.WriteLine("Second AI win!"); gameresult.Add(scoreit); secondAIwin++; Allturn.Add(vmap.turncount);//记录每局长度 } else if (vmap.flag == 3) { draw += 1; draw_3 += 1; Allturn.Add(vmap.turncount);//记录每局长度 gameresult.Add(scoreit); } else if (vmap.flag == 4) { draw_4 += 1; AI_tools.resetground(vmap); allB.Clear(); continue; } Console.WriteLine("Number of Games:" + games);//游戏结束后 games++; cal_averageB(allB); allB.Clear(); AI_tools.resetground(vmap); } for (int i = 0; i < game_noli_limit; i++) { totalturn += Allturn[i] - 1; totalB += calB[i]; } textBox1.AppendText("Simulation Ended" + "\r\n"); textBox1.AppendText("FirstAI Winning Ratio:" + (firstAIwin / game_limit) * 100 + "%" + "\r\n"); textBox1.AppendText("SecondAI Winning Ratio:" + (secondAIwin / game_limit) * 100 + "%" + "\r\n"); textBox1.AppendText("Draw Ratio:" + (draw / game_limit) * 100 + "%" + "\r\n"); textBox1.AppendText("Number of Flag 3 draw:" + draw_3 + "\r\n"); textBox1.AppendText("Number of Flag 4 draw:" + draw_4 + "\r\n"); textBox1.AppendText("Avarage Game Length:" + totalturn / game_noli_limit + " turns" + "\r\n"); textBox1.AppendText("Avarage Branching Factor:" + totalB / game_noli_limit + "\r\n"); for (int i = 0; i < win_jiang.Count; i++) { Console.WriteLine(win_jiang[i]); } Console.WriteLine("=====================================================================================================" + "\r\n"); for (int i = 0; i < win_zu.Count; i++) { Console.WriteLine(win_zu[i]); } Console.WriteLine("=====================================================================================================" + "\r\n"); for (int i = 0; i < win_pao.Count; i++) { Console.WriteLine(win_pao[i]); } Console.WriteLine("=====================================================================================================" + "\r\n"); for (int i = 0; i < lose_jiang.Count; i++) { Console.WriteLine(lose_jiang[i]); } Console.WriteLine("=====================================================================================================" + "\r\n"); for (int i = 0; i < lose_zu.Count; i++) { Console.WriteLine(lose_zu[i]); } Console.WriteLine("=====================================================================================================" + "\r\n"); for (int i = 0; i < lose_pao.Count; i++) { Console.WriteLine(lose_pao[i]); } }