Esempio n. 1
0
bool Command::setFromString(const QString &inp_str)
{
    QString delim = ";";

    QString tmp(inp_str);
    if ( !tmp.contains(QRegExp("[0-7],[0-7]"+delim+"( |F|K|Q|R|B|P|Kn)"+delim+"[wb]"+delim+delim+"[0-7],[0-7]"+delim+"( |F|K|Q|R|B|P|Kn)"+delim+"[wb]\n")) )
        return false;

    tmp.remove("\n");

    QStringList line = tmp.split(delim+delim);

    QStringList b_info_list = line[0].split(delim);
    QStringList b_cell_list = b_info_list[0].split(",");
    b_cell_info_.cell_ = Cell(b_cell_list[0].toInt(), b_cell_list[1].toInt());
    b_cell_info_.ftype_ = b_info_list[1];

    QString b_color = b_info_list[2];
    if (b_color == "w")
        b_cell_info_.fcolor_ = WHITE;
    else if(b_color == "b")
        b_cell_info_.fcolor_ = BLACK;
    else
        b_cell_info_.fcolor_ = NONE;

    QStringList e_info_list = line[1].split(delim);
    QStringList e_cell_list = e_info_list[0].split(",");
    e_cell_info_.cell_ = Cell(e_cell_list[0].toInt(), e_cell_list[1].toInt());
    e_cell_info_.ftype_ = e_info_list[1];

    QString e_color = e_info_list[2];
    if (e_color == "w")
        e_cell_info_.fcolor_ = WHITE;
    else if(e_color == "b")
        e_cell_info_.fcolor_ = BLACK;
    else
        e_cell_info_.fcolor_ = NONE;

    return true;
}
double GlobalPlanner::getRisk(Cell & cell) {
  double risk = explorePenalty;
  if (occProb.find(cell) != occProb.end()) {
    risk = octomap::probability(occProb[cell]);
  }
  Cell front = Cell(cell.x()+1, cell.y(), cell.z());
  Cell back = Cell(cell.x()-1, cell.y(), cell.z());
  Cell right = Cell(cell.x(), cell.y()+1, cell.z());
  Cell left = Cell(cell.x(), cell.y()-1, cell.z());
  Cell up = Cell(cell.x(), cell.y(), cell.z()+1);
  Cell down = Cell(cell.x(), cell.y(), cell.z()-1);
  if (occProb.find(front) != occProb.end()) {
    risk += octomap::probability(occProb[front]);
  }
  if (occProb.find(back) != occProb.end()) {
    risk += octomap::probability(occProb[back]);
  }
  if (occProb.find(right) != occProb.end()) {
    risk += octomap::probability(occProb[right]);
  }
  if (occProb.find(left) != occProb.end()) {
    risk += octomap::probability(occProb[left]);
  }
  if (occProb.find(up) != occProb.end()) {
    risk += octomap::probability(occProb[up]);
  }
  if (occProb.find(down) != occProb.end()) {
    risk += octomap::probability(occProb[down]);
  }
  double prior = heightPrior[floor(cell.z())];
  // ROS_INFO("risk: %f \t prior: %f \n", risk, prior);
  return risk * prior;
}
Esempio n. 3
0
 // Colored table
 void FancyTable(wxArrayString& header, wxArrayPtrVoid& data)
 {
   // Colors, line width and bold font
   SetFillColour(wxColour(255,0,0));
   SetTextColour(255);
   SetDrawColour(wxColour(128,0,0));
   SetLineWidth(.3);
   SetFont(wxT(""),wxT("B"));
   //Header
   double w[4] = {40,35,40,45};
   size_t i;
   for (i = 0; i < header.GetCount(); i++)
   {
     Cell(w[i],7,header[i],wxPDF_BORDER_FRAME, 0, wxPDF_ALIGN_CENTER, 1);
   }
   Ln();
   // Color and font restoration
   SetFillColour(wxColour(224,235,255));
   SetTextColour(0);
   SetFont(wxT(""));
   // Data
   int fill = 0;
   size_t j;
   for (j = 0; j < data.GetCount(); j++)
   {
     wxArrayString* row = (wxArrayString*) data[j];
     Cell(w[0],6,(*row)[0],wxPDF_BORDER_LEFT | wxPDF_BORDER_RIGHT,0,wxPDF_ALIGN_LEFT,fill);
     Cell(w[1],6,(*row)[1],wxPDF_BORDER_LEFT | wxPDF_BORDER_RIGHT,0,wxPDF_ALIGN_LEFT,fill);
     Cell(w[2],6,(*row)[2],wxPDF_BORDER_LEFT | wxPDF_BORDER_RIGHT,0,wxPDF_ALIGN_RIGHT,fill);
     Cell(w[3],6,(*row)[3],wxPDF_BORDER_LEFT | wxPDF_BORDER_RIGHT,0,wxPDF_ALIGN_RIGHT,fill);
     Ln();
     fill = 1 - fill;
   }
   Cell((w[0]+w[1]+w[2]+w[3]),0,wxT(""),wxPDF_BORDER_TOP);
 }
Esempio n. 4
0
 // Better table
 void ImprovedTable(wxArrayString& header,wxArrayPtrVoid& data)
 {
   // Column widths
   double w[4] = {40,35,40,45};
   // Header
   size_t i;
   for (i = 0; i <header.GetCount(); i++)
   {
     Cell(w[i],7,header[i],wxPDF_BORDER_FRAME,0,wxPDF_ALIGN_CENTER);
   }
   Ln();
   // Data
   size_t j;
   for (j = 0; j < data.GetCount(); j++)
   {
     wxArrayString* row = (wxArrayString*) data[j];
     Cell(w[0],6,(*row)[0],wxPDF_BORDER_LEFT | wxPDF_BORDER_RIGHT);
     Cell(w[1],6,(*row)[1],wxPDF_BORDER_LEFT | wxPDF_BORDER_RIGHT);
     Cell(w[2],6,(*row)[2],wxPDF_BORDER_LEFT | wxPDF_BORDER_RIGHT,0,wxPDF_ALIGN_RIGHT);
     Cell(w[3],6,(*row)[3],wxPDF_BORDER_LEFT | wxPDF_BORDER_RIGHT,0,wxPDF_ALIGN_RIGHT);
     Ln();
   }
   // Closure line
   Cell((w[0]+w[1]+w[2]+w[3]),0,wxS(""),wxPDF_BORDER_TOP);
 }
Esempio n. 5
0
void TileMap::set_cell(int p_x,int p_y,int p_tile,bool p_flip_x,bool p_flip_y,bool p_transpose) {

	PosKey pk(p_x,p_y);

	Map<PosKey,Cell>::Element *E=tile_map.find(pk);
	if (!E && p_tile==INVALID_CELL)
		return; //nothing to do

	PosKey qk(p_x/_get_quadrant_size(),p_y/_get_quadrant_size());
	if (p_tile==INVALID_CELL) {
		//erase existing
		tile_map.erase(pk);
		Map<PosKey,Quadrant>::Element *Q = quadrant_map.find(qk);
		ERR_FAIL_COND(!Q);
		Quadrant &q=Q->get();
		q.cells.erase(pk);
		if (q.cells.size()==0)
			_erase_quadrant(Q);
		else
			_make_quadrant_dirty(Q);

		return;
	}

	Map<PosKey,Quadrant>::Element *Q = quadrant_map.find(qk);

	if (!E) {
		E=tile_map.insert(pk,Cell());
		if (!Q) {
			Q=_create_quadrant(qk);
		}
		Quadrant &q=Q->get();
		q.cells.insert(pk);
	} else {
		ERR_FAIL_COND(!Q); // quadrant should exist...

		if (E->get().id==p_tile && E->get().flip_h==p_flip_x && E->get().flip_v==p_flip_y && E->get().transpose==p_transpose)
			return; //nothing changed

	}


	Cell &c = E->get();

	c.id=p_tile;
	c.flip_h=p_flip_x;
	c.flip_v=p_flip_y;
	c.transpose=p_transpose;

	_make_quadrant_dirty(Q);

}
Esempio n. 6
0
void Transport::UpdatePosition(float x, float y, float z, float o)
{
    bool newActive = GetMap()->IsGridLoaded(x, y);

    Relocate(x, y, z, o);

    UpdatePassengerPositions(_passengers);

    /* There are four possible scenarios that trigger loading/unloading passengers:
      1. transport moves from inactive to active grid
      2. the grid that transport is currently in becomes active
      3. transport moves from active to inactive grid
      4. the grid that transport is currently in unloads
    */
    if (_staticPassengers.empty() && newActive) // 1. and 2.
        LoadStaticPassengers();
    else if (!_staticPassengers.empty() && !newActive && Cell(x, y).DiffGrid(Cell(GetPositionX(), GetPositionY()))) // 3.
        UnloadStaticPassengers();
    else
        UpdatePassengerPositions(_staticPassengers);
    // 4. is handed by grid unload
}
CCMSDIntegrator::CCMSDIntegrator(void)
:
		resources((std::vector<IObjectPtr>&) Resource().objects()),
		cells((std::vector<IObjectPtr>&) Cell().objects()),
		parts((std::vector<IObjectPtr>&) Part().objects()),
		processplans((std::vector<IObjectPtr>&) ProcessPlan().objects()),
		jobs((std::vector<IObjectPtr>&) Job().objects()),
		distributions((std::vector<IObjectPtr>&) Distribution().objects()),
		calendars((std::vector<IObjectPtr>&) Calendar().objects()),
		layouts((std::vector<IObjectPtr>&) Layout().objects())

{
}
Esempio n. 8
0
TEST(Parser, correctParsCels) {


    int m(3), n(3);
    std::istringstream inp( "...\n"
                            ".*.\n"
                            ".**");

   std::vector<Cell> corr_cell = {
            Cell(0, 0, Status::DEAD), Cell(1, 0, Status::DEAD), Cell(2, 0, Status::DEAD),
            Cell(0, 1, Status::DEAD), Cell(1, 1, Status::LIVE), Cell(2, 1, Status::DEAD),
            Cell(0, 2, Status::DEAD), Cell(1, 2, Status::LIVE), Cell(2, 2, Status::LIVE)
    };

    Parser parser(inp);
std::vector<Cell> g_inp = parser.getGrid(m, n);

    EXPECT_EQ(g_inp, corr_cell);
}
Esempio n. 9
0
const list<Cell> Combo::getList() {
	int r, c;

	list<Cell> cells;

	switch (getState()) {
	case Combo::VERT:
		r = down()->row;
		c = down()->col;
		for (r; r <= up()->row; ++r) {
			cells.push_back(Cell(r, c));
		}
		break;

	case Combo::HORI:
		r = left()->row;
		c = left()->col;
		for (c; c <= right()->col; ++c) {
			cells.push_back(Cell(r, c));
		}
		break;

	case Combo::MULTI:
		r = left()->row;
		c = left()->col;
		for (c; c <= right()->col; ++c) {
			cells.push_back(Cell(r, c));
		}
		
		c = down()->col;
		r = down()->row;
		for (r; r <= up()->row; ++r) {
			cells.push_back(Cell(r, c));
		}
	}

	return cells;
}
Esempio n. 10
0
TileCell::TileCell(String const& rString, bool remoteFlag) {
    Strings const parts(rString, SEPARATOR);
    ASSERT(parts.Count() == 2); // TODO recovery

    String const first = parts.First();
    mTile = Tile(IndexType(first), remoteFlag);

    mSwapFlag = true;
    String const second = parts.Second();
    if (second != SWAP) {
        mCell = Cell(second);
        mSwapFlag = false;
    }
}
Esempio n. 11
0
void
TableLayout::addComponent(size_t col, size_t row, Component* component)
{
    if(row >= rowproperties.size())
        throw std::runtime_error("row out of range");
    if(col >= colproperties.size())
        throw std::runtime_error("col out of range");

    if(cells[row * colproperties.size() + col].childid >= 0)
        throw std::runtime_error("Already a component in this cell.");
    
    addChild(component);
    cells[row * colproperties.size() + col] = Cell(childs.size()-1);
}
Esempio n. 12
0
void DBNetworkIF::SetMagnitude ()

	{
	DBInt cellID;
	DBObjRecord *cellRec, *toCellRec;
	if (MagnitudeFLD == (DBObjTableField *) NULL)
		{
		MagnitudeFLD = new DBObjTableField (DBrNMagnitude,DBTableFieldInt,"%4d",sizeof (DBShort));
		CellTable->AddField (MagnitudeFLD);
		}
	for (cellID = 0;cellID < CellNum ();++cellID)
		{
		cellRec = Cell (cellID);
		MagnitudeFLD->Int (cellRec,(FromCellDirs (cellRec) == 0x0) ? 1 : 0);
		}
	for (cellID = 0;cellID < CellNum ();++cellID)
		{
		cellRec = Cell (cellID);
		DBPause ((CellNum () - cellRec->RowID ()) * 100 / CellNum ());
		if ((toCellRec = ToCell (cellRec)) != (DBObjRecord *) NULL)
			MagnitudeFLD->Int (toCellRec,MagnitudeFLD->Int (toCellRec) + MagnitudeFLD->Int (cellRec));
		}
	}
Esempio n. 13
0
void BuyerParser::getAdCampaign(std::vector<std::vector<float> >& v) {
  v.clear();
  Cell start_c('c',41);

  for( int b=0; b<N_BRANDS; b++ ) {
    v.push_back(std::vector<float>(N_TIME_INTERVALS));
    Cell c = Cell(start_c.first + b, start_c.second);

    for( int t=0; t<N_TIME_INTERVALS; t++ ) {
      v[b][t] = std::atof( getCell(c).c_str() );
      c.second++;
    }
  }
}
Esempio n. 14
0
inline
typename SlicedCartesian<ScalarParam,dimensionParam,VScalarParam>::Cell
SlicedCartesian<ScalarParam,dimensionParam,VScalarParam>::Cell::getNeighbour(
	int neighbourIndex) const
	{
	Index neighbourCellIndex=index;
	int face=neighbourIndex>>1;
	if(neighbourIndex&0x1)
		{
		++neighbourCellIndex[face];
		if(neighbourCellIndex[face]<grid->numCells[face])
			return Cell(grid,neighbourCellIndex);
		else
			return Cell();
		}
	else
		{
		--neighbourCellIndex[face];
		if(neighbourCellIndex[face]>=0)
			return Cell(grid,neighbourCellIndex);
		else
			return Cell();
		}
	}
Esempio n. 15
0
    Node *findLeaf(Node *node, Cell const &at, bool canSubdivide)
    {
        if(node->isLeaf()) return node;

        // Into which quadrant do we need to descend?
        Node::Quadrant q = node->quadrant(at);

        // Has this quadrant been initialized yet?
        Node **childAdr = &node->children[q];
        if(!*childAdr)
        {
            if(!canSubdivide) return 0;

            // Subdivide the space.
            uint const subSize = node->size >> 1;
            switch(q)
            {
            case Node::TopLeft:
                *childAdr = newNode(node->cell, subSize);
                break;

            case Node::TopRight:
                *childAdr = newNode(Cell(node->cell.x + subSize, node->cell.y), subSize);
                break;

            case Node::BottomLeft:
                *childAdr = newNode(Cell(node->cell.x, node->cell.y + subSize), subSize);
                break;
            case Node::BottomRight:
                *childAdr = newNode(Cell(node->cell.x + subSize, node->cell.y + subSize), subSize);
                break;
            }
        }

        return findLeaf(*childAdr, at, canSubdivide);
    }
Esempio n. 16
0
void BuyerParser::getWeakTiesPreferences(std::vector<std::vector<float> >& ties,
					 size_t ties_count) {
  ties.clear();
  Cell start_c('c', 54);

  for( int k=0; k<ties_count; k++ ) {
    ties.push_back(std::vector<float>(N_BRANDS));
    Cell c = Cell(start_c.first, start_c.second+k);
  
    for( int b=0; b<N_BRANDS; b++ ) {
      ties[k][b] = std::atof( getCell(c).c_str() );
      c.first++;
    }
  }
}
Esempio n. 17
0
void StructuredGrid2D::init(Size nCellsI, Size nCellsJ, std::pair<Scalar, Scalar> xb, std::pair<Scalar, Scalar> yb)
{
    _nCellsI = nCellsI;
    _nCellsJ = nCellsJ;
    _xb = xb;
    _yb = yb;

    Scalar dx = (_xb.second - _xb.first) / _nCellsI;
    Scalar dy = (_yb.second - _yb.first) / _nCellsJ;

    _nodes.clear();

    for (auto j = 0; j < nNodesJ(); ++j)
        for (auto i = 0; i < nNodesI(); ++i)
            _nodes.push_back(Point2D(i * dx + _xb.first, j * dy + _yb.first));

    _cells.clear();

    for(auto j = 0; j < _nCellsJ; ++j)
        for(auto i = 0; i < _nCellsI; ++i)
            _cells.push_back(Cell(*this, i, j));

    _ifaces.clear();

    for(int j = 0; j < _nCellsJ; ++j)
        for(int i = 0; i < nNodesI(); ++i)
        {
            _ifaces.push_back(Face(*this, Coordinates::I, i, j));
        }

    _jfaces.clear();

    for(int i = 0; i < _nCellsI; ++i)
        for(int j = 0; j < nNodesJ(); ++j)
        {
            _jfaces.push_back(Face(*this, Coordinates::J, i, j));
        }

    _faces.clear();
    for(const Face &f: _ifaces)
        _faces.push_back(f);

    for(const Face &f: _jfaces)
        _faces.push_back(f);

    _localCells.add(_cells.begin(), _cells.end());
    _ownership.resize(_cells.size(), _comm->rank());
}
Esempio n. 18
0
std::vector<Cell> MxField::cells() const
{
    std::vector<Cell> result;
    for (uint32_t x = 0; x < m_sides.x; ++x) {
        for (uint32_t y = 0; y < m_sides.y; ++y) {
            for (uint32_t z = 0; z < m_sides.z; ++z) {
                if (m_field[x][y][z] != 0) {
                    result.push_back(Cell(//new FCube(side()),
                                          new FSphere(radius()),
                                          dCoord(x * side(), y * side(), z * side())));
                }
            }
        }
    }
    return result;
}
Esempio n. 19
0
Ground::Ground(int w, int h, Frame *fr) : width(w), height(h), frame(fr)
{
	cell_rows = height/CELL_SZ;
	cell_cols = width/CELL_SZ;

	cells.reserve(cell_rows*cell_cols);
	for(int i=0; i<cell_rows*cell_cols; ++i){
		cells.push_back(Cell(CELL_SZ, CELL_SZ, i%cell_cols, i/cell_cols, this));
	}

	surf = SDL_CreateRGBSurface(0, width, height, 32, 0, 0, 0, 0);
	pixels = static_cast<Uint32 *>(surf->pixels);
//	pixels = new Uint32[width*height];
	std::memset(pixels, 0, width*height*sizeof(Uint32));
	calcMinerals();
}
Esempio n. 20
0
DBObjRecord *DBNetworkIF::ToCell (const DBObjRecord *cellRec) const

	{
	DBInt toCell;
	DBPosition pos;

	if (cellRec == (DBObjRecord *) NULL) return ((DBObjRecord *) NULL);
	toCell = ToCellFLD->Int (cellRec);
	pos = PositionFLD->Position (cellRec);

	if (toCell == 0x0L) return ((DBObjRecord *) NULL);
	if ((toCell == DBNetDirNW) || (toCell == DBNetDirN) || (toCell == DBNetDirNE)) pos.Row++;
	if ((toCell == DBNetDirSE) || (toCell == DBNetDirS) || (toCell == DBNetDirSW)) pos.Row--;
	if ((toCell == DBNetDirNE) || (toCell == DBNetDirE) || (toCell == DBNetDirSE)) pos.Col++;
	if ((toCell == DBNetDirNW) || (toCell == DBNetDirW) || (toCell == DBNetDirSW)) pos.Col--;
	return (Cell (pos));
	}
  vector<Cell> ConnectionsPerformanceTest::randomSDR(UInt n, UInt w)
  {
    set<UInt> sdrSet = set<UInt>();
    vector<Cell> sdr = vector<Cell>();

    for (UInt i = 0; i < w; i++)
    {
      sdrSet.insert(rand() % (UInt)n);
    }

    for (UInt c : sdrSet)
    {
      sdr.push_back(Cell(c));
    }

    return sdr;
  }
Esempio n. 22
0
/*	function : leap_O_faith ()
		called when there's no absolute choice to be made.
		this function chooses the cell with minimum number of possible values and assigns
		it a random value.
		it then pushes a LEAP_OF_FAITH action record on top of the action tracker.
		if this function fails, it sets the state flag _BAD_OPERATION.
		return value :
			Succeeded	->	true.
			Failed		->	false.
*/
bool	 sudokuBoard::leap_O_faith()
{
	Cell *minPossib = &Data[0][0];

	// find the minnimum possibilities cell that is free.
	for(Index i=0 ; i<9 ; i++)
	{
		for(Index j=0 ; j<9 ; j++)
		{
			if( Data[i][j] == sudokuValue::UNSET ) 
				if( Data[i][j].countPossibilities() < minPossib->countPossibilities() )
					minPossib = &Data[i][j];
		}
	}

	// re-validate the chosen cell to check for errors.
	expectFor( *minPossib );

	// if the possibilities have changed, then the current state of the board is invalid.
	if(minPossib->countPossibilities() == 0)
	{
		// set the bad operation flag and push a bad operation action.
		this->state |= sudokuState::_BAD_OPERATION;
		pushAction ( actionRecord( actionRecord::BAD_OPERATION , Cell() , false ) );
		return false;
	}
	// else if the possibilities are correct :
	else
	{
		for(int i=1 ; i<10 ; i++) // cycle through the possibilities of the cell
		{
			if(minPossib->possible[i]) // find the first possible value.
			{
				
				Data[minPossib->row][minPossib->col].v = i;

				// return an action indicating the leap of faith.
				pushAction ( actionRecord( actionRecord::LEAP_OF_FAITH , Data[minPossib->row][minPossib->col] , true) );
				return true;
			}
		}
	}
	// if couldn't find a guess, then report failure.
	return false;
}
Esempio n. 23
0
void Surface3D::addLayer(const AllNeighbors& totalNeighbors, int sX, int sY, int sZ) {
    Surface2D surfaceXY;
    surfaceXY.reserve(sY);

    for (int y = 0; y < sY; ++y) {
        Surface1D surfaceX;
        surfaceX.reserve(sX);

        for (int x = 0; x < sX; ++x) {
            Atoms atoms;
            atoms.reserve(totalNeighbors.size());

            for (auto const& neighbors : totalNeighbors) {
                Neighbors neighbs;
                // First neighbors count
                char numberNeighbs = 0;

                for (int nb = 0; nb < 4; ++nb) {
                    if (x + neighbors[nb].x >= 0
                        && y + neighbors[nb].y >= 0
                        && x + neighbors[nb].x < sX
                        && y + neighbors[nb].y < sY) {
                        ++numberNeighbs;
                        AtomType neighb = {x + neighbors[nb].x,
                                           y + neighbors[nb].y, sZ + neighbors[nb].z,
                                           neighbors[nb].type, false};
                        neighbs.push_back(neighb);
                    }
                }

                AtomInfo atom;
                atom.neighbors = neighbs;
                atom.firstNeighborsCount = numberNeighbs;
                atom.deleted = numberNeighbs == 0;
                atoms.push_back(atom);
            }

            surfaceX.push_back(Cell(atoms));
        }

        surfaceXY.push_back(surfaceX);
    }

    push_back(surfaceXY);
}
Esempio n. 24
0
void Morphology::GenerateObjectList(std::vector<std::vector<int>> map, std::vector<std::shared_ptr<Object>>& objects, int Width, int Height, std::vector<std::vector<int>>& Labels)
{
	std::multimap<int, Cell> Maps;
	Labeling(map, Labels, Width, Height, Maps);

	std::multimap<int, Cell>::iterator k, v;

	for (k = Maps.begin(); k != Maps.end(); k = v)
	{
		Object o;
		auto theKey = k->first;
		auto keyRange = Maps.equal_range(theKey);
		for (v = keyRange.first; v != keyRange.second; ++v)
			o.addCell(Cell(v->second.x, v->second.y));
		o.generateObject();
		objects.push_back(std::make_shared<Object>(o));
	}
}
Esempio n. 25
0
Board::Board()
    : _winner(NULL)
{
  for (int i = 0; i < 3; ++i)
  {
    std::vector<Cell> c;
    for (int j = 0; j < 3; ++j)
    {
      c.push_back( Cell(i, j) );
    }
    _cells.push_back(c);
  }

  populateWinningPatterns();

  if ( DEBUG )
    std::cerr << "New Board created: " << toString() << std::endl;
}
Esempio n. 26
0
void Game::tick()
{
    // create temp array for next grid
    // make every cell DEAD immediately
    int **nextGrid = new int*[width];
    for (int col = 0; col < width; ++col)
    {
        nextGrid[col] = new int[height];
        for (int row = 0; row < height; ++row)
        {
            nextGrid[col][row] = DEAD;
        }
    }

    // for every cell not on an edge/border, determine its status for
    // next generation
    for (int x = 1; x < width - 1; ++x)
    {
        for (int y = 1; y < height - 1; ++y)
        { 
            determineFate(Cell(x, y), nextGrid);
        }
    }

    // now that we know what every cell is going to do...

    // overwrite all cells other than the edge cells
    // this ensure the edge cells always stay DEAD and, thanks to
    // hidden buffers, gives the user the illusion of an infinite world
    for (int x = 1; x < width - 1; ++x)
    {
        for (int y = 1; y < height - 1; ++y)
        {
            grid[x][y] = nextGrid[x][y];
        }
    }

    // deallocate that memory
    for (int col = 0; col < width; ++col)
    {
        delete [] nextGrid[col];
    }
    delete [] nextGrid;
}
Esempio n. 27
0
PrintTable &
PrintTable::end_col()
{
    m_currentCell.m_string = std::string(m_currentCell.m_indent*2, ' ') + m_currentString.str();
    m_table.back().push_back(m_currentCell);
    if (m_table.size() > 1 && m_table[0].size() <= m_table.back().size()) {
        m_currentCell.m_string = "";
        m_currentCell.m_flags = 0;
        m_currentCell.m_justification = m_table[0][m_table[0].size() - 1].m_justification;
        m_currentCell.m_width = m_table[0][m_table[0].size() - 1].m_width;
        m_currentCell.m_indent = m_table[0][m_table[0].size() - 1].m_indent;
    }
    else {
        m_currentCell = Cell();
    }
    m_currentString.str("");

    return *this;
}
Esempio n. 28
0
DBObjRecord *DBNetworkIF::FromCell (const DBObjRecord *cellRec,DBInt dir,DBInt sameBasin) const

	{
	DBInt fromCell;
	DBPosition pos;

	if (cellRec == (DBObjRecord *) NULL) return ((DBObjRecord *) NULL);
	if (sameBasin)
		{
		fromCell = FromCellFLD->Int (cellRec);
		if ((fromCell & dir) != dir) return ((DBObjRecord *) NULL);
		}
	pos = PositionFLD->Position (cellRec);
	if ((dir == DBNetDirNW) || (dir == DBNetDirN) || (dir == DBNetDirNE)) pos.Row++;
	if ((dir == DBNetDirSE) || (dir == DBNetDirS) || (dir == DBNetDirSW)) pos.Row--;
	if ((dir == DBNetDirNE) || (dir == DBNetDirE) || (dir == DBNetDirSE)) pos.Col++;
	if ((dir == DBNetDirNW) || (dir == DBNetDirW) || (dir == DBNetDirSW)) pos.Col--;
	return (Cell (pos));
	}
Esempio n. 29
0
 void reachableNodes (const Function &fn, Graph &g, Set &inputReach, Set& retReach) {
   // formal parameters
   for (Function::const_arg_iterator I = fn.arg_begin(), E = fn.arg_end(); I != E; ++I) {
     const Value &arg = *I;
     if (g.hasCell (arg)) {
       Cell &c = g.mkCell (arg, Cell ());
       markReachableNodes (c.getNode (), inputReach);
     }
   }
   
   // globals
   for (auto &kv : boost::make_iterator_range (g.globals_begin(), g.globals_end())) {
     markReachableNodes (kv.second->getNode (), inputReach);
   }
   
   // return value
   if (g.hasRetCell (fn))
     markReachableNodes (g.getRetCell (fn).getNode(), retReach);
 }
Esempio n. 30
0
Maze::Maze(SceneManager* sceneManager, int* map, int width, int height)
	: mWidth(width), mHeight(height), mSceneManager(sceneManager), 
	mMap(0)
{	
	this->mSceneNode = sceneManager->getRootSceneNode()->createChildSceneNode("mapSenenNode");
	this->pZones = new Cell[mWidth * mHeight];
	this->pMapInfo = new int[mWidth * mHeight];
	this->startPos = std::vector<Ogre::Vector3>();
	this->mSceneNode->setPosition(Ogre::Vector3(-mWidth / 2.0f * 100, 0, -mHeight / 2.0f * 100));

	for(int j = 0; j < width; ++j)
	{
		for(int i = 0; i < height; ++i)
		{
			this->pZones[j * width + i] = Cell(sceneManager, mSceneNode, new Ogre::Vector2(Real(i),Real(j)), map[j * width + i], 0.1f);
		}
	}
	this->horizon = this->pZones[1].getHeight() / 2.0f;
}