Esempio n. 1
0
 public Cell <T> CellAt(PositionInGrid position)
 {
     if (position.IsOutOfBoundsForGridOfSize(size))
     {
         return(new Cell <T>(this, null, default(T)));
     }
     return(_data[position.ToScalarForGridOfSize(size)]);
 }
 void it_is_able_to_retrieved_cells_by_position_in_grid()
 {
     var position = new PositionInGrid(1, 2);
     var cell = _subject.CellAt(position);
     cell.value.should_be(6);
     cell.position.column.should_be(position.column);
     cell.position.row.should_be(position.row);
 }
 void it_is_able_to_retrieve_out_of_bounds_cells_by_position_in_grid()
 {
     var position = new PositionInGrid(1, 4);
     _subject.CellAt(position).value.should_be(default(int));
 }
 public Cell(IGrid <T> grid, PositionInGrid position, T value)
 {
     _grid         = grid;
     this.position = position;
     this.value    = value;
 }
Esempio n. 5
0
 public Grid(List <T> data)
 {
     _size = Convert.ToInt32(Math.Sqrt(data.Count));
     _data = data.Select((v, i) => new Cell <T>(this, PositionInGrid.FromScalarForGridOfSize(i, size), v)).ToList();
 }
 public void MarkCellDeadAt(PositionInGrid position)
 {
     _cells[position.ToScalarForGridOfSize(_size)] = false;
 }
 public void MarkCellAliveAt(PositionInGrid position)
 {
     _cells[position.ToScalarForGridOfSize(_size)] = true;
 }
 public void MarkCellAliveAt(PositionInGrid position)
 {
     _cells[position.ToScalarForGridOfSize(_size)] = true;
 }
 public void MarkCellDeadAt(PositionInGrid position)
 {
     _cells[position.ToScalarForGridOfSize(_size)] = false;
 }
 void before_each()
 {
     _subject = new PositionInGrid(2, 0);
 }