예제 #1
0
        /// <summary>
        /// Обязательные ходы из этой клетки этим игроком. Прыжки
        /// </summary>
        /// <param name="row">Ряд</param>
        /// <param name="column">Колонка</param>
        /// <param name="CurrentPlayer">Игрок.</param>
        /// <returns>Список ходов. Если нет то null. первый в списке откуда ходит</returns>
        public List <List <int> > GetJump(int row, int column, IPlayer CurrentPlayer)
        {
            List <List <int> > res = new List <List <int> >();

            if ((row + column) % 2 == 1 && this[row, column] != null && this[row, column].Player == CurrentPlayer)
            {
                //res.Add(GetPosition(row, column));
                ICheckersCell delBeginCheckersCell = this[row, column];
                this[row, column] = null;
                var temp = IsJump(row, column, delBeginCheckersCell);
                if (temp != null)
                {
                    res.AddRange(temp);
                }

                this[row, column] = delBeginCheckersCell;
            }

            //List<int> res = new List<int>();
            //if (IsJump(row,column,CurrentPlayer))
            //{
            //    res.Add(GetPosition(row, column));
            //}
            if (res.Count > 0)
            {
                return(res);
            }
            return(null);
        }
예제 #2
0
        public void PrivateBoardClear_EqualTrue()
        {
            PlayController playController = new PlayController();

            PrivateObject privateObject = new PrivateObject(playController);

            ICheckersCell[] checkersCell = new ICheckersCell[]
            {
                null, null, null, null,
                null, null, null, null,
                null, null, null, null,
                null, null, null, null,
                null, null, null, null,
                null, null, null, null,
                null, null, null, null,
                null, null, null, null,
            };

            privateObject.Invoke("BoardClear");

            IBoard board = (IBoard)(privateObject.GetFieldOrProperty("Board"));

            for (int i = 1; i <= board.Size; i++)
            {
                Assert.AreEqual(checkersCell[i - 1], board[i]);
            }
        }
예제 #3
0
        public void PrivateBoardFilling_EqualTrue()
        {
            PlayController playController = new PlayController();

            PrivateObject privateObject = new PrivateObject(playController);

            privateObject.Invoke("BoardClear");

            privateObject.Invoke("BoardFilling", 2);

            IBoard  board       = (IBoard)(privateObject.GetFieldOrProperty("Board"));
            IPlayer whitePlayer = (IPlayer)(privateObject.GetFieldOrProperty("WhitePlayer"));
            IPlayer blackPlayer = (IPlayer)(privateObject.GetFieldOrProperty("BlackPlayer"));

            IPiece[] pieces = (IPiece[])(privateObject.GetFieldOrProperty("Pieces"));

            ICheckersCell checkersCellWhite = A.Fake <ICheckersCell>();

            A.CallTo(() => checkersCellWhite.Player).Returns(whitePlayer);
            A.CallTo(() => checkersCellWhite.Piece).Returns(pieces[0]);

            ICheckersCell checkersCellBlack = A.Fake <ICheckersCell>();

            A.CallTo(() => checkersCellBlack.Player).Returns(blackPlayer);
            A.CallTo(() => checkersCellBlack.Piece).Returns(pieces[0]);

            ICheckersCell[] checkersCell = new ICheckersCell[]
            {
                checkersCellWhite, checkersCellWhite, checkersCellWhite, checkersCellWhite,
                checkersCellWhite, checkersCellWhite, checkersCellWhite, checkersCellWhite,
                null, null, null, null,
                null, null, null, null,
                null, null, null, null,
                null, null, null, null,
                checkersCellBlack, checkersCellBlack, checkersCellBlack, checkersCellBlack,
                checkersCellBlack, checkersCellBlack, checkersCellBlack, checkersCellBlack,
            };
            for (int i = 1; i <= board.Size; i++)
            {
                if (checkersCell[i - 1] == null || board[i] == null)
                {
                    Assert.AreEqual(checkersCell[i - 1], board[i], $"\ni={i} \nnull ");
                }
                else
                {
                    Assert.AreEqual(checkersCell[i - 1].Player.Name, board[i].Player.Name, $"\ni={i} \nPlayer ");
                    Assert.AreEqual(checkersCell[i - 1].Piece.Name, board[i].Piece.Name, $"\ni={i} \nPiece ");
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Возможен прыжок из этой клетки этим игроком этой фигурой. Прыжки
        /// </summary>
        /// <param name="row">Ряд</param>
        /// <param name="column">Колонка</param>
        /// <param name="CurrentCheckersCell">Фигура и игрок который бьет.</param>
        /// <returns>True возможно false нет</returns>
        private List <List <int> > IsJump(int row, int column, ICheckersCell CurrentCheckersCell)
        {
            List <List <int> > res = new List <List <int> >();

            if ((row + column) % 2 == 1)
            {
                foreach (var item in CurrentCheckersCell.Piece.HowMoves)
                {
                    int changeRow = item.Row;
                    if (!CurrentCheckersCell.Player.GoesForward)
                    {
                        changeRow = -item.Row;
                    }
                    int changeColumn = item.Column;

                    //Существует ячейка
                    bool CheckExistsCell = CheckCell(row + changeRow, column + changeColumn);
                    if (!CheckExistsCell)
                    {
                        continue;
                    }
                    //На ней враг
                    bool IsEnemyCell = this[row + changeRow, column + changeColumn] != null && this[row + changeRow, column + changeColumn].Player != CurrentCheckersCell.Player;

                    //Существует ячейка после
                    bool CheckExistsCellAfter = CheckCell(row + 2 * changeRow, column + 2 * changeColumn);
                    if (!CheckExistsCellAfter)
                    {
                        continue;
                    }
                    //Эта ячейка пуста
                    bool IsEmptyCellAfter = this[row + 2 * changeRow, column + 2 * changeColumn] == null;

                    if (IsEnemyCell && IsEmptyCellAfter)
                    {
                        ICheckersCell enemyCheckersCell = this[row + changeRow, column + changeColumn];
                        this[row + changeRow, column + changeColumn] = null;


                        var list = new List <int>();
                        list.Add(GetPosition(row, column));
                        list.Add(GetPosition(row + 2 * changeRow, column + 2 * changeColumn));

                        var jumps = IsJump(row + 2 * changeRow, column + 2 * changeColumn, CurrentCheckersCell);



                        List <List <int> > temp1 = new List <List <int> >();
                        if (jumps != null)
                        {
                            foreach (var jum in jumps)
                            {
                                List <int> temp2 = new List <int>();
                                temp2.Add(GetPosition(row, column));
                                temp2.AddRange(jum);
                                temp1.Add(temp2);
                            }
                            res.AddRange(temp1);
                        }
                        else
                        {
                            res.Add(list);
                        }



                        this[row + changeRow, column + changeColumn] = enemyCheckersCell;
                    }
                }
            }
            if (res.Count > 0)
            {
                return(res);
            }
            return(null);
        }