Exemple #1
0
 public CoVua()
 {
     InitializeComponent();
     chessBoard = new ChessBoard();
     Controls.Add(chessBoard);
 }
Exemple #2
0
 private void ChoiLaitoolStripMenuItem_Click(object sender, EventArgs e)
 {
     this.Controls.Remove(chessBoard);
     chessBoard = new ChessBoard();
     Controls.Add(chessBoard);
 }
Exemple #3
0
 static public void Chesspiece_Move_forForwarding(Button Source, Button Destination, ChessBoard chessBoard)
 {
     Destination.Text      = Source.Text;
     Destination.ForeColor = Source.ForeColor;
     Source.Text           = "";
     Source.ForeColor      = Color.AliceBlue;
 }
Exemple #4
0
        static public WorthMovement MovementInfo(ChessBoard chessBoard)
        {
            chessBoard.checkMate = chessBoard.CheckMate(chessBoard);
            List <WorthMovement> list = new List <WorthMovement>();

            foreach (Button item in chessBoard.cells)
            {
                WorthMovement move = new WorthMovement();
                move.value = -99999;
                if (item.ForeColor == Color.Black && item.Text != "")
                {
                    move.Source = item.Location;

                    ChessBoard.ResetBoderColor(chessBoard);

                    if (chessBoard.checkMate)
                    {
                        chessBoard.showCheckMate(chessBoard.assassin, chessBoard.king);
                    }
                    ChessBoard.ShowLegalMovement(item, chessBoard);
                    foreach (Button item2 in chessBoard.cells)       //tìm nước đi ngon của quân cờ.
                    {
                        if (item2.FlatAppearance.BorderColor == Color.Blue)
                        {
                            double value = ValuablePosition(item2, chessBoard, item, item.ForeColor)
                                           + WorthChessman2(item2.Text, item) + hazii(item, item2, chessBoard);
                            //if (move.value < value)
                            //{
                            move.value       = value;
                            move.Destination = item2.Location;
                            //}
                            if (move.value != -99999)
                            {
                                list.Add(move);
                            }
                        }
                    }
                    ChessBoard.ResetBoderColor(chessBoard);
                }
            }

            if (list.Count == 0)
            {
                //MessageBox.Show("you win");
                new EndGame(chessBoard).ShowDialog();
                return(new WorthMovement());
            }
            WorthMovement movement, movement2;

            movement = movement2 = list[0];
            for (int i = 1; i < list.Count; i++)
            {
                if (list[i].value > movement.value)
                {
                    movement2 = movement;
                    movement  = list[i];
                }
            }
            if (movement.value - movement2.value < 5)
            {
                Random rd = new Random();
                int    x  = rd.Next(1, 3);
                if (x == 1)
                {
                    return(movement2);
                }
                else
                {
                    return(movement);
                }
            }
            else
            {
                return(movement);
            }
        }
Exemple #5
0
        static internal ChessBoard Forwarding3(Button SourceClone, Button DestinationClone, ChessBoard chessBoardClone, Color color)
        {
            ChessBoard.Chesspiece_Move_forForwarding(SourceClone, DestinationClone, chessBoardClone);
            ChessBoard.ResetBoderColor(chessBoardClone);

            foreach (Button item in chessBoardClone.cells)
            {
                if (item.ForeColor == color)
                {
                    ChessBoard.ShowMovement(item, chessBoardClone);
                }
            }
            return(chessBoardClone);
        }
Exemple #6
0
        static private double hazii(Button Source, Button Destination, ChessBoard chessBoard)
        {
            //ChessBoard Board = CloneButtonsInfo(chessBoard);
            //Button SourceClone = Board.cells[Source.Location.X / chessBoard.cells[0, 0].Width, Source.Location.Y / chessBoard.cells[0, 0].Height];
            //Button DestinationClone = Board.cells[Destination.Location.X / chessBoard.cells[0, 0].Width, Destination.Location.Y / chessBoard.cells[0, 0].Height];
            ChessBoard Board  = Forwarding(Source, Destination, chessBoard);
            ChessBoard Board2 = Forwarding2(Source, Destination, chessBoard);

            double value = 0;

            //if (Source.Text == "king")
            //    return -9999;

            if (Source.Text == "king" &&
                Board.cells[Source.Location.X / chessBoard.cells[0, 0].Width, Source.Location.Y / chessBoard.cells[0, 0].Height].FlatAppearance.BorderColor == Color.Blue)
            {
                return(value += -888);   /////
            }
            else
            if (Board.cells[Source.Location.X / chessBoard.cells[0, 0].Width, Source.Location.Y / chessBoard.cells[0, 0].Height].FlatAppearance.BorderColor == Color.Blue)
            {
                //if (Board2.cells[Destination.Location.X / chessBoard.cells[0, 0].Width, Destination.Location.Y / chessBoard.cells[0, 0].Height].FlatAppearance.BorderColor == Color.Blue)
                //{
                //    switch (Board.cells[Destination.Location.X / chessBoard.cells[0, 0].Width, Destination.Location.Y / chessBoard.cells[0, 0].Height].Text)
                //    {
                //        case "king":
                //            value = 900;
                //            break;
                //        case "pawn":
                //            value = 0.5;
                //            break;
                //        case "knight":
                //            value = 22;
                //            break;
                //        case "bishop":
                //            value = 22;
                //            break;
                //        case "rook":
                //            value = 35;
                //            break;
                //        case "queen":
                //            value = 70;
                //            break;
                //    }
                //}
                //else
                value += WorthChessman(Source.Text) * 4.0 / 5;
            }


            //_________________________________________
            if (Board.cells[Destination.Location.X / chessBoard.cells[0, 0].Width, Destination.Location.Y / chessBoard.cells[0, 0].Height].FlatAppearance.BorderColor == Color.Blue)
            {
                if (Board2.cells[Destination.Location.X / chessBoard.cells[0, 0].Width, Destination.Location.Y / chessBoard.cells[0, 0].Height].FlatAppearance.BorderColor == Color.Blue)
                {
                    switch (Board.cells[Destination.Location.X / chessBoard.cells[0, 0].Width, Destination.Location.Y / chessBoard.cells[0, 0].Height].Text)
                    {
                    case "king":
                        value -= 900;
                        break;

                    case "pawn":
                        break;

                    case "knight":
                        value -= 22;
                        break;

                    case "bishop":
                        value -= 22;
                        break;

                    case "rook":
                        value -= 35;
                        break;

                    case "queen":
                        value -= 70;
                        break;
                    }
                }
                else
                {
                    value -= WorthChessman(Source.Text);
                }
            }

            value += area(Board, Color.Black) - area(Board2, Color.Red);

            return(value);
        }
Exemple #7
0
        /// <summary>
        /// thực hiện nhập thành
        /// </summary>
        /// <param name="chessBoard"></param>
        static public void ExecuteCastling(ChessBoard chessBoard, int ViTri)
        {
            if (chessBoard.MyTurn)
            {
                if (ViTri == 2)
                {
                    chessBoard.cells[0, 7].Text      = "";
                    chessBoard.cells[0, 7].ForeColor = Color.AliceBlue;
                    ChessBoard.PictureInsert(chessBoard.cells[0, 7]);

                    chessBoard.cells[1, 7].Text      = "";
                    chessBoard.cells[1, 7].ForeColor = Color.AliceBlue;
                    ChessBoard.PictureInsert(chessBoard.cells[1, 7]);

                    chessBoard.cells[2, 7].Text      = "king";
                    chessBoard.cells[2, 7].ForeColor = Color.Red;
                    ChessBoard.PictureInsert(chessBoard.cells[2, 7]);

                    chessBoard.cells[3, 7].Text      = "rook";
                    chessBoard.cells[3, 7].ForeColor = Color.Red;
                    ChessBoard.PictureInsert(chessBoard.cells[3, 7]);

                    chessBoard.cells[4, 7].Text      = "";
                    chessBoard.cells[4, 7].ForeColor = Color.AliceBlue;
                    ChessBoard.PictureInsert(chessBoard.cells[4, 7]);
                }
                else if (ViTri == 6)
                {
                    chessBoard.cells[4, 7].Text      = "";
                    chessBoard.cells[4, 7].ForeColor = Color.AliceBlue;
                    ChessBoard.PictureInsert(chessBoard.cells[4, 7]);

                    chessBoard.cells[5, 7].Text      = "rook";
                    chessBoard.cells[5, 7].ForeColor = Color.Red;
                    ChessBoard.PictureInsert(chessBoard.cells[5, 7]);

                    chessBoard.cells[6, 7].Text      = "king";
                    chessBoard.cells[6, 7].ForeColor = Color.Red;
                    ChessBoard.PictureInsert(chessBoard.cells[6, 7]);

                    chessBoard.cells[7, 7].Text      = "";
                    chessBoard.cells[7, 7].ForeColor = Color.AliceBlue;
                    ChessBoard.PictureInsert(chessBoard.cells[7, 7]);
                }
                chessBoard.vua_trang = false; // đã nhập thành
            }
            else
            {
                if (ViTri == 2)
                {
                    chessBoard.cells[0, 0].Text      = "";
                    chessBoard.cells[0, 0].ForeColor = Color.AliceBlue;
                    ChessBoard.PictureInsert(chessBoard.cells[0, 0]);

                    chessBoard.cells[1, 0].Text      = "";
                    chessBoard.cells[1, 0].ForeColor = Color.AliceBlue;
                    ChessBoard.PictureInsert(chessBoard.cells[1, 0]);

                    chessBoard.cells[2, 0].Text      = "king";
                    chessBoard.cells[2, 0].ForeColor = Color.Black;
                    ChessBoard.PictureInsert(chessBoard.cells[2, 0]);

                    chessBoard.cells[3, 0].Text      = "rook";
                    chessBoard.cells[3, 0].ForeColor = Color.Black;
                    ChessBoard.PictureInsert(chessBoard.cells[3, 0]);

                    chessBoard.cells[4, 0].Text      = "";
                    chessBoard.cells[4, 0].ForeColor = Color.AliceBlue;
                    ChessBoard.PictureInsert(chessBoard.cells[4, 0]);
                }
                else if (ViTri == 6)
                {
                    chessBoard.cells[4, 0].Text      = "";
                    chessBoard.cells[4, 0].ForeColor = Color.AliceBlue;
                    ChessBoard.PictureInsert(chessBoard.cells[4, 0]);

                    chessBoard.cells[5, 0].Text      = "rook";
                    chessBoard.cells[5, 0].ForeColor = Color.Black;
                    ChessBoard.PictureInsert(chessBoard.cells[5, 0]);

                    chessBoard.cells[6, 0].Text      = "king";
                    chessBoard.cells[6, 0].ForeColor = Color.Black;
                    ChessBoard.PictureInsert(chessBoard.cells[6, 0]);

                    chessBoard.cells[7, 0].Text      = "";
                    chessBoard.cells[7, 0].ForeColor = Color.AliceBlue;
                    ChessBoard.PictureInsert(chessBoard.cells[7, 0]);
                }
                chessBoard.vua_den = false; // đã nhập thành
            }
        }