Ejemplo n.º 1
0
gchar *
mix_bg_fg (GtkWidget * win, const gchar * state, float alpha, float beta)
{
    GdkColor color, bgColor, fgColor;
    GtkStyle *style;
    gchar *s;
    gint n;

    TRACE ("entering mix_bg_fg_ui");

    g_return_val_if_fail (win != NULL, NULL);
    g_return_val_if_fail (GTK_IS_WIDGET (win), NULL);
    g_return_val_if_fail (GTK_WIDGET_REALIZED (win), NULL);

    style = get_ui_style (win);
    n = state_value (state);

    bgColor = query_color (win, style->bg[n]);
    fgColor = query_color (win, style->fg[n]);
    color = shade (mix (bgColor, fgColor, alpha), beta);
    s = print_color (win, color);

    TRACE ("mix_bg_fg[%s]=%s", state, s);
    return (s);
}
// Private functions
double Anneal::AcceptRatioNow(int sequence_size) const
{
    std::uniform_real_distribution<double> distribution(0.0, 1.0);
    int accept_state_num = 0;
    int total_state_num = 0;

    std::vector<Path> state_sequence(sequence_size);
    std::vector<double> state_value(sequence_size);
    for (int i = 0; i < sequence_size; i++)
    {
        state_sequence[i] = std::move(GenerateRandomPath());
        state_value[i] = Evaluate(state_sequence[i]);
    }

    for (int i = 0; i < sequence_size; i++)
    {
        for (int j = 0; j < sequence_size; j++)
        {
            total_state_num++;
            if (state_value[j] <= state_value[i] ||
                distribution(generator_) <
                    TransitionProbability(state_value[i], state_value[j]))
                    accept_state_num++;
        }
    }
    return static_cast<double>(accept_state_num) /
           static_cast<double>(total_state_num);
}
void history_processFlags(history_t* past)
// to be called after completely recording this history, before calculating any values.
{
    state_t* flagState = dict_lookup(past->states, "flags");
    state_t* nextState;
    U16 nextFlags, toggledFlags, currentFlags = (U16)flagState->value;
    while (flagState->next)
    {
    	nextState = flagState->next;
    	nextFlags = (U16)nextState->value;
    	toggledFlags = currentFlags ^ nextFlags;
    	if (toggledFlags & IF_FIXED_ALIGNMENT)
    	{ // the IF_FIXED_ALIGNMENT bit will change in the next state
    	    if (nextFlags & IF_FIXED_ALIGNMENT)
    	    { // the IF_FIXED_ALIGNMENT bit will be set
    	    	int onFrame = nextState->frame;
	    	state_t* rotations = dict_lookup(past->states, "rotate");
	    	nextState->params.instanceAngle = state_value(rotations, onFrame);
	    	state_t* resetRotate = state_new(onFrame, CF_JUMP, 0, 0);
	    	state_insert(rotations, resetRotate);
	    	if (onFrame == past->firstFrame)
	    	    onFrame++;
	    	state_t *x, *y;
	    	float dx, dy;
	    	do
	    	{
    	    	    x = dict_lookup(past->states, "x");
    	    	    dx = state_tangent(x, onFrame, T_SYMMETRIC);
    	    	    y = dict_lookup(past->states, "y");
    	    	    dy = state_tangent(y, onFrame, T_SYMMETRIC);
    	    	    onFrame++;
	    	}
	    	while (dx == 0 && dy == 0 && onFrame < past->lastFrame);
	    	if (onFrame == past->lastFrame)
    	    	    nextState->params.pathAngle = 0;
	    	else
    	    	    nextState->params.pathAngle = getAngle(dx, dy) / M_PI * 180;
    	    }
    	    else // the IF_FIXED_ALIGNMENT bit will be reset
    	    {
    	    	int offFrame = nextState->frame;
	    	state_t* rotations = dict_lookup(past->states, "rotate");
	    	state_t* setRotate = state_new(offFrame, CF_JUMP, flagState->params.instanceAngle + state_value(rotations, offFrame), 0);
	    	state_insert(rotations, setRotate);
    	    }
    	}
    	else // the IF_FIXED_ALIGNMENT bit will not change but some processing may be
    	     // required just the same
    	{
    	    if (nextFlags & IF_FIXED_ALIGNMENT)
    	    {
    	    	nextState->params.instanceAngle = flagState->params.instanceAngle;
    	    	nextState->params.pathAngle = flagState->params.pathAngle;
    	    }
    	}
// and so on for all the other bits.
    	flagState = nextState;
    	currentFlags = nextFlags;
	}
}
float history_value(history_t* past, U16 frame, char* parameter)
{
    state_t* state = dict_lookup(past->states, parameter);
    if (state)	//should always be true.
	return state_value(state, frame);
    syntaxerror("no history found to get a value for parameter %s.\n", parameter);
    return 0;
}
Ejemplo n.º 5
0
double GeometricRandomPlayout::eval(board b){
	int steps =1;
	std::uniform_real_distribution<double> unif(0, 1);
	while(!b.is_ended() && unif(rng)<(1.0/steps++) ){
		zet z= select_random_move(b);
		b=b+z;
	}
	return state_value(b);

}
Ejemplo n.º 6
0
DSME_HANDLER(DSM_MSGTYPE_TELINIT, conn, msg)
{
    const char* runlevel = DSMEMSG_EXTRA(msg);
    char*       sender   = endpoint_name(conn);

    dsme_log(LOG_NOTICE,
             PFIX"got telinit '%s' from %s",
             runlevel ? runlevel : "(null)",
             sender   ? sender   : "(unknown)");
    free(sender);

    if (runlevel) {
        telinit_handler(state_value(runlevel))(conn);
    }
}
float state_tangent(state_t* modification, U16 frame, int tangent)
{
    float deltaFrame = 0.1;
    switch (tangent)
{
    	case T_BEFORE:
    	    return (state_value(modification, frame) - state_value(modification, frame - deltaFrame)) / deltaFrame;
    	case T_AFTER:
    	    return (state_value(modification, frame + deltaFrame) - state_value(modification, frame)) / deltaFrame;
    	default:
    	    return (state_value(modification, frame + deltaFrame) - state_value(modification, frame - deltaFrame)) / (2 * deltaFrame);
    }
}
Ejemplo n.º 8
0
static GdkGC *
_getUIStyle_gc (const gchar * name, const gchar * state, GtkStyle * style)
{
    GdkGC *gc;
    gint n, m;

    g_return_val_if_fail (state != NULL, NULL);
    g_return_val_if_fail (name != NULL, NULL);
    g_return_val_if_fail (style != NULL, NULL);
    g_return_val_if_fail (GTK_IS_STYLE(style), NULL);

    n = state_value (state);
    m = name_value (name);

    switch (m)
    {
        case GTKSTYLE_FG:
            gc = style->fg_gc[n];
            break;
        case GTKSTYLE_BG:
            gc = style->bg_gc[n];
            break;
        case GTKSTYLE_TEXT:
            gc = style->text_gc[n];
            break;
        case GTKSTYLE_BASE:
            gc = style->base_gc[n];
            break;
        case GTKSTYLE_LIGHT:
            gc = style->light_gc[n];
            break;
        case GTKSTYLE_DARK:
            gc = style->dark_gc[n];
            break;
        default:
        case GTKSTYLE_MID:
            gc = style->mid_gc[n];
            break;
    }

    return (gc);
}
//  Print state of istream.
void Foam::state(istream& from, const string& s)
{
    state_value isState = state_value(from.rdstate());

    switch (isState)
    {
        case _good:                // Do not anything 'unusual'.
            break;

        case _eof:
            Info
                << "Input stream: premature end of stream", s << endl;
            Info<< "If all else well, possibly a quote mark missing" << endl;
        break;

        case _fail:
            SeriousErrorIn("state(istream& from, const string& s)")
                << "Input stream failure (bad format?)", s << endl;
            Info<< "If all else well, possibly a quote mark missing" << endl;
        break;

        case (_fail + _eof) :
            SeriousErrorIn("state(istream& from, const string& s)")
                << "Input stream failure and end of stream", s << endl;
            Info<< "If all else well, possibly a quote mark missing" << endl;
        break;

        case _bad:
            SeriousErrorIn("state(istream& from, const string& s)")
                << "Serious input stream failure", s << endl;
        break;

        default:
            SeriousErrorIn("state(istream& from, const string& s)")
                << "Input stream failure of unknown type", s << endl;
            SeriousErrorIn("state(istream& from, const string& s)")
                << "Stream state value = ", isState << endl;
        break;
    }

    return;
}
Ejemplo n.º 10
0
static gchar *
print_rc_style (GtkWidget * win, const gchar * name, const gchar * state,
                GtkStyle * style)
{
    gchar *s;
    gint n, m;

    g_return_val_if_fail (state != NULL, NULL);
    g_return_val_if_fail (name != NULL, NULL);

    n = state_value (state);
    m = name_value (name);

    switch (m)
    {
        case GTKSTYLE_FG:
            s = print_colors (win, style->fg, n);
            break;
        case GTKSTYLE_BG:
            s = print_colors (win, style->bg, n);
            break;
        case GTKSTYLE_TEXT:
            s = print_colors (win, style->text, n);
            break;
        case GTKSTYLE_BASE:
            s = print_colors (win, style->base, n);
            break;
        case GTKSTYLE_LIGHT:
            s = print_colors (win, style->light, n);
            break;
        case GTKSTYLE_DARK:
            s = print_colors (win, style->dark, n);
            break;
        default:
        case GTKSTYLE_MID:
            s = print_colors (win, style->mid, n);
            break;
    }
    return (s);
}
void Foam::state(ostream& to, const string& s)
{
    state_value osState = state_value(to.rdstate());

    switch (osState)
    {
        case _good:                // Do not anything 'unusual'.
            break;

        case _eof:
            Info
                << "Output stream: premature end of stream", s << endl;
        break;

        case _fail:
            SeriousErrorIn("state(ostream& to, const string& s)")
                << "Output stream failure (bad format?)", s << endl;
        break;

        case (_fail + _eof) :
         SeriousErrorIn("state(ostream& to, const string& s)")
             << "Output stream failure and end of stream", s << endl;
        break;

        case _bad:
            SeriousErrorIn("state(ostream& to, const string& s)")
                << "Serious output stream failure", s << endl;
        break;

        default:
            SeriousErrorIn("state(ostream& to, const string& s)")
                << "Output stream failure of unknown type", s << endl
                << "Stream state value = ", osState << endl;
        break;
    }

    return;
}
float history_rotateValue(history_t* past, U16 frame)
{
    state_t* rotations = dict_lookup(past->states, "rotate");
    if (rotations)	//should always be true.
    {
    	float angle = state_value(rotations, frame);
    	state_t* flags = dict_lookup(past->states, "flags");
    	U16 currentflags = state_value(flags, frame);
    	if (currentflags & IF_FIXED_ALIGNMENT)
    	{
	    flags = state_at(flags, frame);
	    if (frame == past->firstFrame)
	    	frame++;
	    state_t *x, *y;
	    float dx, dy, pathAngle;
	    do
	    {
    	    	x = dict_lookup(past->states, "x");
    	    	dx = state_value(x, frame) - state_value(x, frame - 1);
    	    	y = dict_lookup(past->states, "y");
    	    	dy = state_value(y, frame) - state_value(y, frame - 1);
    	    	frame--;
	    }
	    while (dx == 0 && dy == 0 && frame > past->firstFrame);
	    if (frame == past->firstFrame)
    	    	pathAngle = 0;
	    else
    	    	pathAngle = getAngle(dx, dy) / M_PI * 180;
    	    return angle + flags->params.instanceAngle + pathAngle - flags->params.pathAngle;
    	}
	else
	    return angle;
    }
    syntaxerror("no history found to get a value for parameter rotate.\n");
	return 0;
}