public bool checkRightDoubleRegularAI(int id_row, int id_col)
        {
            // move value to temp.
            AIBoradSection[,] tempTableBoardSection = new AIBoradSection[row, col];
            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    tempTableBoardSection[i, j] = new AIBoradSection(i, j, tableBoardSection[i, j].getPlayerHolder(), tableBoardSection[i, j].getStatus());
                }
            }

            if (isRangeIndex(id_row + 1, id_col + 1))
            {
                if (tempTableBoardSection[id_row + 1, id_col + 1].getPlayerHolder() == 2) // found item enemy.
                {
                    if (isRangeIndex(id_row + 1 + 1, id_col + 1 + 1))
                    {
                        if (tempTableBoardSection[id_row + 1 + 1, id_col + 1 + 1].isEmpty()) // check can kill
                        {
                            deleteItem(tempTableBoardSection, id_row + 1, id_col + 1);
                            moveItem(tempTableBoardSection, id_row, id_col, id_row + 1 + 1, id_col + 1 + 1); // move to kill.
                            addAnswerDouble(id_row, id_col, id_row + 1 + 1, id_col + 1 + 1, id_row + 1, id_col + 1);
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        public int checkRightRegularAI(int id_row, int id_col)
        {
            // move value to temp.
            AIBoradSection[,] tempTableBoardSection = new AIBoradSection[row, col];
            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    tempTableBoardSection[i, j] = new AIBoradSection(i, j, tableBoardSection[i, j].getPlayerHolder(), tableBoardSection[i, j].getStatus());
                }
            }

            if (isRangeIndex(id_row + 1, id_col + 1))
            {                                                                // check index
                if (tempTableBoardSection[id_row + 1, id_col + 1].isEmpty()) // can walk 1 position. not kill.
                {
                    moveItem(tempTableBoardSection, id_row, id_col, id_row + 1, id_col + 1);
                    addAnswerRight(id_row, id_col, id_row + 1, id_col + 1, -1, -1);
                    return(1);
                }
                else  // have item
                {
                    //for debug
                    //if(id_row==2 && id_col==2){
                    //    for (int i = 0; i < row; i++)
                    //    {
                    //        for (int j = 0; j < col; j++)
                    //        {
                    //            Console.Write("" + tableBoardSection[i, j].getPlayerHolder()+" ");
                    //        }
                    //        Console.Write("\n");
                    //    }
                    //}

                    if (tempTableBoardSection[id_row + 1, id_col + 1].getPlayerHolder() == 2) // found item enemy.
                    {
                        if (isRangeIndex(id_row + 1 + 1, id_col + 1 + 1))
                        {
                            if (tempTableBoardSection[id_row + 1 + 1, id_col + 1 + 1].isEmpty()) // check can kill
                            {
                                deleteItem(tempTableBoardSection, id_row + 1, id_col + 1);
                                moveItem(tempTableBoardSection, id_row, id_col, id_row + 1 + 1, id_col + 1 + 1); // move to kill.
                                addAnswerRight(id_row, id_col, id_row + 1 + 1, id_col + 1 + 1, id_row + 1, id_col + 1);
                                return(10 + checkDoubleRegularAI(id_row + 1 + 1, id_col + 1 + 1));
                            }
                        }
                    }
                }
            }
            return(0);
        }
        private void searchDownRightPathSuperItemAI(int i, int j, int myPlayer, bool flagDoubleKill)
        {
            // move value to temp.
            AIBoradSection[,] tempTableBoardSection = new AIBoradSection[row, col];
            for (int u = 0; u < row; u++)
            {
                for (int p = 0; p < col; p++)
                {
                    tempTableBoardSection[u, p] = new AIBoradSection(u, p, tableBoardSection[u, p].getPlayerHolder(), tableBoardSection[u, p].getStatus());
                }
            }

            int id_row_old = i;
            int id_col_old = j;

            i++;
            j++;

            // search walk down right.
            while (i < row && j < col)
            {
                if (tempTableBoardSection[i, j].isEmpty())
                {
                    if (flagDoubleKill == false)
                    {
                        addSectionToListSectionSelectedAI(id_row_old, id_col_old, i, j, -1, -1, 0);
                    }
                    i++;
                    j++;
                }
                else
                {
                    if (tempTableBoardSection[i, j].getPlayerHolder() != myPlayer) // found Enemy
                    {
                        if (i + 1 < row && j + 1 < col)                            // check index next area have real.
                        {
                            if (tempTableBoardSection[i + 1, j + 1].isEmpty())
                            { // next area is empty.
                                addSectionToListSectionSelectedAI(id_row_old, id_col_old, i + 1, j + 1, i, j, 20);
                                flagDoubleSuperItem = true;
                                //searchPathSuperItemDoubleKill(i + 1, j + 1, myPlayer, false); // recursive. not can walk real , just discovery way.
                            }
                        }
                    }
                    break;  // found Section not empty. or has Item.
                }
            }
        }
        public int checkRightRegularPlayer(int id_row, int id_col)
        {
            // move value to temp.
            AIBoradSection[,] tempTableBoardSection = new AIBoradSection[row, col];
            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    tempTableBoardSection[i, j] = new AIBoradSection(i, j, tableBoardSection[i, j].getPlayerHolder(), tableBoardSection[i, j].getStatus());
                }
            }


            if (isRangeIndex(id_row - 1, id_col + 1))
            {                                                                // check index
                if (tempTableBoardSection[id_row - 1, id_col + 1].isEmpty()) // can walk 1 position. not kill.
                {
                    moveItem(tempTableBoardSection, id_row, id_col, id_row - 1, id_col + 1);
                    return(-1);
                }
                else  // have item
                {
                    if (tempTableBoardSection[id_row - 1, id_col + 1].getPlayerHolder() == 1) // found item enemy.
                    {
                        if (isRangeIndex(id_row - 1 - 1, id_col + 1 + 1))
                        {
                            if (tempTableBoardSection[id_row - 1 - 1, id_col + 1 + 1].isEmpty()) // check can kill
                            {
                                deleteItem(tempTableBoardSection, id_row - 1, id_col + 1);
                                moveItem(tempTableBoardSection, id_row, id_col, id_row - 1 - 1, id_col + 1 + 1); // move to kill.
                                return(-10);
                            }
                        }
                    }
                }
            }
            return(0);
        }
Пример #5
0
        //public bool isRangeIndex(int id_row, int id_col)
        //{
        //    if (id_row >= 0 && id_row < row && id_col >= 0 && id_col < col)
        //    {
        //        return true;
        //    }
        //    return false;
        //}

        public void callAIForBoardPinch()
        {
            bool lose = false;

            // MessageBox.Show("Start AI");
            // Initial object BoardSection For AI.
            AIBoradSection[,] tableBoardSectionForAI = new AIBoradSection[row, col];
            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    // get value important for AI assign to table.
                    int player = boardSection[i, j].getPlayerHolder();
                    int status = 0;
                    if (player > 0)
                    {
                        status = ((Item)(boardSection[i, j].getItemFromPanelSection())).getStatusItem();
                        //status = 1;
                    }
                    tableBoardSectionForAI[i, j] = new AIBoradSection(i, j, player, status);
                }
            }

            // Create Object AI , assign data and table to AI.
            AIBoardNeeb nicky = new AIBoardNeeb(row, col, tableBoardSectionForAI, itemPlayer1, itemPlayer2);

            Console.Write("Start AI : ");
            Console.Write("\n\n");
            //nicky.setMaxStep(3);
            int point = nicky.run(0);
            //MessageBox.Show("" + point);

            List <Tuple <int, int, int, int> > listBestAnswer = nicky.getListBestAnswer2();

            if (listBestAnswer.Count <= 0)
            {
                lose = true;
                //MessageBox.Show("Error , ");
            }
            List <Tuple <int, int> > listBestAnswerKillEnemy = nicky.getListBestAnswerKillEnemy2();

            if (listBestAnswer != null)
            {
                Console.Write("\nCount listanswer = " + listBestAnswer.Count + "\n");
                foreach (Tuple <int, int, int, int> buffer in listBestAnswer)
                {
                    //Tuple<int, int, int, int, int, int> buffer = listBestAnswer.First();
                    int id_row_source = buffer.Item1;
                    int id_col_source = buffer.Item2;
                    int id_row_des    = buffer.Item3;
                    int id_col_des    = buffer.Item4;
                    Console.Write("\n " + id_row_source + "," + id_col_source + " " + id_row_des + "," + id_col_des
                                  );

                    moveItem(id_row_source, id_col_source, id_row_des, id_col_des);
                }
                listBestAnswer.Clear();
            }

            if (listBestAnswerKillEnemy != null)
            {
                Console.Write("\nCount listBestAnswerKillEnemy = " + listBestAnswerKillEnemy.Count + "\n");
                //Tuple<int, int, int, int, int, int> buffer = listBestAnswer.First();


                //List<Tuple<int, int, int, int, int, int>> listDouble = nicky.getListBestAnswerDoubleKill();
                //Console.Write("\nCount listdouble = " + listDouble.Count + "\n");
                //listBestAnswer.AddRange(listDouble);

                foreach (Tuple <int, int> buffer in listBestAnswerKillEnemy)
                {
                    //Tuple<int, int, int, int, int, int> buffer = listBestAnswer.First();
                    int id_row = buffer.Item1;
                    int id_col = buffer.Item2;
                    Console.Write("\n " + id_row + "," + id_col
                                  );

                    deleteItem(id_row, id_col);
                }
                listBestAnswerKillEnemy.Clear();
            }
            updateDataDeBugging();

            if (lose)
            {
                //
            }
        }