Ejemplo n.º 1
0
        public CPiece King_Piece()
        {
            CPiece King = new CPiece();

            foreach (CPiece c in ListPieces)
            {
                if (c.PieceType == 1)
                {
                    King = c;
                }
            }
            return(King);
        }
Ejemplo n.º 2
0
        public CPiece Pawn_Piece(int PieceID)
        {
            CPiece Pawn = new CPiece();

            foreach (CPiece c in ListPieces)
            {
                if (c.Piece_ID == PieceID)
                {
                    Pawn = c;
                }
            }
            return(Pawn);
        }
Ejemplo n.º 3
0
        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!");
                }
            }
        }
Ejemplo n.º 4
0
        public CPiece Pawn_Evaluation(CCartographie cartographie)
        {
            CPiece Pawn_deplace = new CPiece();
            bool   Need_random  = true;

            bool[,] table_mouvement_Pawn_0 = new bool[5, 5];
            bool[,] table_mouvement_Pawn_1 = new bool[5, 5];
            bool[,] table_mouvement_Pawn_2 = new bool[5, 5];
            bool[,] table_mouvement_Pawn_3 = new bool[5, 5];
            bool[,] table_mouvement_Pawn_4 = new bool[5, 5];
            int[,] table0 = new int[5, 5];
            int[,] table1 = new int[5, 5];
            int[,] table2 = new int[5, 5];
            int[,] table3 = new int[5, 5];
            int[,] table4 = new int[5, 5];
            #region Traitement si AI n'est pas blanc
            if (!_AI_White)
            {
                table_mouvement_Pawn_0 = cartographie.Position_Mouvement(cartographie.ReturnListDesPieces[0].PieceType, cartographie.ReturnListDesPieces[0].x, cartographie.ReturnListDesPieces[0].y);
                table_mouvement_Pawn_1 = cartographie.Position_Mouvement(cartographie.ReturnListDesPieces[1].PieceType, cartographie.ReturnListDesPieces[1].x, cartographie.ReturnListDesPieces[1].y);
                table_mouvement_Pawn_2 = cartographie.Position_Mouvement(cartographie.ReturnListDesPieces[2].PieceType, cartographie.ReturnListDesPieces[2].x, cartographie.ReturnListDesPieces[2].y);
                table_mouvement_Pawn_3 = cartographie.Position_Mouvement(cartographie.ReturnListDesPieces[3].PieceType, cartographie.ReturnListDesPieces[3].x, cartographie.ReturnListDesPieces[3].y);
                table_mouvement_Pawn_4 = cartographie.Position_Mouvement(cartographie.ReturnListDesPieces[4].PieceType, cartographie.ReturnListDesPieces[4].x, cartographie.ReturnListDesPieces[4].y);
                for (int i = 0; i < 5; i++)
                {
                    if (table_mouvement_Pawn_0[i, 4] == true && cartographie.Pawn_Piece(0).y != 4)
                    {
                        Pawn_deplace.PieceType = 2;
                        Pawn_deplace.x         = i;
                        Pawn_deplace.y         = 4;
                        Pawn_deplace.Piece_ID  = 0;
                        Need_random            = false;
                    }
                    if (table_mouvement_Pawn_1[i, 4] == true && cartographie.Pawn_Piece(1).y != 4)
                    {
                        Pawn_deplace.PieceType = 2;
                        Pawn_deplace.x         = i;
                        Pawn_deplace.y         = 4;
                        Pawn_deplace.Piece_ID  = 1;
                        Need_random            = false;
                    }
                    if (table_mouvement_Pawn_2[i, 4] == true && cartographie.Pawn_Piece(2).y != 4)
                    {
                        Pawn_deplace.PieceType = 2;
                        Pawn_deplace.x         = i;
                        Pawn_deplace.y         = 4;
                        Pawn_deplace.Piece_ID  = 2;
                        Need_random            = false;
                    }
                    if (table_mouvement_Pawn_3[i, 4] == true && cartographie.Pawn_Piece(3).y != 4)
                    {
                        Pawn_deplace.PieceType = 2;
                        Pawn_deplace.x         = i;
                        Pawn_deplace.y         = 4;
                        Pawn_deplace.Piece_ID  = 3;
                        Need_random            = false;
                    }
                    if (table_mouvement_Pawn_4[i, 4] == true && cartographie.Pawn_Piece(4).y != 4)
                    {
                        Pawn_deplace.PieceType = 2;
                        Pawn_deplace.x         = i;
                        Pawn_deplace.y         = 4;
                        Pawn_deplace.Piece_ID  = 4;
                        Need_random            = false;
                    }
                }
                while (Need_random)
                {
                    Random rnd_Pawn        = new Random();
                    int    rnd_Pawn_number = rnd_Pawn.Next(0, 5);
                    int    count           = 0;

                    if (rnd_Pawn_number == 0)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            for (int j = 0; j < 5; j++)
                            {
                                if (table_mouvement_Pawn_0[i, j])
                                {
                                    table0[i, j] = count;
                                    count++;
                                }
                            }
                        }
                        if (count != 0)
                        {
                            int rnd_Pawn_move = rnd_Pawn.Next(0, count);
                            for (int i = 0; i < 5; i++)
                            {
                                for (int j = 0; j < 5; j++)
                                {
                                    if (rnd_Pawn_move == table0[i, j] && table_mouvement_Pawn_0[i, j])
                                    {
                                        Pawn_deplace.PieceType = 2;
                                        Pawn_deplace.x         = i;
                                        Pawn_deplace.y         = j;
                                        Pawn_deplace.Piece_ID  = 0;
                                        Need_random            = false;
                                    }
                                }
                            }
                        }
                    }
                    count = 0;
                    if (rnd_Pawn_number == 1)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            for (int j = 0; j < 5; j++)
                            {
                                if (table_mouvement_Pawn_1[i, j])
                                {
                                    table1[i, j] = count;
                                    count++;
                                }
                            }
                        }
                        if (count != 0)
                        {
                            int rnd_Pawn_move = rnd_Pawn.Next(0, count);
                            for (int i = 0; i < 5; i++)
                            {
                                for (int j = 0; j < 5; j++)
                                {
                                    if (table1[i, j] == rnd_Pawn_move && table_mouvement_Pawn_1[i, j])
                                    {
                                        Pawn_deplace.PieceType = 2;
                                        Pawn_deplace.x         = i;
                                        Pawn_deplace.y         = j;
                                        Pawn_deplace.Piece_ID  = 1;
                                        Need_random            = false;
                                    }
                                }
                            }
                        }
                    }
                    count = 0;
                    if (rnd_Pawn_number == 2)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            for (int j = 0; j < 5; j++)
                            {
                                if (table_mouvement_Pawn_2[i, j])
                                {
                                    table2[i, j] = count;
                                    count++;
                                }
                            }
                        }
                        if (count != 0)
                        {
                            int rnd_Pawn_move = rnd_Pawn.Next(0, count);
                            for (int i = 0; i < 5; i++)
                            {
                                for (int j = 0; j < 5; j++)
                                {
                                    if (table2[i, j] == rnd_Pawn_move && table_mouvement_Pawn_2[i, j])
                                    {
                                        Pawn_deplace.PieceType = 2;
                                        Pawn_deplace.x         = i;
                                        Pawn_deplace.y         = j;
                                        Pawn_deplace.Piece_ID  = 2;
                                        Need_random            = false;
                                    }
                                }
                            }
                        }
                    }
                    count = 0;
                    if (rnd_Pawn_number == 3)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            for (int j = 0; j < 5; j++)
                            {
                                if (table_mouvement_Pawn_3[i, j])
                                {
                                    table3[i, j] = count;
                                    count++;
                                }
                            }
                        }
                        if (count != 0)
                        {
                            int rnd_Pawn_move = rnd_Pawn.Next(0, count);
                            for (int i = 0; i < 5; i++)
                            {
                                for (int j = 0; j < 5; j++)
                                {
                                    if (table3[i, j] == rnd_Pawn_move && table_mouvement_Pawn_3[i, j])
                                    {
                                        Pawn_deplace.PieceType = 2;
                                        Pawn_deplace.x         = i;
                                        Pawn_deplace.y         = j;
                                        Pawn_deplace.Piece_ID  = 3;
                                        Need_random            = false;
                                    }
                                }
                            }
                        }
                    }
                    count = 0;
                    if (rnd_Pawn_number == 4)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            for (int j = 0; j < 5; j++)
                            {
                                if (table_mouvement_Pawn_4[i, j])
                                {
                                    table4[i, j] = count;
                                    count++;
                                }
                            }
                        }
                        if (count != 0)
                        {
                            int rnd_Pawn_move = rnd_Pawn.Next(0, count);
                            for (int i = 0; i < 5; i++)
                            {
                                for (int j = 0; j < 5; j++)
                                {
                                    if (table4[i, j] == rnd_Pawn_move && table_mouvement_Pawn_4[i, j])
                                    {
                                        Pawn_deplace.PieceType = 2;
                                        Pawn_deplace.x         = i;
                                        Pawn_deplace.y         = j;
                                        Pawn_deplace.Piece_ID  = 4;
                                        Need_random            = false;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            #region Traitement si AI est blanc
            else
            {
                table_mouvement_Pawn_0 = cartographie.Position_Mouvement(cartographie.ReturnListDesPieces[5].PieceType, cartographie.ReturnListDesPieces[5].x, cartographie.ReturnListDesPieces[5].y);
                table_mouvement_Pawn_1 = cartographie.Position_Mouvement(cartographie.ReturnListDesPieces[6].PieceType, cartographie.ReturnListDesPieces[6].x, cartographie.ReturnListDesPieces[6].y);
                table_mouvement_Pawn_2 = cartographie.Position_Mouvement(cartographie.ReturnListDesPieces[7].PieceType, cartographie.ReturnListDesPieces[7].x, cartographie.ReturnListDesPieces[7].y);
                table_mouvement_Pawn_3 = cartographie.Position_Mouvement(cartographie.ReturnListDesPieces[8].PieceType, cartographie.ReturnListDesPieces[8].x, cartographie.ReturnListDesPieces[8].y);
                table_mouvement_Pawn_4 = cartographie.Position_Mouvement(cartographie.ReturnListDesPieces[9].PieceType, cartographie.ReturnListDesPieces[9].x, cartographie.ReturnListDesPieces[9].y);
                for (int i = 0; i < 5; i++)
                {
                    if (table_mouvement_Pawn_0[i, 0] == true && cartographie.Pawn_Piece(5).y != 0)
                    {
                        Pawn_deplace.PieceType = 3;
                        Pawn_deplace.x         = i;
                        Pawn_deplace.y         = 0;
                        Pawn_deplace.Piece_ID  = 5;
                        Need_random            = false;
                    }
                    if (table_mouvement_Pawn_1[i, 0] == true && cartographie.Pawn_Piece(6).y != 0)
                    {
                        Pawn_deplace.PieceType = 3;
                        Pawn_deplace.x         = i;
                        Pawn_deplace.y         = 0;
                        Pawn_deplace.Piece_ID  = 6;
                        Need_random            = false;
                    }
                    if (table_mouvement_Pawn_2[i, 0] == true && cartographie.Pawn_Piece(7).y != 0)
                    {
                        Pawn_deplace.PieceType = 3;
                        Pawn_deplace.x         = i;
                        Pawn_deplace.y         = 0;
                        Pawn_deplace.Piece_ID  = 7;
                        Need_random            = false;
                    }
                    if (table_mouvement_Pawn_3[i, 0] == true && cartographie.Pawn_Piece(8).y != 0)
                    {
                        Pawn_deplace.PieceType = 3;
                        Pawn_deplace.x         = i;
                        Pawn_deplace.y         = 0;
                        Pawn_deplace.Piece_ID  = 8;
                        Need_random            = false;
                    }
                    if (table_mouvement_Pawn_4[i, 0] == true && cartographie.Pawn_Piece(9).y != 0)
                    {
                        Pawn_deplace.PieceType = 3;
                        Pawn_deplace.x         = i;
                        Pawn_deplace.y         = 0;
                        Pawn_deplace.Piece_ID  = 8;
                        Need_random            = false;
                    }
                }
                while (Need_random)
                {
                    Random rnd_Pawn        = new Random();
                    int    rnd_Pawn_number = rnd_Pawn.Next(0, 5);
                    int    count           = 0;

                    if (rnd_Pawn_number == 0)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            for (int j = 0; j < 5; j++)
                            {
                                if (table_mouvement_Pawn_0[i, j])
                                {
                                    table0[i, j] = count;
                                    count++;
                                }
                            }
                        }
                        if (count != 0)
                        {
                            int rnd_Pawn_move = rnd_Pawn.Next(0, count);
                            for (int i = 0; i < 5; i++)
                            {
                                for (int j = 0; j < 5; j++)
                                {
                                    if (rnd_Pawn_move == table0[i, j] && table_mouvement_Pawn_0[i, j])
                                    {
                                        Pawn_deplace.PieceType = 3;
                                        Pawn_deplace.x         = i;
                                        Pawn_deplace.y         = j;
                                        Pawn_deplace.Piece_ID  = 5;
                                        Need_random            = false;
                                    }
                                }
                            }
                        }
                    }
                    count = 0;
                    if (rnd_Pawn_number == 1)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            for (int j = 0; j < 5; j++)
                            {
                                if (table_mouvement_Pawn_1[i, j])
                                {
                                    table1[i, j] = count;
                                    count++;
                                }
                            }
                        }
                        if (count != 0)
                        {
                            int rnd_Pawn_move = rnd_Pawn.Next(0, count);
                            for (int i = 0; i < 5; i++)
                            {
                                for (int j = 0; j < 5; j++)
                                {
                                    if (table1[i, j] == rnd_Pawn_move && table_mouvement_Pawn_1[i, j])
                                    {
                                        Pawn_deplace.PieceType = 3;
                                        Pawn_deplace.x         = i;
                                        Pawn_deplace.y         = j;
                                        Pawn_deplace.Piece_ID  = 6;
                                        Need_random            = false;
                                    }
                                }
                            }
                        }
                    }
                    count = 0;
                    if (rnd_Pawn_number == 2)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            for (int j = 0; j < 5; j++)
                            {
                                if (table_mouvement_Pawn_2[i, j])
                                {
                                    table2[i, j] = count;
                                    count++;
                                }
                            }
                        }
                        if (count != 0)
                        {
                            int rnd_Pawn_move = rnd_Pawn.Next(0, count);
                            for (int i = 0; i < 5; i++)
                            {
                                for (int j = 0; j < 5; j++)
                                {
                                    if (table2[i, j] == rnd_Pawn_move && table_mouvement_Pawn_2[i, j])
                                    {
                                        Pawn_deplace.PieceType = 3;
                                        Pawn_deplace.x         = i;
                                        Pawn_deplace.y         = j;
                                        Pawn_deplace.Piece_ID  = 7;
                                        Need_random            = false;
                                    }
                                }
                            }
                        }
                    }
                    count = 0;
                    if (rnd_Pawn_number == 3)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            for (int j = 0; j < 5; j++)
                            {
                                if (table_mouvement_Pawn_3[i, j])
                                {
                                    table3[i, j] = count;
                                    count++;
                                }
                            }
                        }
                        if (count != 0)
                        {
                            int rnd_Pawn_move = rnd_Pawn.Next(0, count);
                            for (int i = 0; i < 5; i++)
                            {
                                for (int j = 0; j < 5; j++)
                                {
                                    if (table3[i, j] == rnd_Pawn_move && table_mouvement_Pawn_3[i, j])
                                    {
                                        Pawn_deplace.PieceType = 3;
                                        Pawn_deplace.x         = i;
                                        Pawn_deplace.y         = j;
                                        Pawn_deplace.Piece_ID  = 8;
                                        Need_random            = false;
                                    }
                                }
                            }
                        }
                    }
                    count = 0;
                    if (rnd_Pawn_number == 4)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            for (int j = 0; j < 5; j++)
                            {
                                if (table_mouvement_Pawn_4[i, j])
                                {
                                    table4[i, j] = count;
                                    count++;
                                }
                            }
                        }
                        if (count != 0)
                        {
                            int rnd_Pawn_move = rnd_Pawn.Next(0, count);
                            for (int i = 0; i < 5; i++)
                            {
                                for (int j = 0; j < 5; j++)
                                {
                                    if (table4[i, j] == rnd_Pawn_move && table_mouvement_Pawn_4[i, j])
                                    {
                                        Pawn_deplace.PieceType = 3;
                                        Pawn_deplace.x         = i;
                                        Pawn_deplace.y         = j;
                                        Pawn_deplace.Piece_ID  = 9;
                                        Need_random            = false;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            #endregion

            return(Pawn_deplace);
        }