Пример #1
0
        public void canMove(Cell pic, int firstReqv, List <Cell> deletedCells, int currentCond)
        {
            int x;
            int y;

            Deleted_Items newDeletedItem;


            x = pic.x;
            y = pic.y;

            // возможные ходы для Черной в 1 ход
            if (y > 0 && x > 0 && board[y - 1, x - 1].Condition == 0 && currentCond == 2 && firstReqv == 1)
            {
                move_queve.Add(board[y - 1, x - 1]);
            }
            if (y > 0 && x < 7 && board[y - 1, x + 1].Condition == 0 && currentCond == 2 && firstReqv == 1)
            {
                move_queve.Add(board[y - 1, x + 1]);
            }

            // возможные ходы для Белой в 1 ход
            if (y < 7 && x > 0 && board[y + 1, x - 1].Condition == 0 && currentCond == 1 && firstReqv == 1)
            {
                move_queve.Add(board[y + 1, x - 1]);
            }
            if (y < 7 && x < 7 && board[y + 1, x + 1].Condition == 0 && currentCond == 1 && firstReqv == 1)
            {
                move_queve.Add(board[y + 1, x + 1]);
            }

            //
            //
            //Алгоритм кушания (рекурсивный)
            if (y > 1 && x > 1 && board[y - 1, x - 1].Condition != 0 && board[y - 1, x - 1].Condition != currentCond && board[y - 2, x - 2].Condition == 0 && check(board[y - 2, x - 2]) == false)
            {
                List <Cell> newList = new List <Cell>();
                for (int i = 0; i < deletedCells.Count; i++)
                {
                    newList.Add(deletedCells[i]);
                }

                newList.Add(board[y - 1, x - 1]);

                newDeletedItem = new Deleted_Items(board[y - 2, x - 2], newList);
                delItems.Add(newDeletedItem);

                move_queve.Add(board[y - 2, x - 2]);
                canMove(board[y - 2, x - 2], 0, newList, currentCond);
            }
            if (y > 1 && x < 6 && board[y - 1, x + 1].Condition != 0 && board[y - 1, x + 1].Condition != currentCond && board[y - 2, x + 2].Condition == 0 && check(board[y - 2, x + 2]) == false)
            {
                List <Cell> newList = new List <Cell>();
                for (int i = 0; i < deletedCells.Count; i++)
                {
                    newList.Add(deletedCells[i]);
                }

                newList.Add(board[y - 1, x + 1]);

                newDeletedItem = new Deleted_Items(board[y - 2, x + 2], newList);
                delItems.Add(newDeletedItem);

                move_queve.Add(board[y - 2, x + 2]);

                canMove(board[y - 2, x + 2], 0, newList, currentCond);
            }
            if (y < 6 && x > 1 && board[y + 1, x - 1].Condition != 0 && board[y + 1, x - 1].Condition != currentCond && board[y + 2, x - 2].Condition == 0 && check(board[y + 2, x - 2]) == false)
            {
                List <Cell> newList = new List <Cell>();
                for (int i = 0; i < deletedCells.Count; i++)
                {
                    newList.Add(deletedCells[i]);
                }

                newList.Add(board[y + 1, x - 1]);

                newDeletedItem = new Deleted_Items(board[y + 2, x - 2], newList);
                delItems.Add(newDeletedItem);

                move_queve.Add(board[y + 2, x - 2]);

                canMove(board[y + 2, x - 2], 0, newList, currentCond);
            }
            if (y < 6 && x < 6 && board[y + 1, x + 1].Condition != 0 && board[y + 1, x + 1].Condition != currentCond && board[y + 2, x + 2].Condition == 0 && check(board[y + 2, x + 2]) == false)
            {
                List <Cell> newList = new List <Cell>();
                for (int i = 0; i < deletedCells.Count; i++)
                {
                    newList.Add(deletedCells[i]);
                }

                newList.Add(board[y + 1, x + 1]);

                newDeletedItem = new Deleted_Items(board[y + 2, x + 2], newList);
                delItems.Add(newDeletedItem);

                move_queve.Add(board[y + 2, x + 2]);

                canMove(board[y + 2, x + 2], 0, newList, currentCond);
            }
        }
Пример #2
0
        private void canMoveQueen(Cell pic, int firstReqv, List <Cell> deletedCells, int currentCond)
        {
            int x;
            int y;

            x = pic.x;
            y = pic.y;

            int         i       = y;                 //
            int         j       = x;                 //обнуление переменных и List-а
            List <Cell> newList = new List <Cell>(); //

            while (true)                             // вправо вверх
            {
                Deleted_Items buf_del;
                for (int m = 0; m < deletedCells.Count; m++)
                {
                    newList.Add(deletedCells[m]);
                }

                if (i <= -1 || j >= 8 || i >= 8 || j <= -1)
                {
                    break;
                }
                if (i > 0 && j < 7 && board[i - 1, j + 1].Condition == currentCond)
                {
                    break;
                }
                if (i > 1 && j < 6 && (board[i - 1, j + 1].Condition != 0 && board[i - 1, j + 1].Condition != currentCond) && (board[i - 2, j + 2].Condition != 0 && board[i - 2, j + 2].Condition != currentCond))
                {
                    break;
                }

                if (i > 0 && j < 7 && board[i - 1, j + 1].Condition == 0 && check(board[i - 1, j + 1]) == false)
                {
                    List <Cell> bufL = new List <Cell>();
                    for (int m = 0; m < newList.Count; m++)
                    {
                        bufL.Add(newList[m]);
                    }

                    buf_del = new Deleted_Items(board[i - 1, j + 1], bufL);
                    delItems.Add(buf_del);

                    move_queve.Add(board[i - 1, j + 1]);
                }
                if (i > 1 && j < 6 && board[i - 1, j + 1].Condition != 0 && board[i - 1, j + 1].Condition != currentCond && board[i - 2, j + 2].Condition == 0)
                {
                    newList.Add(board[i - 1, j + 1]);

                    List <Cell> bufL = new List <Cell>();
                    for (int m = 0; m < newList.Count; m++)
                    {
                        bufL.Add(newList[m]);
                    }


                    buf_del = new Deleted_Items(board[i - 2, j + 2], bufL);
                    delItems.Add(buf_del);
                    canMove(board[i - 2, j + 2], 0, bufL, currentCond);

                    move_queve.Add(board[i - 2, j + 2]);
                }
                i--;
                j++;
            }

            newList.Clear(); //
            i = y;           //обнуление переменных и List-а
            j = x;           //
            while (true)     // влево вниз
            {
                Deleted_Items buf_del;
                for (int m = 0; m < deletedCells.Count; m++)
                {
                    newList.Add(deletedCells[m]);
                }

                if (i <= -1 || j >= 8 || i >= 8 || j <= -1)
                {
                    break;
                }
                if (i < 7 && j > 0 && board[i + 1, j - 1].Condition == currentCond)
                {
                    break;
                }
                if (i < 6 && j > 1 && (board[i + 1, j - 1].Condition != 0 && board[i + 1, j - 1].Condition != currentCond) && (board[i + 2, j - 2].Condition != 0 && board[i + 2, j - 2].Condition != currentCond))
                {
                    break;
                }

                if (i < 7 && j > 0 && board[i + 1, j - 1].Condition == 0 && check(board[i + 1, j - 1]) == false)
                {
                    List <Cell> bufL = new List <Cell>();
                    for (int m = 0; m < newList.Count; m++)
                    {
                        bufL.Add(newList[m]);
                    }

                    buf_del = new Deleted_Items(board[i + 1, j - 1], bufL);
                    delItems.Add(buf_del);

                    move_queve.Add(board[i + 1, j - 1]);
                }
                if (i < 6 && j > 1 && board[i + 1, j - 1].Condition != 0 && board[i + 1, j - 1].Condition != currentCond && board[i + 2, j - 2].Condition == 0)
                {
                    newList.Add(board[i + 1, j - 1]);

                    List <Cell> bufL = new List <Cell>();
                    for (int m = 0; m < newList.Count; m++)
                    {
                        bufL.Add(newList[m]);
                    }

                    buf_del = new Deleted_Items(board[i + 2, j - 2], bufL);
                    delItems.Add(buf_del);
                    canMove(board[i + 2, j - 2], 0, bufL, currentCond);
                    move_queve.Add(board[i + 2, j - 2]);
                }
                i++;
                j--;
            }



            newList.Clear();
            i = y;
            j = x;
            while (true)// вниз вправо
            {
                Deleted_Items buf_del;
                for (int m = 0; m < deletedCells.Count; m++)
                {
                    newList.Add(deletedCells[m]);
                }

                if (i <= -1 || j >= 8 || i >= 8 || j <= -1)
                {
                    break;
                }
                if (i < 7 && j < 7 && board[i + 1, j + 1].Condition == currentCond)
                {
                    break;
                }
                if (i < 6 && j < 6 && (board[i + 1, j + 1].Condition != 0 && board[i + 1, j + 1].Condition != currentCond) && (board[i + 2, j + 2].Condition != 0 && board[i + 2, j + 2].Condition != currentCond))
                {
                    break;
                }


                if (i < 7 && j < 7 && board[i + 1, j + 1].Condition == 0 && check(board[i + 1, j + 1]) == false)
                {
                    List <Cell> bufL = new List <Cell>();
                    for (int m = 0; m < newList.Count; m++)
                    {
                        bufL.Add(newList[m]);
                    }

                    buf_del = new Deleted_Items(board[i + 1, j + 1], bufL);
                    delItems.Add(buf_del);

                    move_queve.Add(board[i + 1, j + 1]);
                }

                if (i < 6 && j < 6 && board[i + 1, j + 1].Condition != 0 && board[i + 1, j + 1].Condition != currentCond && board[i + 2, j + 2].Condition == 0)
                {
                    newList.Add(board[i + 1, j + 1]);

                    List <Cell> bufL = new List <Cell>();
                    for (int m = 0; m < newList.Count; m++)
                    {
                        bufL.Add(newList[m]);
                    }

                    buf_del = new Deleted_Items(board[i + 2, j + 2], bufL);
                    delItems.Add(buf_del);
                    canMove(board[i + 2, j + 2], 0, bufL, currentCond);
                    move_queve.Add(board[i + 2, j + 2]);
                }
                i++;
                j++;
            }


            newList.Clear();
            i = y;
            j = x;
            while (true)// вверх влево
            {
                Deleted_Items buf_del;
                for (int m = 0; m < deletedCells.Count; m++)
                {
                    newList.Add(deletedCells[m]);
                }

                if (i <= -1 || j >= 8 || i >= 8 || j <= -1)
                {
                    break;
                }
                if (i > 0 && j > 0 && board[i - 1, j - 1].Condition == currentCond)
                {
                    break;
                }
                if (i > 1 && j > 1 && (board[i - 1, j - 1].Condition != 0 && board[i - 1, j - 1].Condition != currentCond) && (board[i - 2, j - 2].Condition != 0 && board[i - 2, j - 2].Condition != currentCond))
                {
                    break;
                }

                if (i > 0 && j > 0 && board[i - 1, j - 1].Condition == 0 && check(board[i - 1, j - 1]) == false)
                {
                    List <Cell> bufL = new List <Cell>();
                    for (int m = 0; m < newList.Count; m++)
                    {
                        bufL.Add(newList[m]);
                    }

                    buf_del = new Deleted_Items(board[i - 1, j - 1], bufL);
                    delItems.Add(buf_del);

                    move_queve.Add(board[i - 1, j - 1]);
                }
                if (i > 1 && j > 1 && board[i - 1, j - 1].Condition != 0 && board[i - 1, j - 1].Condition != currentCond && board[i - 2, j - 2].Condition == 0)
                {
                    newList.Add(board[i - 1, j - 1]);

                    List <Cell> bufL = new List <Cell>();
                    for (int m = 0; m < newList.Count; m++)
                    {
                        bufL.Add(newList[m]);
                    }

                    buf_del = new Deleted_Items(board[i - 2, j - 2], bufL);
                    delItems.Add(buf_del);
                    canMove(board[i - 2, j - 2], 0, bufL, currentCond);
                    move_queve.Add(board[i - 2, j - 2]);
                }
                i--;
                j--;
            }
        }
Пример #3
0
        private void canMove(Cell pic, int firstReqv, List <Cell> deletedCells, int currentCond)
        {
            int x;
            int y;

            Deleted_Items newDeletedItem;

            x = pic.x;
            y = pic.y;

            // возможные ходы для Черной в 1 ход
            if (y > 0 && x > 0 && pole[y - 1, x - 1].Condition == 0 && currentCond == 2 && firstReqv == 1)
            {
                pole[y - 1, x - 1].mypic.Image = possible_step.Image;
                move_queve.Add(pole[y - 1, x - 1]);
            }
            if (y > 0 && x < 7 && pole[y - 1, x + 1].Condition == 0 && currentCond == 2 && firstReqv == 1)
            {
                pole[y - 1, x + 1].mypic.Image = possible_step.Image;
                move_queve.Add(pole[y - 1, x + 1]);
            }

            // возможные ходы для Белой в 1 ход
            if (y < 7 && x > 0 && pole[y + 1, x - 1].Condition == 0 && currentCond == 1 && firstReqv == 1)
            {
                pole[y + 1, x - 1].mypic.Image = possible_step.Image;
                move_queve.Add(pole[y + 1, x - 1]);
            }
            if (y < 7 && x < 7 && pole[y + 1, x + 1].Condition == 0 && currentCond == 1 && firstReqv == 1)
            {
                pole[y + 1, x + 1].mypic.Image = possible_step.Image;
                move_queve.Add(pole[y + 1, x + 1]);
            }

            //
            //
            //Алгоритм кушания (рекурсивный)
            if (y > 1 && x > 1 && pole[y - 1, x - 1].Condition != 0 && pole[y - 1, x - 1].Condition != currentCond && pole[y - 2, x - 2].Condition == 0 && pole[y - 2, x - 2].mypic.Image != possible_step.Image)
            {
                pole[y - 2, x - 2].mypic.Image = possible_step.Image;

                List <Cell> newList = new List <Cell>();
                for (int i = 0; i < deletedCells.Count; i++)
                {
                    newList.Add(deletedCells[i]);
                }

                newList.Add(pole[y - 1, x - 1]);

                newDeletedItem = new Deleted_Items(pole[y - 2, x - 2], newList);
                delItems.Add(newDeletedItem);

                move_queve.Add(pole[y - 2, x - 2]);
                canMove(pole[y - 2, x - 2], 0, newList, currentCond);
            }
            if (y > 1 && x < 6 && pole[y - 1, x + 1].Condition != 0 && pole[y - 1, x + 1].Condition != currentCond && pole[y - 2, x + 2].Condition == 0 && pole[y - 2, x + 2].mypic.Image != possible_step.Image)//&& (currentCond == 2 || (currentCond == 0 && firstReqv == 0)))
            {
                pole[y - 2, x + 2].mypic.Image = possible_step.Image;

                List <Cell> newList = new List <Cell>();
                for (int i = 0; i < deletedCells.Count; i++)
                {
                    newList.Add(deletedCells[i]);
                }

                newList.Add(pole[y - 1, x + 1]);

                newDeletedItem = new Deleted_Items(pole[y - 2, x + 2], newList);
                delItems.Add(newDeletedItem);

                move_queve.Add(pole[y - 2, x + 2]);

                canMove(pole[y - 2, x + 2], 0, newList, currentCond);
            }
            if (y < 6 && x > 1 && pole[y + 1, x - 1].Condition != 0 && pole[y + 1, x - 1].Condition != currentCond && pole[y + 2, x - 2].Condition == 0 && pole[y + 2, x - 2].mypic.Image != possible_step.Image)
            {
                pole[y + 2, x - 2].mypic.Image = possible_step.Image;

                List <Cell> newList = new List <Cell>();
                for (int i = 0; i < deletedCells.Count; i++)
                {
                    newList.Add(deletedCells[i]);
                }

                newList.Add(pole[y + 1, x - 1]);

                newDeletedItem = new Deleted_Items(pole[y + 2, x - 2], newList);
                delItems.Add(newDeletedItem);

                move_queve.Add(pole[y + 2, x - 2]);

                canMove(pole[y + 2, x - 2], 0, newList, currentCond);
            }
            if (y < 6 && x < 6 && pole[y + 1, x + 1].Condition != 0 && pole[y + 1, x + 1].Condition != currentCond && pole[y + 2, x + 2].Condition == 0 && pole[y + 2, x + 2].mypic.Image != possible_step.Image)
            {
                pole[y + 2, x + 2].mypic.Image = possible_step.Image;

                List <Cell> newList = new List <Cell>();
                for (int i = 0; i < deletedCells.Count; i++)
                {
                    newList.Add(deletedCells[i]);
                }

                newList.Add(pole[y + 1, x + 1]);

                newDeletedItem = new Deleted_Items(pole[y + 2, x + 2], newList);
                delItems.Add(newDeletedItem);

                move_queve.Add(pole[y + 2, x + 2]);

                canMove(pole[y + 2, x + 2], 0, newList, currentCond);
            }
        }