コード例 #1
0
ファイル: Computer.cs プロジェクト: AnhTuan2k1/CoVua
        static public void Move(ChessBoard chessBoard)
        {
            WorthMovement ComputerMovement = Computer.MovementInfo(chessBoard);

            if (ComputerMovement.Source == null)
            {
                return;
            }

            int SourceIndexX      = ComputerMovement.Source.X / chessBoard.cells[0, 0].Size.Width;
            int SourceIndexY      = ComputerMovement.Source.Y / chessBoard.cells[0, 0].Size.Height;
            int DestinationIndexX = ComputerMovement.Destination.X / chessBoard.cells[0, 0].Size.Width;
            int DestinationIndexY = ComputerMovement.Destination.Y / chessBoard.cells[0, 0].Size.Height;

            ChessBoard.Chesspiece_Move(chessBoard.cells[SourceIndexX, SourceIndexY], chessBoard.cells[DestinationIndexX, DestinationIndexY], chessBoard);
            chessBoard.checkMate = chessBoard.CheckMate(chessBoard);
            if (chessBoard.checkMate)
            {
                chessBoard.showCheckMate(chessBoard.assassin, chessBoard.king);
            }
            chessBoard.MyTurn = !chessBoard.MyTurn;
            if (chessBoard.endGame())
            {
                return;
            }

            chessBoard.cells[SourceIndexX, SourceIndexY].FlatAppearance.BorderColor           = Color.Blue;
            chessBoard.cells[DestinationIndexX, DestinationIndexY].FlatAppearance.BorderColor = Color.Blue;
            //chessBoard.movementInfos.Add(chessBoard.saveMovementInfor(chessBoard.cells[SourceIndexX, SourceIndexY], chessBoard.cells[DestinationIndexX, DestinationIndexY]));
        }
コード例 #2
0
        static public WorthMovement MovementInfo(ChessBoard chessBoard)
        {
            chessBoard.checkMate = chessBoard.CheckMate(chessBoard);
            List <WorthMovement> list = new List <WorthMovement>();
            WorthMovement        movement;

            foreach (Button item in chessBoard.cells)
            {
                WorthMovement move = new WorthMovement();
                move.value = -9999;
                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.Location.X / chessBoard.cells[0, 0].Size.Width, item2.Location.Y / chessBoard.cells[0, 0].Size.Height)
                                           + WorthChessman(item2.Text) + hazii(item, item2, chessBoard);
                            if (move.value < value)
                            {
                                move.value       = value;
                                move.Destination = item2.Location;
                            }
                        }
                    }
                    ChessBoard.ResetBoderColor(chessBoard);
                    if (move.value != -9999)
                    {
                        list.Add(move);
                    }
                }
            }

            if (list.Count == 0)
            {
                MessageBox.Show("you win");
            }

            movement = list[0];
            for (int i = 1; i < list.Count; i++)
            {
                if (list[i].value > movement.value)
                {
                    movement = list[i];
                }
            }

            return(movement);
        }
コード例 #3
0
        static public void Move(ChessBoard chessBoard)
        {
            WorthMovement ComputerMovement  = Computer.MovementInfo(chessBoard);
            int           SourceIndexX      = ComputerMovement.Source.X / chessBoard.cells[0, 0].Size.Width;
            int           SourceIndexY      = ComputerMovement.Source.Y / chessBoard.cells[0, 0].Size.Height;
            int           DestinationIndexX = ComputerMovement.Destination.X / chessBoard.cells[0, 0].Size.Width;
            int           DestinationIndexY = ComputerMovement.Destination.Y / chessBoard.cells[0, 0].Size.Height;

            chessBoard.movementInfos.Add(chessBoard.saveMovementInfor(chessBoard.cells[SourceIndexX, SourceIndexY], chessBoard.cells[DestinationIndexX, DestinationIndexY]));
            ChessBoard.Chesspiece_Move(chessBoard.cells[SourceIndexX, SourceIndexY], chessBoard.cells[DestinationIndexX, DestinationIndexY], chessBoard);
        }
コード例 #4
0
ファイル: Computer.cs プロジェクト: AnhTuan2k1/CoVua
        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);
            }
        }