Beispiel #1
0
void MainWindow::addRandomDir(CellList& list)
{
  Cell* cell = list.first();
  Cell* ucell = uCell(cell);
  Cell* rcell = rCell(cell);
  Cell* dcell = dCell(cell);
  Cell* lcell = lCell(cell);

  typedef QMap<Cell::Dirs, Cell*> CellMap;
  CellMap freecells;

  if(ucell && ucell->dirs() == Cell::Free)
    freecells[Cell::U] = ucell;
  if(rcell && rcell->dirs() == Cell::Free)
    freecells[Cell::R] = rcell;
  if(dcell && dcell->dirs() == Cell::Free)
    freecells[Cell::D] = dcell;
  if(lcell && lcell->dirs() == Cell::Free)
    freecells[Cell::L] = lcell;
  if(freecells.isEmpty())
    return;

  CellMap::ConstIterator it = freecells.constBegin();
  for(int i = rand() % freecells.count(); i > 0; --i)
    ++it;

  cell->setDirs(Cell::Dirs(cell->dirs() | it.key()));
  it.value()->setDirs(contrdirs[it.key()]);
  list.append(it.value());
}
Beispiel #2
0
SparseMap::SparseMap(const SparseMap &other)
{
  document_ = other.document_;
  
  const CellMap &cells = other.cells();
  for (CellMap::ConstIterator it = cells.begin(); it != cells.end(); ++it) {
    cells_[it.key()] = new Cell(*it.value());
  }
}