Exemple #1
0
static void cube_loop( void )
{
	cube_clear_screen();
	cube_rotate(xa,ya,za);
	if (zoom_out)
		cube_zoom_out();
	if (zoom_in)
		cube_zoom_in();
	cube_viewport();
	cube_draw();
	xa+=xs;
	if (xa>359)
		xa-=360;
	if (xa<0)
		xa+=360;
	ya+=ys;
	if (ya>359)
		ya-=360;
	if (ya<0)
		ya+=360;
	za+=zs;
	if (za>359)
		za-=360;
	if (za<0)
		za+=360;
}
Exemple #2
0
/* suche gueltiges Labyrinth */
void labyrinth_solve(struct labyrinth *l)
{
    struct cube c;
    char rot, rot_count;
    int x_from, y_from, x_to, y_to,
        old_faults, i;
    struct rectangle *r;

    printf("suche %4d x %-4d Labyrinth\n", l->width, l->height);

    r = rectangle_new(l->height, l->width, l->cube_cnt);
    rectangle_fill(l, r);

    rot_count = -1;

    for (i = 0; i < l->try_count; i++) {
        x_from = x_to = rand() % r->width;
        y_from = y_to = rand() % r->height;

        rot = 0;

        if (l->rotation && rand() % 2) {
            rot       = 1;
            rot_count = 1 + rand() % 3;
        }

        while (!rot && x_from == x_to && y_from == y_to
               && r->cube[y_from][x_from].type == r->cube[y_to][x_to].type) {
            x_to = rand() % r->width;
            y_to = rand() % r->height;
        }

        old_faults = r->faults;

        if (rot) {
            cube_rotate(&(r->cube[y_from][x_from]), rot_count);
        } else {
            c                       = r->cube[y_from][x_from];
            r->cube[y_from][x_from] = r->cube[y_to][x_to];
            r->cube[y_to][x_to]     = c;
        }

        rectangle_evaluate(r, l->alley);

        if (r->faults == 0) {
            l->solution = r;
            return;
        }

        if (r->faults <= old_faults)
            continue;

        r->faults = old_faults;

        if (rot) {
            /* wieder zurueck drehen */
            cube_rotate(&(r->cube[y_from][x_from]), 4 - rot_count);
        } else {
            /* wieder zurueck tauschen */
            c                       = r->cube[y_from][x_from];
            r->cube[y_from][x_from] = r->cube[y_to][x_to];
            r->cube[y_to][x_to]     = c;
        }
    }

    if (l->verbose)
        printf("Labyrinth %4d x %-4d hat noch %d Fehler\n",
               l->width, l->height, r->faults);

    rectangle_remove(r);
}