Пример #1
0
        public void EmptyCell(ChessBoardPosition chessBoardPosition)
        {
            var cell = new ChessBoardCell
            {
                Entity     = null,
                IsOccupied = false,
            };

            SetCell(chessBoardPosition, cell);
        }
Пример #2
0
        public ChessBoardPosition CalculatePosition(ChessBoardPosition currentPosition, int x, int y, bool ignoreOccupacy = false)
        {
            var newPosition = new ChessBoardPosition
            {
                CurrentRow    = currentPosition.CurrentRow - x,
                CurrentColumn = currentPosition.CurrentColumn - y,
            };

            if ((newPosition.CurrentRow > -1 && newPosition.CurrentRow < 8) &&
                (newPosition.CurrentColumn > -1 && newPosition.CurrentColumn < 8))
            {
                ChessBoardCell cell = GetCell(newPosition);
                if (cell.IsOccupied && !ignoreOccupacy)
                {
                    return(null);
                }

                return(newPosition);
            }

            return(null);
        }
Пример #3
0
 public ChessBoardCell GetCell(ChessBoardPosition chessBoardPosition)
 {
     return(ChessBoardCells[chessBoardPosition.CurrentRow, chessBoardPosition.CurrentColumn]);
 }
Пример #4
0
 public void SetCell(ChessBoardPosition chessBoardPosition, ChessBoardCell cell)
 {
     ChessBoardCells[chessBoardPosition.CurrentRow, chessBoardPosition.CurrentColumn] = cell;
 }
Пример #5
0
        public ChessBoardPosition ParseChessBoardCellPosition(string line)
        {
            int column = -1;

            switch (line[0])
            {
            case 'A':
                column = 0;
                break;

            case 'B':
                column = 1;
                break;

            case 'C':
                column = 2;
                break;

            case 'D':
                column = 3;
                break;

            case 'E':
                column = 4;
                break;

            case 'F':
                column = 5;
                break;

            case 'G':
                column = 6;
                break;

            case 'H':
                column = 7;
                break;

            default:
                column = -1;
                Console.WriteLine("Invalid chess board column.");
                break;
            }

            if (column < 0)
            {
                return(null);
            }

            int  inputRow;
            bool validRow = Int32.TryParse(line[1].ToString(), out inputRow);

            int row = -1;

            if (validRow)
            {
                if (inputRow > 0 && inputRow < 9)
                {
                    row = Rows - inputRow;
                }
            }

            if (row < 0)
            {
                return(null);
            }

            var chessBoardPosition = new ChessBoardPosition
            {
                CurrentRow    = row,
                CurrentColumn = column,
            };

            return(chessBoardPosition);
        }