Beispiel #1
0
 public Board()
 {
     for (var i = 0; i < TOTAL_CELL_COUNT; i++)
     {
         _boardCells[i] = new BoardCell();
     }
     for (var i = 0; i < TOTAL_CELL_COUNT; i++)
     {
         InitializeBoardCell(_boardCells[i], i);
     }
 }
Beispiel #2
0
        private void FindOccupiedBoardCells(List<BoardCell> occupiedCells, PieceCell pieceCell, BoardCell boardCell)
        {
            if (pieceCell != null && boardCell != null && !pieceCell.IsProcessed)
            {
                occupiedCells.Add(boardCell);

                /* Neighbouring cells can form loops, which would lead to an
                infinite recursion. Avoid this by marking the processed
                cells. */

                pieceCell.IsProcessed = true;
                // Repeat for each neighbour of the piece cell
                for (var i = 0; i < Cell.NUMBER_OF_SIDES; i++)
                {
                    FindOccupiedBoardCells(occupiedCells,
                        (PieceCell) pieceCell.GetNeighbor((CellSide) i),
                        (BoardCell) boardCell.GetNeighbor((CellSide) i));
                }
            }
        }
Beispiel #3
0
        private void FindOccupiedBoardCells(List <BoardCell> occupiedCells, PieceCell pieceCell, BoardCell boardCell)
        {
            if (pieceCell != null && boardCell != null && !pieceCell.IsProcessed)
            {
                occupiedCells.Add(boardCell);

                /* Neighbouring cells can form loops, which would lead to an
                 * infinite recursion. Avoid this by marking the processed
                 * cells. */

                pieceCell.IsProcessed = true;
                // Repeat for each neighbour of the piece cell
                for (var i = 0; i < Cell.NUMBER_OF_SIDES; i++)
                {
                    FindOccupiedBoardCells(occupiedCells,
                                           (PieceCell)pieceCell.GetNeighbor((CellSide)i),
                                           (BoardCell)boardCell.GetNeighbor((CellSide)i));
                }
            }
        }
Beispiel #4
0
        /**
         * Initialize the neighbours of the given boardCell at the given
         * index on the board
         */
        private void InitializeBoardCell(BoardCell boardCell, int index)
        {
            // define the row of the cell.
            var row = index / CELLS_IN_ROW_COUNT;
            // check if the cell is last or first in the row.
            var isFirst = false;
            var isLast  = false;

            if (index % CELLS_IN_ROW_COUNT == 0)
            {
                isFirst = true;
            }
            if ((index + 1) % CELLS_IN_ROW_COUNT == 0)
            {
                isLast = true;
            }
            if (row % 2 == 0)
            {
                // Even rows
                if (row != 0)
                {
                    // Northern neighbours
                    if (!isFirst)
                    {
                        boardCell.SetNeighbor(CellSide.NORTH_WEST, _boardCells[index - 6]);
                    }
                    boardCell.SetNeighbor(CellSide.NORTH_EAST, _boardCells[index - 5]);
                }
                if (row != ((TOTAL_CELL_COUNT / CELLS_IN_ROW_COUNT) - 1))
                {
                    // Southern neighbours
                    if (!isFirst)
                    {
                        boardCell.SetNeighbor(CellSide.SOUTH_WEST, _boardCells[index + 4]);
                    }
                    boardCell.SetNeighbor(CellSide.SOUTH_EAST, _boardCells[index + 5]);
                }
            }
            else
            {
                // Uneven rows
                // Northern neighbours
                if (!isLast)
                {
                    boardCell.SetNeighbor(CellSide.NORTH_EAST, _boardCells[index - 4]);
                }
                boardCell.SetNeighbor(CellSide.NORTH_WEST, _boardCells[index - 5]);
                // Southern neighbours
                if (row != ((TOTAL_CELL_COUNT / CELLS_IN_ROW_COUNT) - 1))
                {
                    if (!isLast)
                    {
                        boardCell.SetNeighbor(CellSide.SOUTH_EAST, _boardCells[index + (CELLS_IN_ROW_COUNT + 1)]);
                    }
                    boardCell.SetNeighbor(CellSide.SOUTH_WEST, _boardCells[index + CELLS_IN_ROW_COUNT]);
                }
            }

            // Set the east and west neighbours
            if (!isFirst)
            {
                boardCell.SetNeighbor(CellSide.WEST, _boardCells[index - 1]);
            }
            if (!isLast)
            {
                boardCell.SetNeighbor(CellSide.EAST, _boardCells[index + 1]);
            }
        }
Beispiel #5
0
        /**
        * Initialize the neighbours of the given boardCell at the given
        * index on the board
        */
        private void InitializeBoardCell(BoardCell boardCell, int index)
        {
            // define the row of the cell.
            var row = index/CELLS_IN_ROW_COUNT;
            // check if the cell is last or first in the row.
            var isFirst = false;
            var isLast = false;
            if (index%CELLS_IN_ROW_COUNT == 0) isFirst = true;
            if ((index + 1)%CELLS_IN_ROW_COUNT == 0) isLast = true;
            if (row%2 == 0)
            {
                // Even rows
                if (row != 0)
                {
                    // Northern neighbours
                    if (!isFirst)
                    {
                        boardCell.SetNeighbor(CellSide.NORTH_WEST, _boardCells[index - 6]);
                    }
                    boardCell.SetNeighbor(CellSide.NORTH_EAST, _boardCells[index - 5]);
                }
                if (row != ((TOTAL_CELL_COUNT/CELLS_IN_ROW_COUNT) - 1))
                {
                    // Southern neighbours
                    if (!isFirst)
                    {
                        boardCell.SetNeighbor(CellSide.SOUTH_WEST, _boardCells[index + 4]);
                    }
                    boardCell.SetNeighbor(CellSide.SOUTH_EAST, _boardCells[index + 5]);
                }
            }
            else
            {
                // Uneven rows
                // Northern neighbours
                if (!isLast)
                {
                    boardCell.SetNeighbor(CellSide.NORTH_EAST, _boardCells[index - 4]);
                }
                boardCell.SetNeighbor(CellSide.NORTH_WEST, _boardCells[index - 5]);
                // Southern neighbours
                if (row != ((TOTAL_CELL_COUNT/CELLS_IN_ROW_COUNT) - 1))
                {
                    if (!isLast)
                    {
                        boardCell.SetNeighbor(CellSide.SOUTH_EAST, _boardCells[index + (CELLS_IN_ROW_COUNT + 1)]);
                    }
                    boardCell.SetNeighbor(CellSide.SOUTH_WEST, _boardCells[index + CELLS_IN_ROW_COUNT]);
                }
            }

            // Set the east and west neighbours
            if (!isFirst)
            {
                boardCell.SetNeighbor(CellSide.WEST, _boardCells[index - 1]);
            }
            if (!isLast)
            {
                boardCell.SetNeighbor(CellSide.EAST, _boardCells[index + 1]);
            }
        }