public void RenderBoard(IBoard board) { this.PrintHorizontalNumbers(); for (int row = 0; row < board.NumberOfRows; row++) { Console.Write(row + "| "); for (int column = 0; column < board.NumberOfColumns; column++) { Position position = new Position(row, column); var figure = board.GetFigureAtPosition(position); if (figure != null) { Console.Write(figure.DisplayName + " "); } else { this.PrintCell(position); } } Console.Write("|"); Console.WriteLine(); } this.PrintHorizontalLines(); }
public override Move Move(string command,IBoard board) { int[] deltaRed = { -1, +1, +1, -1 }; //UR, DR, DL, UL int[] deltaColona = { +1, +1, -1, -1 }; int indexOfChange = -1; if (command.Length != 3) { //TODO:change the exception to custom exception throw new ArgumentOutOfRangeException("The command should contain three symbols"); } var oldPosition = board.GetFigurePosition(this.Figures[0]); switch (command) { case "kur": { indexOfChange = 0; } break; case "kdr": { indexOfChange = 1; } break; case "kdl": { indexOfChange = 2; } break; case "kul": { indexOfChange = 3; } break; default: //TODO:change the exception to custom exception throw new ArgumentOutOfRangeException("The command is not correct"); } int newRow = oldPosition.Row + deltaRed[indexOfChange]; int newColumn = oldPosition.Col + deltaColona[indexOfChange]; var newPosition = new Position(newRow, newColumn); //Position.CheckIfValid(newPosition, GlobalErrorMessages.PositionNotValidMessage); // this.Figures[0].Position = newPosition; return new Move(oldPosition, newPosition); }
public void CheckIfTheAddFigureMethodThrowsCorrectlyNullReferenceExeption() { var board = new Board(); var position = new Position(-1, -1); IFigure figure = new King(FigureSign.K); board.AddFigure(figure, position); }
public void CheckIfAddNullFigureThrowsException() { var board = new Board(); var position = new Position(6, 6); IFigure figure = null; board.AddFigure(figure, position); }
public static void CheckIfFigureOnTheWay(Position position, IBoard board, string message) { if (board.GetFigureAtPosition(position) != null) { throw new ArgumentException(message); } }
public override Move Move(string command,IBoard board) { int[] deltaRed = { -1, +1, +1, -1 }; //UR, DR, DL, UL int[] deltaColona = { +1, +1, -1, -1 }; int indexOfChange = -1; if (command.Length != 3) { //TODO:Change the exception to custom exception throw new ArgumentOutOfRangeException("The command should contain three symbols"); } switch (command) { case "adr": case "bdr": case "cdr": case "ddr": { indexOfChange = 1; } break; case "adl": case "bdl": case "cdl": case "ddl": { indexOfChange = 2; } break; default: //TODO:change the exception to custom exception throw new ArgumentOutOfRangeException("The command is not correct"); } int pawnIndex = -1; switch (command[0]) { case 'a': case 'A': { pawnIndex = 0; } break; case 'b': case 'B': { pawnIndex = 1; } break; case 'c': case 'C': { pawnIndex = 2; } break; case 'd': case 'D': { pawnIndex = 3; } break; } var fig = this.Figures; var oldPosition = board.GetFigurePosition(this.Figures[pawnIndex]); int pawnNewRow = oldPosition.Row + deltaRed[indexOfChange]; int pawnNewColum = oldPosition.Col + deltaColona[indexOfChange]; var newPosition = new Position(pawnNewRow, pawnNewColum); //Position.CheckIfValid(newPosition, GlobalErrorMessages.PositionNotValidMessage); // this.Figures[pawnIndex].Position = newPosition; return new Move(oldPosition, newPosition); }
public void CheckIfMoveConstructorSetsToRowCorrectly() { Position positionFrom = new Position(1, 3); Position positionTo = new Position(2, 4); Move move = new Move(positionFrom, positionTo); int expectedPositionRow = 2; Assert.AreEqual(positionTo.Row, expectedPositionRow); }
public void AddFigure(IFigure figure,Position position) { Validator.CheckIfObjectIsNull(figure, GlobalErrorMessages.NullFigureErrorMessage); Validator.CheckIfPositionValid(position,GlobalErrorMessages.PositionNotValidMessage); this.board[position.Row, position.Col] = figure; this.figurePositionsOnBoard[figure] = position; }
public void CheckIfAFigureIsAddedCorrectlyToTheBoard() { var board = new Board(); var position = new Position(1, 1); var figure = new KingFigure(); board.AddFigure(figure, position); Assert.AreEqual(figure, board.GetFigureAtPosition(position)); }
public void CheckfAddFigureMethodThrowsWhenPositionIsNotValid() { var board = new Board(); var position = new Position(9, 9); IFigure king = new KingFigure(); board.AddFigure(king, position); }
public void CheckIfCheckFigureOnTheWayWorksProperlyWhenFigureIsOnTheWay() { IFigure king = new KingFigure("K"); var position = new Position(Constants.InitialKingRow, Constants.InitialKingColumn); var board = new Board(); board.AddFigure(king, position); Validator.CheckIfFigureOnTheWay(position, board); }
public void CheckIfCheckFigureOnTheWayWorksProperlyWhenFigureIsOnTheWay() { var board = new Board(); var figure = new KingFigure(); var position = new Position(1, 1); board.AddFigure(figure, position); Validator.CheckIfFigureOnTheWay(position, board, "Figure on the way"); }
public void CheckIfTheAddFigureMethodThrowsCorrectlyIndexOutOfRangeException() { var board = new Board(); var position = new Position(9, 9); var figureSign = FigureSign.K; var figure = new King(figureSign); board.AddFigure(figure, position); }
public IPosition GenerateNewPosition(int direction) { int[] deltaRow = { -1, +1, +1, -1 }; ////UR, DR, DL, UL int[] deltaCol = { +1, +1, -1, -1 }; int newRow = this.Row + deltaRow[direction]; int newColumn = this.Col + deltaCol[direction]; var newPosition = new Position(newRow, newColumn); return newPosition; }
public void CheckIfAddFigureWorksCorrectlyWithCorrectFigureAndCorrectPosition() { var board = new Board(); var position = new Position(3, 7); IFigure king = new KingFigure(); board.AddFigure(king, position); Assert.AreSame(king, board.GetFigureAtPosition(position)); }
public void CheckIfCheckFigureOnTheWayWorksProperlyWhenNoFigureOnTheWay() { IFigure king = new KingFigure("K"); var board = new Board(); var position = new Position(1, 1); board.AddFigure(king, position); var expectedPosition = new Position(2, 2); Validator.CheckIfFigureOnTheWay(expectedPosition, board); }
public void CheckIfGetFigureAtPositionReturnsTheCorrectFigure() { var board = new Board(); var position = new Position(1, 1); var figure = new KingFigure(); board.AddFigure(figure, position); Assert.AreEqual(figure, board.GetFigureAtPosition(position)); }
private IPosition GenerateNewPosition(IPosition oldPosition, int direction) { int[] deltaRow = { -1, +1, +1, -1 }; ////UR, DR, DL, UL int[] deltaCol = { +1, +1, -1, -1 }; int newRow = oldPosition.Row + deltaRow[direction]; int newColumn = oldPosition.Col + deltaCol[direction]; var newPosition = new Position(newRow, newColumn); return newPosition; }
private void PrintCell(Position position) { if ((position.Row + position.Col) % 2 != 0) { Console.Write(EmptyWhiteCell + " "); } else { Console.Write(EmptyBlackCell + " "); } }
public void CheckIfRemoveFigureRemovesTheFigure() { var board = new Board(); var position = new Position(1, 1); var figureSign = FigureSign.K; var figure = new King(figureSign); board.AddFigure(figure, position); board.RemoveFigure(figure, position); Assert.AreNotEqual(figure, board.GetFigureAtPosition(position)); }
public void CheckIfAFigureIsAddedCorrectlyToTheBoard() { var position = new Position(1, 1); Mock<IFigure> mockedFigure = new Mock<IFigure>(); mockedFigure.Setup(r => r.DisplaySign).Returns("K"); var board = new Board(); board.AddFigure(mockedFigure.Object, position); Assert.AreSame(mockedFigure.Object, board.GetFigureAtPosition(position)); }
public void CheckIfAddFigureMethodThrowsWhenPositionIsNotValid() { var position = new Position(Constants.MaximumRowValueOnBoard + 2, Constants.MaximumRowValueOnBoard + 2); Mock<IFigure> mockedFigure = new Mock<IFigure>(); mockedFigure.Setup(r => r.DisplaySign).Returns("K"); var king = mockedFigure.Object; var board = new Board(); board.AddFigure(king, position); }
private bool CheckIfPositionIsEmpty(Position position, IBoard board) { if (this.CheckIfInsideTheBoard(position)) { if (board.GetFigureAtPosition(position) == null) { return true; } } return false; }
private bool CheckIfInsideTheBoard(Position position) { try { Validator.CheckIfPositionValid(position, GlobalErrorMessages.PositionNotValidMessage); return true; } catch (IndexOutOfRangeException) { return false; } }
private bool CheckIfInsideTheBoard(Position position) { try { Validator.CheckIfPositionValid(position); return true; } catch (InvalidPositionException) { return false; } }
public void CheckIfAddFigureWorksCorrectlyWithCorrectFigureAndCorrectPosition() { var board = new Board(); var position = new Position(Constants.MaximumRowValueOnBoard / 2, Constants.MaximumColumnValueOnBoard / 2); Mock<IFigure> mockedFigure = new Mock<IFigure>(); mockedFigure.Setup(r => r.DisplaySign).Returns("K"); var king = mockedFigure.Object; board.AddFigure(king, position); Assert.AreSame(king, board.GetFigureAtPosition(position)); }
public static void CheckIfPositionValid(Position position, string errorMessage) { if (position.Row < Constants.MinimumRowValueOnBoard || position.Row > Constants.MaximumRowValueOnBoard) { throw new IndexOutOfRangeException(errorMessage); } if (position.Col < Constants.MinimumColumnValueOnBoard || position.Col > Constants.MaximumColumnValueOnBoard) { throw new IndexOutOfRangeException(errorMessage); } }
public void CheckIfGetFigureAtPositionReturnsTheCorrectFigure() { var position = new Position(1, 1); Mock<IFigure> mockedFigure = new Mock<IFigure>(); mockedFigure.Setup(r => r.DisplaySign).Returns("K"); var figure = mockedFigure.Object; var board = new Board(); board.AddFigure(figure, position); Assert.AreSame(figure, board.GetFigureAtPosition(position)); }
public void CheckIfAnExceptionIsThrownWhenTheCommandIsThreeSymbolsLongButStillNotCorrect() { var player = new Player("Serafim"); var king = new KingFigure(); player.AddFigure(king); var board = new Board(); var position = new Position(Constants.InitialKingRow, Constants.InitialKingColumn); board.AddFigure(king, position); var commandFactory = new CommandFactory(); var commandContext = new CommandContext(new BoardMemory(), board, player); player.ExecuteCommand(commandContext, "aaa"); }
public void CheckIfAnExceptionIsThrownWhenTheCommandIsNotExactlyThreeSymbolsAndThePlayerIsPawn() { var player = new Player("Serafim"); var pawn = new PawnAFigure(); player.AddFigure(pawn); var board = new Board(); var position = new Position(Constants.InitialKingRow, Constants.InitialKingColumn); board.AddFigure(pawn, position); var commandFactory = new CommandFactory(); var commandContext = new CommandContext(new BoardMemory(), board, player); player.ExecuteCommand(commandContext, "aaaa"); }