public IFigure GetFigureAtPosition(Position position) { int arrRow = this.GetArrayRow(position.Row); int arrCol = this.GetArrayCol(position.Col); return this.board[arrRow, arrCol]; }
public static Position FromChessCoordinates(int chessRow, char chessCol) { var newPosition = new Position(chessRow, chessCol); ChechIfValid(newPosition); return newPosition; }
public void RemoveFigure(Position position) { Position.ChechIfValid(position); int arrRow = this.GetArrayRow(position.Row); int arrCol = this.GetArrayCol(position.Col); this.board[arrRow, arrCol] = null; }
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 AddFigure(IFigure figure, Position position) { ObjectValidator.CheckIfObjectIsNull(figure, GlobalErrorMessages.NullFigureErrorMessage); Position.ChechIfValid(position); int arrRow = this.GetArrayRow(position.Row); int arrCol = this.GetArrayCol(position.Col); this.board[arrRow, arrCol] = figure; }
private bool CheckOtherFigureIfValid(IBoard board, Position to, ChessColor color) { var otherFigure = board.GetFigureAtPosition(to); if (otherFigure != null && otherFigure.Color == color) { return false; } return true; }
private void AddPawnsToBoardRow(IPlayer player, IBoard board, int chessRow) { for (int i = 0; i < StandartGameTotalCols; i++) { var pawn = new Pawn(player.Color); player.AddFigure(pawn); var position = new Position(chessRow, (char)(i + 'a')); board.AddFigure(pawn, position); } }
private void AddArmyToBoardRow(IPlayer player, IBoard board, int chessRow) { for (int i = 0; i < StandartGameTotalCols; 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); } }
public static void ChechIfValid(Position position) { if (position.Row < GlobalConstants.MinimumRowValueOnBoard || position.Row > GlobalConstants.MaximumRowValueOnBoard) { throw new IndexOutOfRangeException("Selected row position is not valid"); } if (position.Col < GlobalConstants.MinimumColValueOnBoard || position.Col > GlobalConstants.MaximumColValueOnBoard) { throw new IndexOutOfRangeException("Selected col position is not valid"); } }
private bool CheckDiagonalMove(Position from, Position to) { return (from.Col + 1 == to.Col || from.Col - 1 == to.Col); }