private ChessWeight GetWeight(int m_x, int m_y, GobangPlayer m_play) { int[] m_Weight = new int[4]; for (int i = 0; i < 4; i++) { m_Weight[i] = GetWeightSingle(i, m_x, m_y, m_play); } //return CalculateWright1(m_Weight, 4, m_play); ChessWeight CW = new ChessWeight(m_Weight, m_play); //if(m_play==Player.Player1) //{ //if (CW.WeightMax == 7 && CW.WeightLarge != 5) //{ //CW.WeightMax = 5; //} //} return(CW); }
public Task <Point> CalculateComputerAI() { return(Task.Run <Point>(() => { Task.Delay(100); //电脑玩家所有的权重集合 ChessWeight[,] m_Weights_Computer = new ChessWeight[21, 21]; //玩家一的所有的权重集合 ChessWeight[,] m_Weights_Player1 = new ChessWeight[21, 21]; //初始化所有的权重子 for (int i = 0; i <= 20; i++) { for (int j = 0; j <= 20; j++) { if (main_chess[i, j].GobangPlayer != GobangPlayer.NonePlayer) { m_Weights_Computer[i, j] = new ChessWeight(new int[] { -1, -1, -1, -1 }, GobangPlayer.Player1); m_Weights_Player1[i, j] = new ChessWeight(new int[] { -1, -1, -1, -1 }, GobangPlayer.Player2); continue; } m_Weights_Computer[i, j] = GetWeight(i, j, GobangPlayer.Player1); m_Weights_Player1[i, j] = GetWeight(i, j, GobangPlayer.Player2); m_Weights_Computer[i, j].WeightOpponent = m_Weights_Player1[i, j].WeightMax; m_Weights_Player1[i, j].WeightOpponent = m_Weights_Computer[i, j].WeightMax; } } //to get the computer highest score point //获取电脑综合评定分最高的点 List <Point> MaxPointComputer = new List <Point>(); int MaxPlayer1 = 0; int MaxPlayer2 = 0; List <Point> MaxPointPlayer1 = new List <Point>(); for (int i = 0; i <= 20; i++) { for (int j = 0; j <= 20; j++) { if (m_Weights_Computer[i, j].TotleScore > MaxPlayer1) { MaxPlayer1 = m_Weights_Computer[i, j].TotleScore; MaxPointComputer.Clear(); MaxPointComputer.Add(new Point(i, j)); } else if (m_Weights_Computer[i, j].TotleScore == MaxPlayer1) { MaxPointComputer.Add(new Point(i, j)); } if (m_Weights_Player1[i, j].TotleScore > MaxPlayer2) { MaxPlayer2 = m_Weights_Player1[i, j].TotleScore; MaxPointPlayer1.Clear(); MaxPointPlayer1.Add(new Point(i, j)); } else if (m_Weights_Player1[i, j].TotleScore == MaxPlayer2) { MaxPointPlayer1.Add(new Point(i, j)); } } } if (MaxPlayer1 > 49 && MaxPlayer2 < 200 || (MaxPlayer1 >= 200 && MaxPlayer2 >= 200)) { int MaxTemp = 0; Point MaxPoint = new Point(); for (int i = 0; i < MaxPointComputer.Count; i++) { if (m_Weights_Computer[MaxPointComputer[i].X, MaxPointComputer[i].Y].WeightOpponent > MaxTemp) { MaxTemp = m_Weights_Computer[MaxPointComputer[i].X, MaxPointComputer[i].Y].WeightOpponent; MaxPoint = MaxPointComputer[i]; } } return MaxPoint; } if (MaxPlayer1 >= MaxPlayer2) { int MaxTemp = 0; Point MaxPoint = new Point(); for (int i = 0; i < MaxPointComputer.Count; i++) { if (m_Weights_Computer[MaxPointComputer[i].X, MaxPointComputer[i].Y].WeightOpponent > MaxTemp) { MaxTemp = m_Weights_Computer[MaxPointComputer[i].X, MaxPointComputer[i].Y].WeightOpponent; MaxPoint = MaxPointComputer[i]; } } return MaxPoint; } else { int MaxTemp = 0; Point MaxPoint = new Point(); for (int i = 0; i < MaxPointPlayer1.Count; i++) { if (m_Weights_Player1[MaxPointPlayer1[i].X, MaxPointPlayer1[i].Y].WeightOpponent > MaxTemp) { MaxTemp = m_Weights_Player1[MaxPointPlayer1[i].X, MaxPointPlayer1[i].Y].WeightOpponent; MaxPoint = MaxPointPlayer1[i]; } } return MaxPoint; } })); }