Exemplo n.º 1
0
enum piglit_result
piglit_display(void)
{
	GLboolean pass;
	int srcy = 5;


	glClear(GL_COLOR_BUFFER_BIT);


	/* Test plain old 2D textures.
	 */
	pass = do_row(srcy, 32, 32, GL_TEXTURE_2D);
	srcy += 33 + 5;


	/* Test non-power-of-two 2D textures.
	 */
	if (have_NPOT) {
		pass &= do_row(srcy, 31, 13, GL_TEXTURE_2D);
		srcy += 15;
		pass &= do_row(srcy, 11, 34, GL_TEXTURE_2D);
		srcy += 35 + 5;
	}


	/* Test non-power-of-two 2D textures.
	 */
	if (have_rect) {
		pass &= do_row(srcy, 31, 13, GL_TEXTURE_RECTANGLE_ARB);
		srcy += 14;
		pass &= do_row(srcy, 11, 34, GL_TEXTURE_RECTANGLE_ARB);
		srcy += 35 + 5;
	}

	piglit_present_results();

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Exemplo n.º 2
0
static char *solve_game(game_state *state, game_state *currstate,
			char *ai, char **error)
{
    unsigned char *matrix;
    int w = state->w, h = state->h;
    int i;
    char *ret;
    int done_any, max;
    unsigned char *workspace;
    int *rowdata;

    /*
     * If we already have the solved state in ai, copy it out.
     */
    if (ai)
        return dupstr(ai);

    matrix = snewn(w*h, unsigned char);
    max = max(w, h);
    workspace = snewn(max*3, unsigned char);
    rowdata = snewn(max+1, int);

    memset(matrix, 0, w*h);

    do {
        done_any = 0;
        for (i=0; i<h; i++) {
            memcpy(rowdata, state->rowdata + state->rowsize*(w+i),
                   max*sizeof(int));
            rowdata[state->rowlen[w+i]] = 0;
            done_any |= do_row(workspace, workspace+max, workspace+2*max,
                               matrix+i*w, w, 1, rowdata
#ifdef STANDALONE_SOLVER
			       , NULL, 0, 0 /* never do diagnostics here */
#endif
			       );
        }
        for (i=0; i<w; i++) {
            memcpy(rowdata, state->rowdata + state->rowsize*i, max*sizeof(int));
            rowdata[state->rowlen[i]] = 0;
            done_any |= do_row(workspace, workspace+max, workspace+2*max,
                               matrix+i, h, w, rowdata
#ifdef STANDALONE_SOLVER
			       , NULL, 0, 0 /* never do diagnostics here */
#endif
			       );
        }
    } while (done_any);

    sfree(workspace);
    sfree(rowdata);

    for (i = 0; i < w*h; i++) {
        if (matrix[i] != BLOCK && matrix[i] != DOT) {
            sfree(matrix);
            *error = "Solving algorithm cannot complete this puzzle";
            return NULL;
        }
    }

    ret = snewn(w*h+2, char);
    ret[0] = 'S';
    for (i = 0; i < w*h; i++) {
	assert(matrix[i] == BLOCK || matrix[i] == DOT);
	ret[i+1] = (matrix[i] == BLOCK ? '1' : '0');
    }
    ret[w*h+1] = '\0';

    sfree(matrix);

    return ret;
}
Exemplo n.º 3
0
static unsigned char *generate_soluble(random_state *rs, int w, int h)
{
    int i, j, done_any, ok, ntries, max;
    unsigned char *grid, *matrix, *workspace;
    int *rowdata;

    grid = snewn(w*h, unsigned char);
    matrix = snewn(w*h, unsigned char);
    max = max(w, h);
    workspace = snewn(max*3, unsigned char);
    rowdata = snewn(max+1, int);

    ntries = 0;

    do {
        ntries++;

        generate(rs, w, h, grid);

        /*
         * The game is a bit too easy if any row or column is
         * completely black or completely white. An exception is
         * made for rows/columns that are under 3 squares,
         * otherwise nothing will ever be successfully generated.
         */
        ok = TRUE;
        if (w > 2) {
            for (i = 0; i < h; i++) {
                int colours = 0;
                for (j = 0; j < w; j++)
                    colours |= (grid[i*w+j] == GRID_FULL ? 2 : 1);
                if (colours != 3)
                    ok = FALSE;
            }
        }
        if (h > 2) {
            for (j = 0; j < w; j++) {
                int colours = 0;
                for (i = 0; i < h; i++)
                    colours |= (grid[i*w+j] == GRID_FULL ? 2 : 1);
                if (colours != 3)
                    ok = FALSE;
            }
        }
        if (!ok)
            continue;

        memset(matrix, 0, w*h);

        do {
            done_any = 0;
            for (i=0; i<h; i++) {
                rowdata[compute_rowdata(rowdata, grid+i*w, w, 1)] = 0;
                done_any |= do_row(workspace, workspace+max, workspace+2*max,
                                   matrix+i*w, w, 1, rowdata
#ifdef STANDALONE_SOLVER
				   , NULL, 0, 0 /* never do diagnostics here */
#endif
				   );
            }
            for (i=0; i<w; i++) {
                rowdata[compute_rowdata(rowdata, grid+i, h, w)] = 0;
                done_any |= do_row(workspace, workspace+max, workspace+2*max,
                                   matrix+i, h, w, rowdata
#ifdef STANDALONE_SOLVER
				   , NULL, 0, 0 /* never do diagnostics here */
#endif
				   );
            }
        } while (done_any);

        ok = TRUE;
        for (i=0; i<h; i++) {
            for (j=0; j<w; j++) {
                if (matrix[i*w+j] == UNKNOWN)
                    ok = FALSE;
            }
        }
    } while (!ok);

    sfree(matrix);
    sfree(workspace);
    sfree(rowdata);
    return grid;
}