コード例 #1
0
ファイル: CaroChess.cs プロジェクト: lechitam/Gomoku
        public CaroChess()
        {
            InitializeComponent();
            Width = 800;
            Height = 600;
            Paint += new PaintEventHandler(Form1_Paint);

            for (int i = 0; i < graph.Row * graph.Row; i++)
                BoardArr[i % graph.Row, i / graph.Row] = 0;
            eBoard = new EvalBoard(graph);

            //Buttons
            //label3.Image = Properties.Resources.Khung11;

        }
コード例 #2
0
ファイル: CaroChess.cs プロジェクト: 17071997/CaroAI
        public CaroChess()
        {
            InitializeComponent();
            Width  = 800;
            Height = 600;
            Paint += new PaintEventHandler(Form1_Paint);

            for (int i = 0; i < graph.Row * graph.Row; i++)
            {
                BoardArr[i % graph.Row, i / graph.Row] = 0;
            }
            eBoard = new EvalBoard(graph);

            //Buttons
            //label3.Image = Properties.Resources.Khung11;
        }
コード例 #3
0
ファイル: CaroChess.cs プロジェクト: 17071997/CaroAI
        //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 < graph.Row; rw++)
            {
                for (cl = 0; cl < graph.Col - 4; 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 < graph.Col; cl++)
            {
                for (rw = 0; rw < graph.Row - 4; 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 < graph.Col - 4; cl++)
            {
                for (rw = 0; rw < graph.Row - 4; 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 < graph.Row; rw++)
            {
                for (cl = 0; cl < graph.Col - 4; 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;
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: CaroChess.cs プロジェクト: lechitam/Gomoku
        //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 < graph.Row; rw++)            
                for (cl = 0; cl < graph.Col - 4; 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 < graph.Col; cl++)
                for (rw = 0; rw < graph.Row - 4; 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 < graph.Col - 4; cl++)
                for (rw = 0; rw < graph.Row - 4; 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 < graph.Row; rw++)
                for (cl = 0; cl < graph.Col - 4; 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;
                            }
                        }

                    }
                }
            
        }