Ejemplo n.º 1
0
//----------------------------------------------------------------------------------------
bool check(int i, int j)
{
	for(int m=i-2; m<=i+2; ++m)
		for(int n=j-2; n<=j+2; ++n)
			if(surround(m,n,CPlant::farm)>=4) return false;
	return true;
}
Ejemplo n.º 2
0
int
pushsnake(void)
{
	int	i, bonus;
	int	issame = 0;
	struct point tmp;

	/*
	 * My manual says times doesn't return a value.  Furthermore, the
	 * snake should get his turn every time no matter if the user is
	 * on a fast terminal with typematic keys or not.
	 * So I have taken the call to times out.
	 */
	for (i = 4; i >= 0; i--)
		if (same(&snake[i], &snake[5]))
			issame++;
	if (!issame)
		pchar(&snake[5], ' ');
	/* Need the following to catch you if you step on the snake's tail */
	tmp.col = snake[5].col;
	tmp.line = snake[5].line;
	for (i = 4; i >= 0; i--)
		snake[i + 1] = snake[i];
	chase(&snake[0], &snake[1]);
	pchar(&snake[1], SNAKETAIL);
	pchar(&snake[0], SNAKEHEAD);
	for (i = 0; i < 6; i++) {
		if ((same(&snake[i], &you)) || (same(&tmp, &you))) {
			surround(&you);
			i = (cashvalue) % 10;
			bonus = arc4random_uniform(10);
			mvprintw(lcnt + 1, 0, "%d\n", bonus);
			refresh();
			delay(30);
			if (bonus == i) {
				spacewarp(1);
#ifdef LOGGING
				logit("bonus");
#endif
				flushinp();
				return(1);
			}
			flushinp();
			endwin();
			if (loot >= penalty) {
				printf("\nYou and your $%d have been eaten\n", cashvalue);
			} else {
				printf("\nThe snake ate you.  You owe $%d.\n", -cashvalue);
			}
#ifdef LOGGING
			logit("eaten");
#endif
			length(moves);
			snscore(TOPN);
			close(rawscores);
			exit(0);
		}
	}
	return(0);
}
Ejemplo n.º 3
0
//----------------------------------------------------------------------------------
bool loadRandomStable(SDL_Renderer* ren, int N)
{
	int i,j; int limit = 500;
	while(N && limit--){
	i=rand()%MAP_HEIGHT;  j=rand()%(MAP_WIDTH-4);
	  
	if(CPlant::farm[i][j] == 0){
		if( surround(i,j,CPlant::farm)==2 || surround(i,j,CPlant::farm)==3 )
		 {if(surround(i-1,j-1,CPlant::farm)!=3 && surround(i-1,j,CPlant::farm)!=3 && surround(i-1,j+1,CPlant::farm)!=3 && surround(i,j-1,CPlant::farm)!=3 && surround(i,j+1,CPlant::farm)!=3 && surround(i+1,j-1,CPlant::farm)!=3 && surround(i+1,j,CPlant::farm)!=3 && surround(i+1,j+1,CPlant::farm)!=3)
		   {CPlant::farm[i][j]=1;  --N;}
		 }
		else
		if(surround(i,j,CPlant::farm)<2)
		{
			int range = 3-surround(i,j,CPlant::farm); int count = range;
			int p = 1+rand()%range;
			while(count--)
			{
			  //fill and check
				if(fillNcheck(i,j,p)) {  --N;  break;}
				else { p = 1+(p+1)%range;}
			}
		}
	 }
	}
	return true;
}
Ejemplo n.º 4
0
BVH::BVH(Shape** shapes, int num_shapes) {
    if (num_shapes == 1) {*this = BVH(shapes[0], shapes[0]);}
    else if (num_shapes == 2) {*this = BVH(shapes[0], shapes[1]);}
    
    //find midpoint of bbox to use as qsplit pivot
    bbox = shapes[0] -> boundingBox(0.0f, 0.0f);
    for (int i = 1; i < num_shapes; i++) {
        bbox = surround(bbox, shapes[i] -> boundingBox(0.0f, 0.0f));
    }
    Vector3 pivot = (bbox.max() + bbox.min()) / 2.0f;
    
    int midpt = QSplit::qsplit(shapes, num_shapes, pivot.x(), 0);
    
    //create new bounding volume
    left = buildBranch(shapes, midpt, 1);
    right = buildBranch(&shapes[midpt], num_shapes - midpt, 1);
}
Ejemplo n.º 5
0
Shape* BVH::buildBranch(Shape** shapes, int shape_size, int axis) {
    if (shape_size == 1) {return shapes[0];}
    else if (shape_size == 2) {return new BVH(shapes[0], shapes[1]);}
    
    //find midpoint of bbox to use as qsplit pivot
    BBox box = shapes[0] -> boundingBox(0.0f, 0.0f);
    for (int i = 1; i < shape_size; i++) {
        box = surround(box, shapes[i] -> boundingBox(0.0f, 0.0f));
    }
    Vector3 pivot = (box.max() + box.min()) / 2.0f;
    
    //split according to correct axis
    int midpt = QSplit::qsplit(shapes, shape_size, pivot[axis], axis);
    
    //create new bounding volume
    Shape* left = buildBranch(shapes, midpt, (axis + 1) % 3);
    Shape* right = buildBranch(&shapes[midpt], shape_size - midpt, (axis + 1) %3);
    return new BVH(left, right, box);
}