コード例 #1
0
ファイル: main.c プロジェクト: starapple/HeadsUpPoker
static Eval_T get_handstrength(Hand_T cards1, Hand_T cards2) {
    int numcards = count_cards(cards1) + count_cards(cards2);
    Hand_T cards; CombineHands(cards, cards1, cards2);
    switch( numcards ) {
    case 5: return Hand_5_Eval(cards);
    case 6: return Hand_6_Eval(cards);
    case 7: return Hand_7_Eval(cards);
    }
    fprintf(stderr, "WARN: unable to eval %d cards\n", numcards);
    return 0;
}
コード例 #2
0
ファイル: main.c プロジェクト: starapple/HeadsUpPoker
static void parse_matchinfo(const char *key, const char *value, struct PokerState *state) {
    if( strcmp(key, "round") == 0 ) {
        state->info.round = atoi(value);
        state->boardsize = 0;
        state->sidepots = 0;
    } else if( strcmp(key, "smallBlind") == 0 ) {
        state->info.smallblind = atoi(value);
    } else if( strcmp(key, "bigBlind") == 0 ) {
        state->info.bigblind = atoi(value);
    } else if( strcmp(key, "pot") == 0 ) {
        state->potsize = atoi(value);
    } else if( strcmp(key, "table") == 0 ) {
        state->board = parse_cards(value);
        state->boardsize = count_cards(state->board);
    } else if( strcmp(key, "sidepots") == 0 ) {
        state->currentbet = 0;
        state->sidepots = parse_pots(value, state->sidepot, MAX_SIDEPOTS);
        if( state->sidepots > 0 ) {
            state->currentbet = state->sidepot[0];
        }
    } else if( strcmp(key, "onButton") == 0 ) {
        if( state->settings.myname == NULL ) {
            fprintf(stderr, "WARN: got ``onButton'', but don't know my name yet\n");
        } else {
            int mybutton = (strcmp(value,state->settings.myname)==0);
            state->hero.onbutton = mybutton;
            state->villain.onbutton = (!mybutton);
        }
    }
}
コード例 #3
0
ファイル: sgen-stw.c プロジェクト: Adamcbrz/mono
/* LOCKING: assumes the GC lock is held */
int
sgen_stop_world (int generation)
{
	TV_DECLARE (end_handshake);
	int count, dead;

	mono_profiler_gc_event (MONO_GC_EVENT_PRE_STOP_WORLD, generation);
	MONO_GC_WORLD_STOP_BEGIN ();
	binary_protocol_world_stopping (sgen_timestamp ());
	acquire_gc_locks ();

	/* We start to scan after locks are taking, this ensures we won't be interrupted. */
	sgen_process_togglerefs ();

	update_current_thread_stack (&count);

	sgen_global_stop_count++;
	SGEN_LOG (3, "stopping world n %d from %p %p", sgen_global_stop_count, mono_thread_info_current (), (gpointer)mono_native_thread_id_get ());
	TV_GETTIME (stop_world_time);
	count = sgen_thread_handshake (TRUE);
	dead = restart_threads_until_none_in_managed_allocator ();
	if (count < dead)
		g_error ("More threads have died (%d) that been initialy suspended %d", dead, count);
	count -= dead;

	SGEN_LOG (3, "world stopped %d thread(s)", count);
	mono_profiler_gc_event (MONO_GC_EVENT_POST_STOP_WORLD, generation);
	MONO_GC_WORLD_STOP_END ();
	if (binary_protocol_is_enabled ()) {
		long long major_total, major_marked, los_total, los_marked;
		count_cards (&major_total, &major_marked, &los_total, &los_marked);
		binary_protocol_world_stopped (sgen_timestamp (), major_total, major_marked, los_total, los_marked);
	}

	TV_GETTIME (end_handshake);
	time_stop_world += TV_ELAPSED (stop_world_time, end_handshake);

	sgen_memgov_collection_start (generation);
	if (sgen_need_bridge_processing ())
		sgen_bridge_reset_data ();

	return count;
}
コード例 #4
0
ファイル: sgen-stw.c プロジェクト: Adamcbrz/mono
/* LOCKING: assumes the GC lock is held */
int
sgen_restart_world (int generation, GGTimingInfo *timing)
{
	int count;
	SgenThreadInfo *info;
	TV_DECLARE (end_sw);
	TV_DECLARE (start_handshake);
	TV_DECLARE (end_bridge);
	unsigned long usec, bridge_usec;

	if (binary_protocol_is_enabled ()) {
		long long major_total, major_marked, los_total, los_marked;
		count_cards (&major_total, &major_marked, &los_total, &los_marked);
		binary_protocol_world_restarting (generation, sgen_timestamp (), major_total, major_marked, los_total, los_marked);
	}

	/* notify the profiler of the leftovers */
	/* FIXME this is the wrong spot at we can STW for non collection reasons. */
	if (G_UNLIKELY (mono_profiler_events & MONO_PROFILE_GC_MOVES))
		sgen_gc_event_moves ();
	mono_profiler_gc_event (MONO_GC_EVENT_PRE_START_WORLD, generation);
	MONO_GC_WORLD_RESTART_BEGIN (generation);
	FOREACH_THREAD (info) {
		info->stack_start = NULL;
#ifdef USE_MONO_CTX
		memset (&info->ctx, 0, sizeof (MonoContext));
#else
		memset (&info->regs, 0, sizeof (info->regs));
#endif
	} END_FOREACH_THREAD

	TV_GETTIME (start_handshake);
	count = sgen_thread_handshake (FALSE);
	TV_GETTIME (end_sw);
	time_restart_world += TV_ELAPSED (start_handshake, end_sw);
	usec = TV_ELAPSED (stop_world_time, end_sw);
	max_pause_usec = MAX (usec, max_pause_usec);
	SGEN_LOG (2, "restarted %d thread(s) (pause time: %d usec, max: %d)", count, (int)usec, (int)max_pause_usec);
	mono_profiler_gc_event (MONO_GC_EVENT_POST_START_WORLD, generation);
	MONO_GC_WORLD_RESTART_END (generation);
	binary_protocol_world_restarted (generation, sgen_timestamp ());

	/*
	 * We must release the thread info suspend lock after doing
	 * the thread handshake.  Otherwise, if the GC stops the world
	 * and a thread is in the process of starting up, but has not
	 * yet registered (it's not in the thread_list), it is
	 * possible that the thread does register while the world is
	 * stopped.  When restarting the GC will then try to restart
	 * said thread, but since it never got the suspend signal, it
	 * cannot answer the restart signal, so a deadlock results.
	 */
	release_gc_locks ();

	sgen_try_free_some_memory = TRUE;

	if (sgen_need_bridge_processing ())
		sgen_bridge_processing_finish (generation);

	TV_GETTIME (end_bridge);
	bridge_usec = TV_ELAPSED (end_sw, end_bridge);

	if (timing) {
		timing [0].stw_time = usec;
		timing [0].bridge_time = bridge_usec;
	}
	
	sgen_memgov_collection_end (generation, timing, timing ? 2 : 0);

	return count;
}