Example #1
0
region * create_region(unsigned int uid, int x, int y, const terrain * t)
{
    region * r = 0;
    region **bucket = 0;

    while (!uid || r) {
        uid = (unsigned int)genrand_int31();
        r = get_region(uid);
    };

    assert(t);
    r = (region *)malloc(sizeof(region));
    if (r) {
        memset(r, 0, sizeof(region));

        bucket = &regionhash[uid & RHASHMASK];
        r->nexthash_ = *bucket;
        *bucket = r;

        r->uid = uid;
        r->x = x;
        r->y = y;
        r->terrain = t;

        ql_push(&regions, r);
    }
    return r;
}
Example #2
0
void game_next_piece()
{
	curr_piece.t = next_piece;
	curr_piece.x = 3 + next_piece->x_init_off;
	curr_piece.y = -1;
	curr_piece.lock = 0;
	curr_piece.rot = 0;
	if(key_time[TK_A]||key_time[TK_C]) curr_piece.rot = curr_piece.t->frames-1;
	else if(key_time[TK_B]) curr_piece.rot = min(1, curr_piece.t->frames-1);

	int i,j,next;
	for(i=3; i>=0; --i)
	{
		next = genrand_int31()%7;
		for(j=3; j>=0; --j)
			if(history[j] == next)
				j=-1;
		if(j==0) break;
	}
	history[3] = history[2];
	history[2] = history[1];
	history[1] = history[0];
	history[0] = next;

	next_piece = pieces[next];
}
Example #3
0
knh_uint_t knh_rand(void)
{
#if defined(K_USING_INT32)
	return (knh_uint_t)genrand_int31();
#else
	return (knh_uint_t)genrand64_int63();
#endif
}
Example #4
0
knh_uint_t knh_rand(void)
{
#if defined(KONOHA_ON_LKM)
	return (knh_uint_t)random32();
#elif defined(K_USING_INT32)
	return (knh_uint_t)genrand_int31();
#else
	return (knh_uint_t)genrand64_int63();
#endif
}
Example #5
0
// A Fisher-Yates shuffle
void shuffle_ints( int n, int *array ) {
    int i, tmp, r;
    for ( i = n-1; i >= 0; i-- ) {
        // This will be slightly biased for large n, but it is not a
        // noticeable issue for dynamic solutions
        r = genrand_int31() % ( i + 1 );
        tmp = array[r];
        array[r] = array[i];
        array[i] = tmp;
    }
    return;
}
Example #6
0
void game_init(SDL_Surface *screen)
{
	init_genrand(time(0));
	f = new_field(10, 20);
	rs = get_ars_rotation_system();
	memset(key_time, 0, sizeof(int[8]));

	if(f == NULL)
		exit(-1);

	block_color[0x00] = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
	block_color[0x01] = SDL_MapRGB(screen->format, 0xFF, 0x00, 0x00);
	block_color[0x02] = SDL_MapRGB(screen->format, 0x00, 0xFF, 0xFF);
	block_color[0x03] = SDL_MapRGB(screen->format, 0xFF, 0x80, 0x00);
	block_color[0x04] = SDL_MapRGB(screen->format, 0x00, 0x00, 0xFF);
	block_color[0x05] = SDL_MapRGB(screen->format, 0xFF, 0x00, 0xFF);
	block_color[0x06] = SDL_MapRGB(screen->format, 0x00, 0xFF, 0x00);
	block_color[0x07] = SDL_MapRGB(screen->format, 0xFF, 0xFF, 0x00);
	block_color[0xFE] = SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF);
	block_color[0xFF] = SDL_MapRGB(screen->format, 0x40, 0x40, 0x40);
	
	pieces[0] = &rs->I;
	pieces[1] = &rs->T;
	pieces[2] = &rs->L;
	pieces[3] = &rs->J;
	pieces[4] = &rs->S;
	pieces[5] = &rs->Z;
	pieces[6] = &rs->O;
	
	history[0] = 4;
	history[1] = 5;
	history[2] = 4;
	history[3] = 5;

	next_piece = pieces[genrand_int31()%4];
	game_next_piece();
}
Example #7
0
/// Generates a random number in the interval [0, SINT32_MAX]
int32 rnd(void)
{
	return (int32)genrand_int31();
}
Example #8
0
int	gen_random(void) {
	return genrand_int31();
}
int main(int argc, char *argv[])
{

    pthread_t first_thread;
    pthread_attr_t attr;

    struct thread_data index_main;
    void *status;
    int i, ttime, rc;

	/* Allocate buffer space */
	buf = (double *)malloc(MAXLEN * sizeof(double));

    /*
     * Explicitly set the pthreads to be joinable 
     */
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
    pthread_mutex_init(&mutexthread, NULL);

    /*
     * Populate the array with random double numbers 
     */
    for (i = 0; i < MAXLEN; i++)
        buf[i] = genrand_int31();

    /*
     * Initialize and set thread detached attribute 
     */
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);

    // ttime=timer();
    clock_t startclock, stopclock;

    startclock = clock();

    /*
     * Fire the first thread 
     */
    index_main.st_idx = 0;
    index_main.en_idx = MAXLEN - 1;
    rc = pthread_create(&first_thread, &attr, parallel_qsort,
                        (void *) &index_main);
    pthread_join(first_thread, &status);

    // ttime=timer() - ttime;

    stopclock = clock();

    // printf("Elapsed time: %f \n",ttime/1000000.0);
    fprintf(stderr, "%s%.2f%s\n", "Time: ",
            (stopclock - startclock) / (float) CLOCKS_PER_SEC, " sec.");

    printf
        ("Total Actual Thread Count = <%d>, Recursion Tree Branches = <%d>\n",
         real_thread_count, thread_count);

    printf("After\n");
    (MAXLEN <= 100) && (print(), 0);    // Print out only to test 
    pthread_mutex_destroy(&mutexthread);
    pthread_attr_destroy(&attr);
	free(buf);
	
    pthread_exit(NULL);
}