private void AI_Move() { ((CGraphiqueSolo)(this.Parent)).majlabel("Computer Turn!"); CAnalyse analyse = new CAnalyse(_WhiteTurn, _AI_White, _KingBlackMoved, _GameState); analyse.King_Evaluation(m); if (!AI_White) { if (m.King_Piece() != null && _KingBlackMoved == false) { m.Update_position(1, m.King_Piece().x, m.King_Piece().y, analyse.Kingdx, analyse.Kingdy); ((CGraphiqueSolo)(this.Parent)).debug_label1(analyse.Kingdx.ToString() + " " + analyse.Kingdy.ToString() + " "); _KingBlackMoved = true; _KingWhiteMoved = false; } if (analyse.Pawn_Evaluation(m) != null && _WhiteTurn == false) { CPiece get_ans = new CPiece(); get_ans = analyse.Pawn_Evaluation(m); int dx = get_ans.x; int dy = get_ans.y; m.Update_position(2, m.Pawn_Piece(get_ans.Piece_ID).x, m.Pawn_Piece(get_ans.Piece_ID).y, get_ans.x, get_ans.y); ((CGraphiqueSolo)(this.Parent)).debug_label2(get_ans.Piece_ID.ToString() + " " + get_ans.x.ToString() + " " + get_ans.y.ToString() + " "); _WhiteTurn = true; ((CGraphiqueSolo)(this.Parent)).majlabel("Player Turn!"); } } else { if (m.King_Piece() != null && _KingWhiteMoved == false) { m.Update_position(1, m.King_Piece().x, m.King_Piece().y, analyse.Kingdx, analyse.Kingdy); ((CGraphiqueSolo)(this.Parent)).debug_label1(analyse.Kingdx.ToString() + " " + analyse.Kingdy.ToString() + " "); _KingBlackMoved = false; _KingWhiteMoved = true; } if (analyse.Pawn_Evaluation(m) != null && _WhiteTurn == true) { CPiece get_ans = new CPiece(); get_ans = analyse.Pawn_Evaluation(m); int dx = get_ans.x; int dy = get_ans.y; m.Update_position(3, m.Pawn_Piece(get_ans.Piece_ID).x, m.Pawn_Piece(get_ans.Piece_ID).y, get_ans.x, get_ans.y); ((CGraphiqueSolo)(this.Parent)).debug_label2(get_ans.Piece_ID.ToString() + " " + get_ans.x.ToString() + " " + get_ans.y.ToString() + " "); _WhiteTurn = false; ((CGraphiqueSolo)(this.Parent)).majlabel("Player Turn!"); } } }
public void King_Evaluation(CCartographie cartographie) { bool[,] table_mouvement_possible = new bool[5, 5]; bool Need_Random = true; table_mouvement_possible = cartographie.Position_Mouvement(1, cartographie.King_Piece().x, cartographie.King_Piece().y); _KingdX = cartographie.King_Piece().x; _KingdY = cartographie.King_Piece().y; for (int j = 0; j < 5; j++) { if (table_mouvement_possible[j, 0] == true && _AI_White == false && _WhiteTurn == false && _KingMoved == false) { _KingdX = j; _KingdY = 0; Need_Random = false; } if (table_mouvement_possible[j, 4] == true && _AI_White == true && _WhiteTurn == true && _KingMoved == false) { _KingdX = j; _KingdY = 4; Need_Random = false; } } while (Need_Random) { int[,] table = new int[5, 5]; int compt = 0; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { if (table_mouvement_possible[i, j]) { table[i, j] = compt; compt++; } } } Random rnd = new Random(); int rnd_number = rnd.Next(0, compt); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { if (rnd_number == table[i, j] && table_mouvement_possible[i, j]) { if (!_AI_White && j != 4) { _KingdX = i; _KingdY = j; Need_Random = false; } if (_AI_White && j != 0) { _KingdX = i; _KingdY = j; Need_Random = false; } } } } } }