Esempio n. 1
0
dir_e computeDir(Grid &myGrid, char NT)
{
	int m=0,ms=myGrid.getScore(),nt;
	float dm[4]={0};
	dir_e bd=LEFT;

	for(int d=0;d<4;d++) {
	for(int i=0;i<RUNCNT;i++) {
		Grid tg=myGrid;
		if(!tg.shift(getDirFromInt(d))) break;
		//printf("%d\n", tg.getSlotNo());fflush(stdout);
		if(NT=='+') setNT(tg, genSNT(tg));
		else { setNT(tg, NT-'0'); }
		for(int j=0;j<RUNDEP;j++) {
			if(!tg.shift(getRandDir())) continue;
			setNT(tg, getNT(tg));
		}
		int s=tg.getScore();
		if(s>m) { m=s; bd=getDirFromInt(d); }
		dm[d]+=s;
	}
	}
	int d=rand()%4;
	float dmm=dm[d];
	gotoXY(5,20);
	for(int i=0;i<4;i++) {
		if(dm[i]>dmm) { dmm=dm[i]; d=i; }
		//printf("%.0f ", dm[i]);
	}
	//printf("\n%.0f %d\n", dmm, m);
	//printf("%d %d\n", d, bd);
	if(dmm/RUNCNT*DTHRS>m) return getDirFromInt(d);
	return bd;
}
Esempio n. 2
0
/*
	Create a drone.
	
	The x and y parameters are the maximum height and width of the drawing area
*/
Drone createDrone(int xMin, int xMax, int yMin, int yMax)
{
	Drone drone;
	drone = getRandDir(drone);
	drone.locX = randomize(xMin+1, xMax-1);
	drone.locY = randomize(yMin+1, yMax-1);
	return drone;
}
Esempio n. 3
0
void PlayNRounds(int n){
#ifdef _WIN32
    system("cls");
#elif defined(__linux__)
    system("clear");
#endif
    int score;
    Game myGame;
    bool isGameOver;
    dir_e dir;

    gotoXY(5,0);
    std::cout<<"Previous";
    gotoXY(35,0);
    std::cout<<"Current (Hint: "<<myGame.getHint()<<")";
    myGame.printGrid(35,2);

    if(myGame.isGameOver(score))  myGame.reset();

    Grid myGrid;
    for(int i = 0;i < n;i++){    
        isGameOver = false;
        while(!isGameOver){
			dir = getRandDir();
            gotoXY(5,10);
            std::cout<<dirToStr(dir);
            myGame.printGrid(5,2);
          
            myGame.insertDirection(dir);
            gotoXY(50,0);
            std::cout<<myGame.getHint();
            isGameOver = myGame.isGameOver(score);
            myGame.printGrid(35,2);
            
       }
        myGame.printGrid(35,2);
        if(i < n - 1)  myGame.reset();
        gotoXY(0,15); 
        printf("  Round:    %d      \n", i+1);
        printf("  Score:    %d      \n", score);
 
    }
}
int getSheepDir (int sheepPos, int *theGrid, int gridX, Rand *thisRand) {
	// smart sheep will move toward something to eat if it is adjacent.
	// eventually, we might re-introduce tree age; sheep can only eat young trees and
	// must move around old trees.
	// do fires kill sheep?
	//
	int foodDirections[4] = {0,0,0,0};
	int nFoodDirs=0, sheepDir=0;
	//
	if (*(theGrid+sheepPos+1)==1) {
		foodDirections[nFoodDirs]=1;
		nFoodDirs++;
		};
	if (*(theGrid+sheepPos-1)==1) {
		foodDirections[nFoodDirs]=-1;
		nFoodDirs++;
		};
	if (*(theGrid+sheepPos+gridX)==1) {
		foodDirections[nFoodDirs] = gridX;
		nFoodDirs++;
		};
	if (*(theGrid+sheepPos-gridX)==1) {
		foodDirections[nFoodDirs] = -gridX;
		nFoodDirs++;
		};
	//
	// debug:
	// printf("from getSheepDir: %d\n", getRandDir(gridX, thisRand));
	//printf("sheepPos: %d,%d\n", sheepPos/gridX, sheepPos%gridX);
	//printf("nFoodDirs: %d:: %d, %d, %d, %d\n", nFoodDirs, foodDirections[0], foodDirections[1], foodDirections[2], foodDirections[3] );
	//printf("neighbors(l, u, r, d): %d, %d, %d, %d\n", *(theGrid-1), *(theGrid+gridX), *(theGrid+1), *(theGrid-gridX));
	//
	if (nFoodDirs>0) {
		// there is something we can eat...
		sheepDir = foodDirections[thisRand->nextInt(nFoodDirs)];
		}
	else {
		sheepDir = getRandDir(gridX, thisRand);
		};
	//
	if (sheepDir<0) sheepDir=-sheepDir;
	return sheepDir;
	};
int getSheepDir (int sheepPos, int *theGrid, int gridX, Rand thisRand) {
    // smart sheep will move toward something to eat if it is adjacent.
    // eventually, we might re-introduce tree age; sheep can only eat young trees and
    // must move around old trees.
    // do fires kill sheep?
    //
    int foodDirections[4] = {0,0,0,0};
    int nFoodDirs=0, sheepDir=0;
    //
    if (*(theGrid+1)==1) {
        foodDirections[nFoodDirs]=1;
        nFoodDirs++;
    };
    if (*(theGrid-1)==1) {
        foodDirections[nFoodDirs]=-1;
        nFoodDirs++;
    };
    if (*(theGrid+gridX)==1) {
        foodDirections[nFoodDirs] = gridX;
        nFoodDirs++;
    };
    if (*(theGrid-gridX)==1) {
        foodDirections[nFoodDirs] = -gridX;
        nFoodDirs++;
    };
    //
    if (nFoodDirs>0) {
        // there is something we can eat...
        sheepDir = foodDirections[thisRand.nextInt(nFoodDirs)];
    }
    else {
        sheepDir = getRandDir(gridX, thisRand);
    };
    //
    return sheepDir;
};
// int doffire(unsigned int xmax=128, unsigned int ymax=128, unsigned int fmatch=125 unsigned short burnPropAge=400) {
// use simpler float nRand, nClust probabilities...
int doffire(unsigned tmax=1000000, int doSQL=1, unsigned short fMatch=200, float nRand=1, float nClust=0, int kmax=4, int sheepSpeed=1) {
	// burn toplolgy: do we nave nnn burning
	//
	std::string simName("ForestFire7d");
	std::string simPramComment("");
	//int fMatch = 250;
	//
	unsigned short rFire = 1;
	unsigned int nBurning = 0;
	unsigned short dnBurning = 0;
	int thisX, thisY, xFire, yFire; 
	//int *fireSquare = new int;
	int *fireSquare = NULL;
	unsigned int nBurnedTotal=0, nFires=0;  // number of elements burning, new Elements burning...
	//
	int burnPropAge=1;
	//
	//int *bigClustMaps = new int[(ymax+2)*(xmax+2)];
	int *grids = new int[(ymax+2)*(xmax+2)];
	int intKey;
	float aveRho, aveVol;
	int gridPos=0;
	//
	int rSeed=int(time(NULL));
	int drSeed = 0;
	srand(time(NULL));	
	Rand plantRandx(rSeed + drSeed);
		drSeed ++;
	Rand plantRandy(rSeed + drSeed);
		drSeed ++;
	Rand fireRandx(rSeed + drSeed);
		drSeed ++;
	Rand fireRandy(rSeed + drSeed);
		drSeed ++;
	Rand rfMatch(rSeed + drSeed);
		drSeed ++;
	Rand rcPlant(rSeed + drSeed);
		drSeed ++;
	Rand walkDir(rSeed + drSeed);
		drSeed ++;
	Rand sheepRand(rSeed + drSeed);
		drSeed ++;

	// initialize sheep:
	unsigned int sheepPos = (xmax+2) + 1 + sheepRand.nextInt(xmax) + (xmax+2)*sheepRand.nextInt(ymax);	// a little sloppy with the rand. numbs, but not important.

	// initialize the grid/cluster-grid with "rocks" around the border and in otherwise empty cells.
	// "cluster 0" will, for the time being, not participate in the simulation. just for posterity,
	// we will place "rocks" around the borders. initialize the interior of the grid with 0; we will
	// map the excluded areas via the clusters grid.
	for (unsigned int i = (xmax+2); i<(xmax+2)*(ymax+1); i++) {
		grids[i] = 0;
		//clustGrids[i] = 0;
		};
	for (unsigned int i=0; i<(xmax+2); i++) {
		grids[i] = rockAge;
		grids[(ymax+1)*(xmax+2) + i] = rockAge;
		//
		};
	for (unsigned int i=0; i<(ymax+2); i++) {
		grids[(xmax+2)*i] = rockAge;
		grids[(xmax+2)*i + xmax+1] = rockAge;
		//
		};
	//printf("the grid:\n");
	//printGrid(grids, 1, xmax, ymax);
	//
	// cluster map moved to a function:
//	unsigned int biggestFire = getClustMaps1(bigClustMaps);
	unsigned int biggestFire = xmax0*ymax0;
	// now, the cluster map is established. as we plant trees, we will plant against this grid.
	//
	// seed the grid with some trees:
	Rand treeSeedx(rSeed + drSeed);
		drSeed ++;
	Rand treeSeedy(rSeed + drSeed);
		drSeed ++;
	// particularly for dendritic models, how many seeds to we want? in the purest form, we want 1, but that will take a LONG time to get started.
	for (unsigned int i=0; i < xmax; i++) {
		// seed the grid with some trees
		//if (rand()%(xmax)==1 and i%(xmax+2)!=0 and (i+1)%(xmax+2)!=0 and i>(xmax+2) and i<((xmax+2)*(ymax+1)) ) grids[i]++;
		int thisX = treeSeedx.nextInt(xmax);
		int thisY = treeSeedy.nextInt(ymax);
		//thisClust = clustGrids[(xmax+2)*(thisY+1)+thisX+1];
		//grids[(xmax+2)*(thisY+1)+thisX+1] = thisClust;
		//thisClust = *(bigClustMaps + (xmax+2)*(thisY+1)+thisX+1);
		*(grids + (xmax+2)*(thisY+1)+thisX+1) = 1;		
		//yodapause();
		};
	//printf("random grid established...\n");
	//printGrid(&grids[0], 1, xmax, ymax);
	//
	char DB[]="ForestFire";
	char HOST[]="localhost";
	char USER[]="myoder";
	char PASSWORD[]="yoda";
	mysqlpp::Connection myconn(DB, HOST, USER, PASSWORD);
	mysqlpp::Query myquery=myconn.query();
	mysqlpp::Result res1;
	//int intKey;
	//unsigned int fcounts[xmax*ymax];
	//unsigned int *fcounts = new unsigned int[xmax*ymax];
	unsigned int *fcounts = new unsigned int[biggestFire];
		for (unsigned int i=0; i<biggestFire; i++) {
			//fcounts[i]=0;
			*(fcounts + i) = 0;
			};
	if (doSQL==1 or doSQL==5) {	
		//
		// insert a new row for this sim-run:
		myquery.reset();
		printf("insert simprams.\n");
		//myquery << "insert into ForestFire.SimPrams (SimName, SimSW, xmax, ymax, sparkInterval, sparkProb, burnAge, propAge, tmax, wrapX, wrapY, Comment) values (%0q, %1q, %2q, %3q, %4q, %5q, %6q, %7q, %8q, %9q, %10q, %11q )";
		myquery << "insert into ForestFire.SimPrams (SimName, SimSW, xmax, ymax, sparkInterval, tmax, nRand, nClust, kmax, Comment) values (%0q, %1q, %2q, %3q, %4q, %5q, %6q, %7q, %8q, %9q)";
		myquery.parse();
		// note: simIndex(auto-int) and dtTime (default TIMESTAMP) set automatically.
		myquery.execute(simName.c_str(), simName.c_str(), xmax, ymax, fMatch, tmax, nRand, nClust, kmax, simPramComment.c_str());
		//
		// now, get the integer key for this simulation:
		// note that this could be accomplished with one call (optimal if MySQL calls have high overhead)
		// by writing a SPROC on the MySQL side.
		// also see the mysql_insert_id() (C API) and LAST_INSERT_ID() (SQL) functions, by which we should be ablt to automatically retrieve the indexID.
		myquery.reset();
		printf("fetch simIndex.\n");
		myquery << "select max(simIndex) from ForestFire.SimPrams where simName=%0q and simSW=%1q";
		myquery.parse();
		res1 = myquery.store(simName.c_str(), simName.c_str());
		intKey = res1.at(0).at(0);
		}; // doSQL

/*
	if (doSQL==1 or doSQL==5) {	
		//
		// insert a new row for this sim-run:
		myquery.reset();
		printf("insert simprams.\n");
		myquery << "insert into ForestFire.SimPrams (SimName, SimSW, xmax, ymax, sparkInterval, sparkProb, burnAge, propAge, tmax, wrapX, wrapY, Comment) values (%0q, %1q, %2q, %3q, %4q, %5q, %6q, %7q, %8q, %9q, %10q, %11q )";
		myquery.parse();
		// note: simIndex(auto-int) and dtTime (default TIMESTAMP) set automatically.
		myquery.execute(simName.c_str(), simName.c_str(), xmax, ymax, fmatch, pMatch, burnAge, burnPropAge, tmax, wrapx1, wrapy1, simPramComment.c_str());
		//
		// now, get the integer key for this simulation:
		// note that this could be accomplished with one call (optimal if MySQL calls have high overhead)
		// by writing a SPROC on the MySQL side.
		// also see the mysql_insert_id() (C API) and LAST_INSERT_ID() (SQL) functions, by which we should be ablt to automatically retrieve the indexID.
		myquery.reset();
		printf("fetch simIndex.\n");
		myquery << "select max(simIndex) from ForestFire.SimPrams where simName=%0q and simSW=%1q";
		myquery.parse();
		res1 = myquery.store(simName.c_str(), simName.c_str());
		intKey = res1.at(0).at(0);
		}; // doSQL
*/
	//
	for (unsigned int i=0; i<=tmax; i++) {
		//
		// first do the sheep:
		// note, we can remove sheep by setting sheepSpeed=0
		for (unsigned short isheep = 0; isheep<sheepSpeed; isheep++) {
			switch (*(grids+sheepPos)) {
				case 0: case rockAge:
					// move:
					sheepPos = sheepPos + getRandDir((xmax+2), sheepRand);
					break;
				case 1:
					// eat:
					*(grids+sheepPos)=0;
					break;
				default:
					// nothing.
					break;
				};
			//
			// are we outside the grid or on an illegal spot?
			if (sheepPos<=(xmax+2) or sheepPos>((xmax+2)*(ymax+1)) or sheepPos%(xmax+2)==0 or sheepPos%(xmax+1)==0) {
				// we've wandered off the grid; get new sheep.
				sheepPos = (xmax+2) + 1 + sheepRand.nextInt(xmax) + (xmax+2)*sheepRand.nextInt(ymax);
				};
			}; // sheep-speed
		//
		//if (doSQL==5 or doSQL==6) if(i%1000000 == 0) printf("%d million\n", i/1000000);
		if (doSQL==6) if(i%1000000 == 0) printf("%d million\n", i/1000000);

		if (doSQL==16) {
			if(i%100000 == 0) {
				// printf("%d million\n", i/1000000);
				aveRho=0;
				aveVol=0;
				for (unsigned int k=0; k<(xmax+2)*(ymax+2); k++) {
					if (*(grids+k)>0 and *(grids+k)<rockAge) {
						aveRho = aveRho + 1;
						aveVol = aveVol + *(grids+k);
						};
					};
				//printf("mils,\t Rho,\t Vol,\t %d, %f, %f\n", i/1000000, float(aveRho)/float(xmax*ymax), float(aveVol)/float(xmax*ymax));
				printf("%d, %f, %f\n", i/1000000, float(aveRho)/float(xmax*ymax), float(aveVol)/float(xmax*ymax));
				};
			};
		//
		// PLANT A TREE:
		// select a grid for tree planting:
		// yoder, v7: introduce dendritic growth. we have two prams, nRand, nClst. define a P(rand)-> Pr, P(clust)->Pc: Pr=nRand/(nRand+nClust), etc.
		//for (unsigned int irp=0; irp<randPlant; irp++) {
		thisX = plantRandx.nextInt(xmax);
		thisY = plantRandy.nextInt(ymax);
		gridPos = (xmax+2)*(thisY+1)+1+thisX;
		//
		// what is the grid value? if it's empty, plant against P=nRand/(nRand+nClust); if it's a tree, plant each adjacent grid with nR/(nR+nC)
		switch (*(grids+gridPos)) {
			case 0:
				// planting stats:
				if (rcPlant.nextDouble() <= nRand) {
					*(grids+gridPos) = 1;
					};
				break;
			case 1:
				if (rcPlant.nextDouble() <= float(nClust)/float(nClust+nRand) and *(grids+gridPos + 1)==0) {
					*(grids+gridPos+1) = 1;
					};
				if (rcPlant.nextDouble() <= float(nClust)/float(nClust+nRand) and *(grids+gridPos - 1)==0) {
					*(grids+gridPos-1) = 1;
					};
				if (rcPlant.nextDouble() <= float(nClust)/float(nClust+nRand) and *(grids+gridPos + (xmax+2))==0) {
					*(grids+gridPos+(xmax+2)) = 1;
					};
				if (rcPlant.nextDouble() <= float(nClust)/float(nClust+nRand) and *(grids+gridPos - (xmax+2))==0) {
					*(grids+gridPos-(xmax+2)) = 1;
					};
				break;
			};
		//
// debug:
//		if (i%10000==0) {
//			plotGridSimple (grids, i, xmax, ymax);
//			};

	// we've planted a tree. do we throw a match?
	// a 1 in fMatch chance (use any value between 0 and fMatch)
		if (rfMatch.nextInt(fMatch) == 1) {
			//yodapause();
			// throw a match.
			xFire = fireRandx.nextInt(xmax) + 1;
			yFire = fireRandy.nextInt(ymax) + 1;
			//
			fireSquare = grids + (xmax+2)*yFire + xFire;
			//printf("match: (%d, %d) :: %d\n", xFire, yFire, *fireSquare);
			//yodapause();
			//
			if (*fireSquare > 0 and *fireSquare<rockAge) {
				// initiate a new fire.
				// start from the epicenter and work out in concentric rectangles (squares)
				// until there are no new fires.
				// note: we make two passes over each circle. for now, we assume all squares
				// continue to burn until the fire is over. this is a subtle consideration that
				// will not matter for simpler versions of the model, but if we introduce burn probabilities,
				// we will have to be more careful.

				//burningClust = clustGrids[(xmax+2)*yFire + xFire];
				//burningClust = *(bigClustMaps + (xmax+2)*yFire + xFire);
				*fireSquare=-(*fireSquare);	// the fire-square starts burning
				//
				rFire = 1;
				dnBurning = 1;
				//
				nBurning = dnBurning;
				int yFireMin = int(yodacode::greaterOf((yFire-rFire), 1));	// we always start with a 1 squar boundary. we might, however, encounter the edges.
				int yFireMax = int(yodacode::lesserOf((yFire+rFire), float(ymax)));
				int xFireMin = int(yodacode::greaterOf(float(xFire-rFire), 1));
				int xFireMax = int(yodacode::lesserOf(float(xFire+rFire), float(xmax)));
				//printf("fire range: %d, %d, %d, %d\n", yFireMin, yFireMax, xFireMin, xFireMax);
				//printf("preplot\n.");
				//
				//plotGrid(&grids[0],i, xmax, ymax);
				if (doSQL==0) {
					printGrid(grids, i, xmax, ymax);
					};
				//while (dnBurning > 0) {
				while (dnBurning > 0) {
					dnBurning=0;
					for (char doTwice = 0; doTwice <=1; doTwice++) {	// "char" is a 1 byte integer. we could also use a boolean to count to 2.
					for (int iy = (yFireMin); iy <= (yFireMax); iy++) {
						for (int ix = (xFireMin); ix <= (xFireMax); ix++) {
							// also note: Gelb is right. a recursive approach is faster, though this bredth-first appraoch is more like real fire propagation.
							// printf("try-burn: %d, %d\n", ix, iy);
							//plotGrid(&grids[0], xmax, ymax);
							//yodapause();
							//
							int * centerGrid = (grids + ix + (xmax+2)*iy);
							int cStat, uStat, dStat, lStat, rStat;
							//int ulStat, urStat, llStat, lrStat;	// diagonal elements.
							cStat = *centerGrid;
							//
							uStat = *(centerGrid + (xmax+2));
							dStat = *(centerGrid - (xmax+2));
							lStat = *(centerGrid - 1);
							rStat = *(centerGrid + 1);
							//
							// diagonal elements:
							//ulStat = getGridStatus(*(centerGrid + (xmax+2) - 1), i);
							//urStat = getGridStatus(*(centerGrid + (xmax+2) + 1), i);
							//llStat = getGridStatus(*(centerGrid - (xmax+2) - 1), i);
							//lrStat = getGridStatus(*(centerGrid - (xmax+2) + 1), i);
							//yodapause();
								//if (*centerGrid >= burnAge and (*leftGrid==-1 or *rightGrid==-1 or *upGrid==-1 or *downGrid==-1)) {
								//if (*centerGrid >= burnAge and (*leftGrid<=-burnPropAge or *rightGrid<=-burnPropAge or *upGrid<=-burnPropAge or *downGrid<=-burnPropAge)) {
								//if (cStat >= burnAge and cStat < rockAge and (lStat<=-burnPropAge or rStat<=-burnPropAge or uStat<=-burnPropAge or dStat<=-burnPropAge)) {
								//
							// no immunity:
							if (cStat >= 1 and cStat < rockAge 
								and (lStat<=-1 or rStat<=-1 or uStat<=-1 or dStat<=-1) )
								{
	//
	//						// next nearest neighbors:
	//						if (cStat >= burnAge and cStat < rockAge 
	//							and  ( (lStat<=-burnPropAge or rStat<=-burnPropAge or uStat<=-burnPropAge or dStat<=-burnPropAge)
	//								 or ( (ulStat<=-nnnAge or urStat<=-nnnAge  or llStat<=-nnnAge  or lrStat<=-nnnAge)
	//									 and (ulStat<=-burnPropAge or urStat<=-burnPropAge or llStat<=-burnPropAge  or lrStat<=-burnPropAge)
	//									 )
	//						 		)
	//							) {
								*centerGrid = -(*centerGrid);
								// age -> number of trees in that grid...
								dnBurning ++;
								//printf("[%d, %d] catches from [%d, %d]\n", ix, iy, xFire, yFire);
								};
							}; // ix
						}; // iy
						}; // doTwice	
						// plotGridSimple (grids, i, xmax, ymax);
						nBurning = nBurning + dnBurning;
						//yodapause();
					xFireMin = int(yodacode::greaterOf(1, float(xFireMin-1)));
					xFireMax = int(yodacode::lesserOf(float(xmax), xFireMax+1));
					yFireMin = int(yodacode::greaterOf(1, float(yFireMin-1)));
					yFireMax = int(yodacode::lesserOf(float(ymax), yFireMax+1));
					// g1.plot_xy(vfireX, vfireY, "");
					};	// end "while" fire still burining
				//
				nFires++;
				nBurnedTotal = nBurnedTotal + nBurning;
				fcounts[nBurning-1]++;
			//	plotGrid(&grids[0], xmax, ymax);
				if (doSQL==0) {
					printGrid(&grids[0], i, xmax, ymax);
					printf("fire size, vol, nFires, totalBurned, totalVol: (%d) (%d) (%d)\n", nBurning, nFires, nBurnedTotal);
					};
				// write fire to MySQL:
				if (doSQL==1) {
					printf("fire size, nFires, totalBurned: (%d) (%d) (%d)\n", nBurning, nFires, nBurnedTotal);
	//				myquery.reset();
	//				myquery << "insert into ForestFire.ForestFires (simIndex, t, xSpark, ySpark, AveTreeAge, nBurned) values (%0q, %1q, %2q, %3q, %4q, %5q) ";
	//				myquery.parse();
	//				myquery.execute(intKey, i, xFire, yFire, aveTreeAge, nBurning);
					};
				if (doSQL==3) {
					printf("fire (%d) at time %d\n",nBurning, i);
					if (nBurning>=10) plotGridSimple (grids, i, xmax, ymax);
					};
				if (doSQL==4) {
					if (nBurning>=10) plotGridImg (grids, i, xmax, ymax, burnPropAge);
					};
				//
				// fires finished burning; extinguish:
				for (int iy = (yFireMin); iy <= (yFireMax); iy++) {
					for (int ix = (xFireMin); ix <= (xFireMax); ix++) {
						// &grids[0] + ix + (xmax+2)*iy
						//if (grids[ix + (xmax+2)*iy] < 0) grids[ix + (xmax+2)*iy]=0;
						if (*(grids +ix + (xmax+2)*iy) < 0) *(grids +ix + (xmax+2)*iy)=0;
						};
					};
				}; //else printf("no tree at match point.\n");	// if match -> tree...
			}; // if match-time
		};	// end sim-steps.
	// end simulation.
	//printf("doSQL: %d\n", doSQL);
	// doSQL's:
	// 0: 'print-grid" fires
	// 1: full SQL: insert each forest fire data-set into ForestFires
	// 2: print summary to screen. use this for direct gnuplot calls, " plot '<./ffire4...'" 
	// 3: Print each fire to screen; "plotGrid" each fire nBurning>(25) print summary to screen at end
	// 4: plotGridImg each fire nBurning>(20); print summary to screen,
	// 5: SQL: insert just summary data to SQL; prints progress by million (will screw up plotting)
	// 6: report summary, progress by million.
	// 11: return to standard-output the last grid in full. use to make an image of the final grid.
	//
	// end-o-run summaries (print):
	if (doSQL==2 or doSQL==3 or doSQL==4 or doSQL==6) {
		for (unsigned int i=0; i<(biggestFire); i++) {
			//if (fcounts[i]!=0) printf("%d\t%d\n", i+1, fcounts[i]);
			if (*(fcounts + i) != 0) printf("%d\t%d\n", i+1, *(fcounts + i));
			//printf("%d,\t%d\n", i+1, fcounts[i]);
			};
		} else {
			//printf("finished.\nfire size, nFires, totalBurned: (%d) (%d) (%d)\n", nBurning, nFires, nBurnedTotal);
			};
	if (doSQL==5 ) { // no plots, just a summary -> SQL
		//
		for (unsigned int i=0; i<(biggestFire); i++) {
			// if (fcounts[i]!=0) printf("%d\t%d\n", i+1, fcounts[i]);
		//	printf ("sql bits: %d, %d, %d, %d\n", intKey, tmax, i+1, fcounts[i]);
			myquery.reset();
			myquery << "insert into ffcounts (simIndex, tmax, nBurned, nEvents) values (%0q, %1q, %2q, %3q)";
			myquery.parse();
			myquery.execute(intKey, tmax, i+1, fcounts[i]);
			//printf("%d,\t%d\n", i+1, fcounts[i]);
			};				
		};
	// return the final grid in full and give an average density at the end...?
	if (doSQL==11) {
		for (unsigned int i=0; i<(xmax+2)*(ymax+2); i++) {
			printf ("%d,\t%d,\t%d\n", i-int(i/(xmax+2))*(xmax+2), i/(xmax+2), getGridStatus(*(grids+i), tmax));
			};
		};

	//yodacode::yodapause();
	return 0;
	//return &grids[0];
	};