Esempio n. 1
0
/* Divide the chamber recursively. Necessary parameters:
	- the array in which the maze exists 
	- the size of the whole maze (for printing)
	- the size of the current 'sector' of the maze
	- an absolute reference point for the sector's position in the array:
		- the coords of top-left corner

	NB: THIS IS THE FUNCTION THAT SEG FAULTS. But it's close... 
 */
int chamber_divide(max_maze array, maze_dimensions maze_dims, maze_dimensions c_dims, int tl_i, int tl_j){

	int div_j = 0, div_i = 0;	// Indices of dividing walls in array
	c_dims.height = 0;	
	c_dims.width = 0;

	// How big is the current empty chamber?
	c_dims = find_chamber_dims(array, tl_i, tl_j);

	// BASE CASE: If the chamber is only TWO cells wide OR tall, stop dividing
	if (c_dims.width <= BASECASE || c_dims.height <= BASECASE) {
		return 0; 
	}

	//If both h+w are greater than three cells, split it in four:

	/* Note: To create random numbers for an offset that places the division between 
	near edge + 1 and far edge - 1 we have to do %(something - 3). So must carefully 
	handle cases where 'something' is near 3 (EDGE_OFFSET): */

	else if (c_dims.width > EDGE_OFFSET && c_dims.height > EDGE_OFFSET) {

		int randw_offset = 1 + rand()%(c_dims.width - EDGE_OFFSET);
		int randh_offset = 1 + rand()%(c_dims.height - EDGE_OFFSET);

		div_j = tl_j + randw_offset; 
		div_i = tl_i + randh_offset;
	}

	else if(c_dims.width == EDGE_OFFSET || c_dims.height == EDGE_OFFSET){
		div_i = tl_i + 1;
		div_j = tl_j + 1;
	} 

	// Create the new walls
	create_walls(array, c_dims, tl_i, tl_j,div_i,div_j);

	// Create the doors (only with *'s for now)
	create_doors(array, maze_dims,tl_i, tl_j, div_i, div_j);

	// Once split, recurse down into the new, smaller sector. Then move on the next clockwise sector
	chamber_divide(array, maze_dims, c_dims, tl_i, tl_j ); // Try the top left chamber
	chamber_divide(array, maze_dims, c_dims, tl_i, div_j+1); // Try the top right
	chamber_divide(array, maze_dims, c_dims, div_i+1, div_j+1); // Try the bottom right
	chamber_divide(array, maze_dims, c_dims, div_i+1, tl_j); // Try the bottom left

	return 1;
}
Esempio n. 2
0
void demography  :: init()
{
//    pos.resize(CELLS);
//    pos_sf.resize(CELLS);
    confload conf;
    conf.init("swarm.cfg");

    //radius = cfg->getfloat("radius");
    radius          = conf.getfloat("radius");
    sensor_radius   = radius * conf.getfloat("sensor_radius");
    sensor_radius_e = radius * conf.getfloat("sensor_radius_e");
    query_radius    = radius * conf.getfloat("query_radius");
    force_coeff     = conf.getfloat("force_coeff");
    dampen          = conf.getfloat("dampen");
    cohesion_factor = conf.getfloat("cohesion_factor");
    separate_factor = conf.getfloat("separate_factor");

    if(true)
    {
        use_masks       = conf.getint  ("use_masks");
        
        auto aly_group       = conf.getint  ("aly_group"  );
        auto aly_group_s     = conf.getint  ("aly_group_s");
        auto aly_group_s_e   = conf.getint  ("aly_group_s_e");
             
        auto nmy_group       = conf.getint  ("nmy_group"  );
        auto nmy_group_s     = conf.getint  ("nmy_group_s");
        auto nmy_group_s_e   = conf.getint  ("nmy_group_s_e");
        
        auto v_aly        = conf.getvec2i("aly");
        auto v_aly_s      = conf.getvec2i("aly_s");
        auto v_aly_s_e    = conf.getvec2i("aly_s_e");

        auto v_nmy        = conf.getvec2i("nmy");
        auto v_nmy_s      = conf.getvec2i("nmy_s");
        auto v_nmy_s_e    = conf.getvec2i("nmy_s_e");

        filters[0][0].groupIndex     = aly_group     ;
        filters[0][1].groupIndex     = aly_group_s   ;
        filters[0][2].groupIndex     = aly_group_s_e ;

        filters[1][0].groupIndex     = nmy_group     ;
        filters[1][1].groupIndex     = nmy_group_s   ;
        filters[1][2].groupIndex     = nmy_group_s_e ;

        filters[0][0].categoryBits   = v_aly       .x;
        filters[0][0].maskBits       = v_aly       .y;
        filters[0][1].categoryBits   = v_aly_s     .x;
        filters[0][1].maskBits       = v_aly_s     .y;
        filters[0][2].categoryBits   = v_aly_s_e   .x;
        filters[0][2].maskBits       = v_aly_s_e   .y;

        filters[1][0].categoryBits   = v_nmy       .x;
        filters[1][0].maskBits       = v_nmy       .y;
        filters[1][1].categoryBits   = v_nmy_s     .x;
        filters[1][1].maskBits       = v_nmy_s     .y;
        filters[1][2].categoryBits   = v_nmy_s_e   .x;
        filters[1][2].maskBits       = v_nmy_s_e   .y;
    }
    vbunk.size=radius*sqrt(2)*5;
    ek.rate=0;
    ek.n=10;
    ek.res=0;
    timer=0;
    for(int i = 0; i < 10; ++i)
    bars.push_back(bar());
    Vec2 orig(20,20);
    for(int i = 0; i < 10; ++i)
    {
//        bars[i].
    }
    create_walls();
    World.SetContactListener(this);
    q=0;
}