Exemplo n.º 1
0
 private void AIplayer_Click(object sender, RoutedEventArgs e)
 {
     AIplayer.Visibility   = Visibility.Hidden;
     twoplayer.Visibility  = Visibility.Hidden;
     PlayOnline.Visibility = Visibility.Hidden;
     PC_online.Visibility  = Visibility.Hidden;
     TaoButton1();
     isCreated = true;
     ChangeSize();
     eBoard     = new EvalBoard();
     fWin       = false;
     fEnd       = 0;
     playerFlag = 1;
     for (int i = 0; i < 144; i++)
     {
         BoardArr[i % 12, i / 12]   = 0;
         BoardArrVt[i % 12, i / 12] = 0;
     }
 }
Exemplo n.º 2
0
        private void PC_online_Click(object sender, RoutedEventArgs e)
        {
            AIplayer.Visibility   = Visibility.Hidden;
            twoplayer.Visibility  = Visibility.Hidden;
            PlayOnline.Visibility = Visibility.Hidden;
            PC_online.Visibility  = Visibility.Hidden;
            TaoButton3();
            isCreated = true;
            ChangeSize();
            eBoard = new EvalBoard();
            fWin   = false;
            fEnd   = 0;
            for (int i = 0; i < 144; i++)
            {
                BoardArr[i % 12, i / 12]   = 0;
                BoardArrVt[i % 12, i / 12] = 0;
            }
            Thread AIThread = new Thread(choiPcOnline);

            AIThread.IsBackground = true;
            AIThread.Start();
        }
Exemplo n.º 3
0
        //xu li ai

        //Ham tinh gia tri cho bang luong gia

        private void EvalChessBoard(int player, ref EvalBoard eBoard)
        {
            int rw, cl, ePC, eHuman;

            eBoard.ResetBoard();

            //Danh gia theo hang
            for (rw = 0; rw < 12; rw++)
            {
                for (cl = 0; cl < 8; cl++)
                {
                    ePC = 0; eHuman = 0;
                    for (int i = 0; i < 5; i++)
                    {
                        if (BoardArr[rw, cl + i] == 1)
                        {
                            eHuman++;
                        }
                        if (BoardArr[rw, cl + i] == 2)
                        {
                            ePC++;
                        }
                    }

                    if (eHuman * ePC == 0 && eHuman != ePC)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            if (BoardArr[rw, cl + i] == 0) // Neu o chua duoc danh
                            {
                                if (eHuman == 0)
                                {
                                    if (player == 1)
                                    {
                                        eBoard.EBoard[rw, cl + i] += DScore[ePC];
                                    }
                                    else
                                    {
                                        eBoard.EBoard[rw, cl + i] += AScore[ePC];
                                    }
                                }
                                if (ePC == 0)
                                {
                                    if (player == 2)
                                    {
                                        eBoard.EBoard[rw, cl + i] += DScore[eHuman];
                                    }
                                    else
                                    {
                                        eBoard.EBoard[rw, cl + i] += AScore[eHuman];
                                    }
                                }
                                if (eHuman == 4 || ePC == 4)
                                {
                                    eBoard.EBoard[rw, cl + i] *= 2;
                                }
                            }
                        }
                    }
                }
            }

            //Danh gia theo cot
            for (cl = 0; cl < 12; cl++)
            {
                for (rw = 0; rw < 8; rw++)
                {
                    ePC = 0; eHuman = 0;
                    for (int i = 0; i < 5; i++)
                    {
                        if (BoardArr[rw + i, cl] == 1)
                        {
                            eHuman++;
                        }
                        if (BoardArr[rw + i, cl] == 2)
                        {
                            ePC++;
                        }
                    }

                    if (eHuman * ePC == 0 && eHuman != ePC)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            if (BoardArr[rw + i, cl] == 0) // Neu o chua duoc danh
                            {
                                if (eHuman == 0)
                                {
                                    if (player == 1)
                                    {
                                        eBoard.EBoard[rw + i, cl] += DScore[ePC];
                                    }
                                    else
                                    {
                                        eBoard.EBoard[rw + i, cl] += AScore[ePC];
                                    }
                                }
                                if (ePC == 0)
                                {
                                    if (player == 2)
                                    {
                                        eBoard.EBoard[rw + i, cl] += DScore[eHuman];
                                    }
                                    else
                                    {
                                        eBoard.EBoard[rw + i, cl] += AScore[eHuman];
                                    }
                                }
                                if (eHuman == 4 || ePC == 4)
                                {
                                    eBoard.EBoard[rw + i, cl] *= 2;
                                }
                            }
                        }
                    }
                }
            }

            //Danh gia duong cheo xuong
            for (cl = 0; cl < 8; cl++)
            {
                for (rw = 0; rw < 8; rw++)
                {
                    ePC = 0; eHuman = 0;
                    for (int i = 0; i < 5; i++)
                    {
                        if (BoardArr[rw + i, cl + i] == 1)
                        {
                            eHuman++;
                        }
                        if (BoardArr[rw + i, cl + i] == 2)
                        {
                            ePC++;
                        }
                    }

                    if (eHuman * ePC == 0 && eHuman != ePC)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            if (BoardArr[rw + i, cl + i] == 0) // Neu o chua duoc danh
                            {
                                if (eHuman == 0)
                                {
                                    if (player == 1)
                                    {
                                        eBoard.EBoard[rw + i, cl + i] += DScore[ePC];
                                    }
                                    else
                                    {
                                        eBoard.EBoard[rw + i, cl + i] += AScore[ePC];
                                    }
                                }
                                if (ePC == 0)
                                {
                                    if (player == 2)
                                    {
                                        eBoard.EBoard[rw + i, cl + i] += DScore[eHuman];
                                    }
                                    else
                                    {
                                        eBoard.EBoard[rw + i, cl + i] += AScore[eHuman];
                                    }
                                }
                                if (eHuman == 4 || ePC == 4)
                                {
                                    eBoard.EBoard[rw + i, cl + i] *= 2;
                                }
                            }
                        }
                    }
                }
            }

            //Danh gia duong cheo len
            for (rw = 4; rw < 12; rw++)
            {
                for (cl = 0; cl < 8; cl++)
                {
                    ePC = 0; eHuman = 0;
                    for (int i = 0; i < 5; i++)
                    {
                        if (BoardArr[rw - i, cl + i] == 1)
                        {
                            eHuman++;
                        }
                        if (BoardArr[rw - i, cl + i] == 2)
                        {
                            ePC++;
                        }
                    }

                    if (eHuman * ePC == 0 && eHuman != ePC)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            if (BoardArr[rw - i, cl + i] == 0) // Neu o chua duoc danh
                            {
                                if (eHuman == 0)
                                {
                                    if (player == 1)
                                    {
                                        eBoard.EBoard[rw - i, cl + i] += DScore[ePC];
                                    }
                                    else
                                    {
                                        eBoard.EBoard[rw - i, cl + i] += AScore[ePC];
                                    }
                                }
                                if (ePC == 0)
                                {
                                    if (player == 2)
                                    {
                                        eBoard.EBoard[rw - i, cl + i] += DScore[eHuman];
                                    }
                                    else
                                    {
                                        eBoard.EBoard[rw - i, cl + i] += AScore[eHuman];
                                    }
                                }
                                if (eHuman == 4 || ePC == 4)
                                {
                                    eBoard.EBoard[rw - i, cl + i] *= 2;
                                }
                            }
                        }
                    }
                }
            }
        }