Example #1
0
 /// <summary>
 /// Returns a reference to the cell at location [row,col]. If not in bounds, throws IndexOutOfRangeException
 /// </summary>
 /// <param name="row"></param>
 /// <param name="col"></param>
 /// <returns></returns>
 public AbstractCell GetCell(int row, int col)
 {
     if (row >= _spreadsheet.GetLowerBound(_row_dim) && row <= _spreadsheet.GetUpperBound(_row_dim) &&
         col >= _spreadsheet.GetLowerBound(_col_dim) && col <= _spreadsheet.GetUpperBound(_col_dim))
     {
         return(_spreadsheet[row, col]);
     }
     else
     {
         throw new IndexOutOfRangeException();
     }
 }
Example #2
0
        public static void Print(Cell[,] cells, CellPrintFunction cellPrintFn)
        {
            int u1 = cells.GetUpperBound(0);
            int u2 = cells.GetUpperBound(1);
            int l1 = cells.GetLowerBound(0);
            int l2 = cells.GetLowerBound(1);

            string[,] printArray = new string[u1 + 2, u2 + 2];
            setPrintContent(cells, cellPrintFn, u1, u2, l1, l2, printArray);
            setPrintRowHeading(printArray);
            setPrintColHeading(printArray);
            printIt(printArray);
        }
Example #3
0
        public bool generation()
        {
            counter++;
            if (counter % 5 == 0)
            {
                color_adapters.increment();
            }

            CellVisitor touchvisitor = new TouchCellVisitor(this);
            Cell        cell;
            int         cells_changed = 0;

            for (int x = array.GetLowerBound(0); x < array.GetUpperBound(0); x++)
            {
                for (int y = array.GetLowerBound(1); y < array.GetUpperBound(1); y++)
                {
                    cell = array[x, y];
                    if (cell != null)
                    {
                        if (touchvisitor.visit(cell))
                        {
                            cells_changed++;
                        }
                    }
                }
            }
            for (int x = array.GetLowerBound(0); x < array.GetUpperBound(0); x++)
            {
                for (int y = array.GetLowerBound(1); y < array.GetUpperBound(1); y++)
                {
                    cell = array[x, y];
                    if (cell != null)
                    {
                        cell.move_to_next();
                    }
                }
            }
            return(cells_changed > 10);
        }
Example #4
0
    private List <Cell> GetValidCellHelper(int x, int y)
    {
        List <Cell> validCells = new List <Cell>();
        List <int>  cellOffset = new List <int>()
        {
            -1, 0, 1, -1, 0, 1, -1, 0, 1
        };

        // Visual of what offsets to test:
        //
        //              COLUMN
        //     +-------+-------+-------+
        //     | -1,+1 | +0,+1 | +1,+1 |
        //     +-------+-------+-------+
        // ROW | -1,+0 |  Cell | +1,+0 |
        //     +-------+-------+-------+
        //     | -1,-1 | +0,-1 | +1,-1 |
        //     +-------+-------+-------+
        //

        int column = -1;
        int row    = 0;

        for (int i = 0; i < cellOffset.Count; i++)
        {
            if (row >= 3)
            {
                row = 0;
                column++;
            }

            // If tested cell is off boundary
            if (x + column < cells.GetLowerBound(0) || y + cellOffset[i] < cells.GetLowerBound(1) || x + column > cells.GetUpperBound(0) || y + cellOffset[i] > cells.GetUpperBound(1))
            {
                //Debug.Log((x+column) + "," + (y+cellOffset[i]) + " doesn't exist.");
                row++;
                continue;
            }

            // If tested cell already contains card
            if (ContainsCard(cells[x + column, y + cellOffset[i]].transform))
            {
                //Debug.Log((x+column) + "," + (y+cellOffset[i]) + " doesn't contain a card.");
                row++;
                continue;
            }

            // If tested cell can flank opponent
            bool canFlank = CanFlankOpponent(x, y, x + column, y + cellOffset[i]);
            if (!canFlank)
            {
                row++;
                continue;
            }

            //Debug.Log((x+column) + "," + (y+cellOffset[i]) + " is valid.");
            validCells.Add(cells[x + column, y + cellOffset[i]]);
            row++;
        }

        return(validCells);
    }