Exemplo n.º 1
0
void SandPile::testCritical(int point,std::vector<int> &lat,std::vector<int> &critical,std::vector<int> &allCritical){

	if(lat[point]>zk){

		lat[point]-=2*dimension;
		increaseNeighbours(point,lat);

		//std::cout << "Critical: " << std::endl;
		//coutLattice2d(lat);

		critical[point] = 1;
		// setNeighbours(point,critical,1);
		allCritical[point] = 1;
		// setNeighbours(point,allCritical,1);

		int neighbourNr[2*dimension];
		neighboursNumbers(point,neighbourNr);

		for(int i=0;i<2*dimension;i++){
			if(neighbourNr[i]>=0){
				testCritical(neighbourNr[i],lat,critical,allCritical);
			}
		}

	}
}
Exemplo n.º 2
0
bool CubeBox::simulateMove(Player fromWhom,int row, int column)
{
   bool finished;
   bool playerWon=false;

   if(cubes[row][column]->owner()!=(Cube::Owner)fromWhom && cubes[row][column]->owner()!=Cube::Nobody)
      return false;

   cubes[row][column]->increase((Cube::Owner)fromWhom);

   do
   {
      int i,j;
      finished=true;
      playerWon=true;

      // check all Cubes
      for(i=0;i<dim();i++)
      {
	      for(j=0;j<dim();j++)
         {
	         if(cubes[i][j]->overMax())
	         {
	            increaseNeighbours(fromWhom,i,j);
	            cubes[i][j]->decrease();
	            finished=false;
	         }

	         if(cubes[i][j]->owner()!=(Cube::Owner)fromWhom)
	         playerWon=false;
         }
      }

      if(playerWon)
	      return true;
   }
   while(!finished);


   return true;
}
Exemplo n.º 3
0
void SandPile::testReached(int point,std::vector<int> &lat,std::vector<int> &critical){
	if(lat[point]>zk){

		lat[point]-=2*dimension;
		increaseNeighbours(point,lat);


		critical[point] = 1;
		setNeighbours(point,critical,1);

		int neighbourNr[2*dimension];
		neighboursNumbers(point,neighbourNr);

		for(int i=0;i<2*dimension;i++){
			if(neighbourNr[i]>=0){
				testReached(neighbourNr[i],lat,critical);
			}
		}

	}
}
Exemplo n.º 4
0
std::vector<int> SandPile::relax(std::vector<int> &lat) {
	std::vector<int> nextTimeStepLattice (lat);

	// std::cout<< "\tRelax Lattice" << std::endl;
	bool relaxed;
	do{ // performance optimierbar!!!
		lat=nextTimeStepLattice;
		relaxed = true;
		for(int i=0;i<nrOfElements;i++){


			if(lat[i]>zk){
				relaxed = false;
				nextTimeStepLattice[i]-= 2*dimension;
				increaseNeighbours(i,nextTimeStepLattice);
			}

		}
		// std::cout << "Relaxed: " << relaxed << "\n";
	}while(!relaxed);
	return nextTimeStepLattice;
}
Exemplo n.º 5
0
void SandPile::testCritical(int point,std::vector<int> &lat,std::vector<int> &critical, int timesteps, int &timestepsMax, int &size){
	if(lat[point]>zk){
		timesteps ++;
		if(timesteps>timestepsMax) timestepsMax = timesteps;
		lat[point]-=2*dimension;
		increaseNeighbours(point,lat);
		critical[point] = 1;
		size ++;
		// setNeighbours(point,critical,1);

		int neighbourNr[2*dimension];
		neighboursNumbers(point,neighbourNr);

		for(int i=0;i<2*dimension;i++){
			if(neighbourNr[i]>=0){
				testCritical(neighbourNr[i],lat,critical,timesteps,timestepsMax,size);
			}
		}

	}
	// std::cout << "testCritical: time:" << timestepsMax << " size " << size << std::endl;
}