public void Test_GetFigureAtPositionWhitInvalidPosition()
        {
            Board testBoard = new Board();
            Position position = new Position(100, 'w');

            Assert.AreEqual(null, testBoard.GetFigureAtPosition(position));
        }
        public void Test_GetFigureAtPositionWhitValidEmptyPosition()
        {
            Board testBoard = new Board();
            Position position = new Position(8, 'c');

            Assert.AreEqual(null, testBoard.GetFigureAtPosition(position));
        }
 public void Test_CreatePositionWhitValidData()
 {
     int chessRow = 7;
     char chessCol = 'c';
     Position testedPosition = new Position(chessRow, chessCol);
     bool result = testedPosition.Row == chessRow && testedPosition.Col == chessCol;
     Assert.IsTrue(result);
 }
        public void Test_AddFigureWhitInvalidFigureAndValidPosition()
        {
            Board testBoard = new Board();
            Position position = new Position(5, 'a');
            Pawn testPawn = null;

            testBoard.AddFigure(testPawn, position);
        }
        public void Test_AddFigureWhitValidFigureAndInvalidPosition()
        {
            Board testBoard = new Board();
            Position position = new Position(-61, 'q');
            Pawn testPawn = new Pawn(ChessColor.White);

            testBoard.AddFigure(testPawn, position);
        }
Esempio n. 6
0
        public void RemoveFigure(Position position)
        {
            Position.CheckIfPositionIsValid(position);

            int arrRow = this.GetArrayRow(position.Row);
            int arrCol = this.GetArrayCol(position.Col);
            this.board[arrRow, arrCol] = null;
        }
Esempio n. 7
0
        public void AddFigure(IFigure figure, Position position)
        {
            ObjectValidator.CheckIfObjectIsNull(figure, GlobalErrorMessages.NullFigureErrorMessages);
            Position.CheckIfPositionIsValid(position);

            int arrRow = this.GetArrayRow(position.Row);
            int arrCol = this.GetArrayCol(position.Col);
            this.board[arrRow, arrCol] = figure;
        }
 private void AddPawnsToBoardRow(IPlayer player, IBoard board, int chessRow)
 {
     for (int i = 0; i < BoardTotalRowsAndCols; i++)
     {
         var pawn = new Pawn(player.Color);
         player.AddFigure(pawn);
         var position = new Position(chessRow, (char)(i + 'a'));
         board.AddFigure(pawn, position);
     }
 }
        public void Test_AddFigureWhitValidData()
        {
            Board testBoard = new Board();
            Position position = new Position(5, 'a');
            Pawn testPawn = new Pawn(ChessColor.White);

            testBoard.AddFigure(testPawn, position);

            Assert.AreSame(testPawn, testBoard.GetFigureAtPosition(position));
        }
Esempio n. 10
0
        public void MoveFigureAtPosition(IFigure figure, Position from, Position to)
        {
            int arrFromRow = this.GetArrayRow(from.Row);
            int arrFromCol = this.GetArrayCol(from.Col);
            this.board[arrFromRow, arrFromCol] = null;

            int arrToRow = this.GetArrayRow(to.Row);
            int arrToCol = this.GetArrayCol(to.Col);
            this.board[arrToRow, arrToCol] = figure;
        }
        public void Test_GetFigureAtPositionWhitValidPosition()
        {
            Board testBoard = new Board();
            Position position = new Position(8, 'c');
            Bishop testBishop = new Bishop(ChessColor.White);

            testBoard.AddFigure(testBishop, position);

            Assert.AreSame(testBishop, testBoard.GetFigureAtPosition(position));
        }
 private void AddArmyToBoardRow(IPlayer player, IBoard board, int chessRow)
 {
     for (int i = 0; i < BoardTotalRowsAndCols; i++)
     {
         var figureType = this.figureTypes[i];
         var figureInstance = (IFigure)Activator.CreateInstance(figureType, player.Color);
         player.AddFigure(figureInstance);
         var position = new Position(chessRow, (char)(i + 'a'));
         board.AddFigure(figureInstance, position);
     }
 }
Esempio n. 13
0
 private void DownChecker(IBoard board, Position from, Position to)
 {
     for (int i = from.Row; i > to.Row + 1; i--)
     {
         Position curentPosition = new Position(i - 1, from.Col);
         var figureAtPosition = board.GetFigureAtPosition(curentPosition);
         if (figureAtPosition != null)
         {
             throw new InvalidOperationException("Rook cannot move this way!");
         }
     }
 }
Esempio n. 14
0
        public static void CheckIfPositionIsValid(Position position)
        {
            if (position.Row < GlobalConstants.MinimumRowOnBoard || position.Row > GlobalConstants.MaximumRowOnBoard)
            {
                throw new IndexOutOfRangeException("Selected row position on the board is not valid!");
            }

            if (position.Col < GlobalConstants.MinimumColOnBoard || position.Col > GlobalConstants.MaximumColOnBoard)
            {
                throw new IndexOutOfRangeException("Selected column position on the board is not valid!");
            }
        }
Esempio n. 15
0
 private void RightChecker(IBoard board, Position from, Position to)
 {
     var currentCol = from.Col + 1;
     for (int i = from.Col; i < to.Col - 1; i++)
     {
         Position curentPosition = new Position(from.Row, (char)currentCol);
         var figureAtPosition = board.GetFigureAtPosition(curentPosition);
         if (figureAtPosition != null)
         {
             throw new InvalidOperationException("Rook cannot move this way!");
         }
         currentCol++;
     }
 }
 private void DownRightChecker(IBoard board, Position from, Position to)
 {
     var fromRow = from.Row;
     var fromCol = from.Col;
     var currentRow = fromRow;
     var currentCol = fromCol;
     while (true)
     {
         currentRow--;
         currentCol++;
         if (currentRow == to.Row && currentCol == to.Col)
         {
             return;
         }
         Position curentPosition = new Position(currentRow, currentCol);
         var figureAtPosition = board.GetFigureAtPosition(curentPosition);
         if (figureAtPosition != null)
         {
             throw new InvalidOperationException("Bishop cannot move this way!");
         }
     }
 }
 private void CheckIfPlayerOwnsFigure(IPlayer player, IFigure figure, Position from)
 {
     if (figure == null)
     {
         throw new InvalidOperationException(string.Format("Position {0}{1} is empty!", from.Col, from.Row));
     }
     if (figure.Color != player.Color)
     {
         throw new InvalidOperationException(string.Format("Figure at {0}{1} is not yiurs!", from.Col, from.Row));
     }
 }
Esempio n. 18
0
 public IFigure GetFigureAtPosition(Position position)
 {
     int arrRow = this.GetArrayRow(position.Row);
     int arrCol = this.GetArrayCol(position.Col);
     return this.board[arrRow, arrCol];
 }
Esempio n. 19
0
        private bool CheckOtherFigureIfValid(IBoard board, Position to, ChessColor color)
        {
            var otherFigure = board.GetFigureAtPosition(to);
            if (otherFigure != null && otherFigure.Color == color)
            {
                return true;
            }

            return false;
        }
Esempio n. 20
0
 private bool CheckDiagonalMove(Position from, Position to)
 {
     return from.Col + 1 == to.Col || from.Col - 1 == to.Col;
 }
        public void Test_RemoveFigureWhitValidЕmptyPosition()
        {
            Board testBoard = new Board();
            Position position = new Position(8, 'c');

            testBoard.RemoveFigure(position);
        }
 private void TopChecker(IBoard board, Position from, Position to)
 {
     for (int i = from.Row; i < to.Row - 1; i++)
     {
         Position curentPosition = new Position(i + 1, from.Col);
         var figureAtPosition = board.GetFigureAtPosition(curentPosition);
         if (figureAtPosition != null)
         {
             throw new InvalidOperationException("Queen cannot move this way!");
         }
     }
 }
        public void Test_MoveFigureAtPositionWhitInvalidFromPosition()
        {
            Board testBoard = new Board();
            Position fromPosition = new Position(2, 'a');
            Position invalidFromPosition = new Position(0, '1');
            Position toPosition = new Position(4, 'a');
            Pawn testPawn = new Pawn(ChessColor.White);

            testBoard.AddFigure(testPawn, fromPosition);

            testBoard.MoveFigureAtPosition(testPawn, invalidFromPosition, toPosition);
        }
 private void CheckIfToPositionIsEmpty(IFigure figure, Position to)
 {
     var figureAtPosition = this.board.GetFigureAtPosition(to);
     if (figureAtPosition != null && figureAtPosition.Color == figure.Color)
     {
         throw new InvalidOperationException(string.Format("You already have a figure at {0}{1}!", to.Col, to.Row));
     }
 }
 public void Test_CreatePositionWhitInvalidData()
 {
     int chessRow = 12;
     char chessCol = 'k';
     Position testedPosition = new Position(chessRow, chessCol);
 }
        public void Test_MoveFigureAtPositionWhitValidData()
        {
            Board testBoard = new Board();
            Position fromPosition = new Position(2, 'a');
            Position toPosition = new Position(4, 'a');
            Pawn testPawn = new Pawn(ChessColor.White);

            testBoard.AddFigure(testPawn, fromPosition);

            testBoard.MoveFigureAtPosition(testPawn, fromPosition, toPosition);

            bool result = (testPawn == testBoard.GetFigureAtPosition(toPosition)) &&
                (testBoard.GetFigureAtPosition(fromPosition) == null);

            Assert.IsTrue(result);
        }
 public void Test_MethodCheckIfPositionIsValidWhitValidData()
 {
     Position testedPosition = new Position(6, 'h');
     Position.CheckIfPositionIsValid(testedPosition);
 }
        public void Test_RemoveFigureWhitInvalidPosition()
        {
            Board testBoard = new Board();
            Position position = new Position(14, '0');

            testBoard.RemoveFigure(position);
        }
Esempio n. 29
0
 public static Position FromChessCoordinates(int chessRow, char chessCol)
 {
     var newPosition = new Position(chessRow, chessCol);
     Position.CheckIfPositionIsValid(newPosition);
     return newPosition;
 }
        public void Test_RemoveFigureWhitValidPosition()
        {
            Board testBoard = new Board();
            Position position = new Position(8, 'c');
            Bishop testBishop = new Bishop(ChessColor.White);

            testBoard.AddFigure(testBishop, position);

            testBoard.RemoveFigure(position);

            Assert.IsNull(testBoard.GetFigureAtPosition(position));
        }