Esempio n. 1
0
void init_buttons(uint16_t grows, uint16_t gcolumns, uint16_t width, uint16_t bombs) {
    
    free(lefts);
    free(tops);
    free(button_arr);

    xcount = 0;
    ycount = -1;
    button_posx = 0;
    button_posy = 0;
    game_state = 1;
    button_col = GRAY;
    def_button_col = GRAY;
    button_width =width;
    rows = grows;
    columns = gcolumns;
    flags = bombs;
    maxflags = bombs;

    lefts = (uint16_t**) Make2DIntArray(rows, columns);
    tops = (uint16_t**) Make2DIntArray(rows, columns);
    button_arr = (button**) Make2DButtonArray(rows, columns);

}
Esempio n. 2
0
/* 
 * Note that this will allocate space for the result, and you will need 
 * to free it yourself to avoid a memory leak. 
 */
int GetLCS(char* a, char* b, char* lcs) {
	int n = strlen(a);
	int m = strlen(b);

	int** S = Make2DIntArray(n+1,m+1);
	int** R = Make2DIntArray(n+1,m+1);

	int ii;
	int jj;

	int i;

	int pos;


	/* It is important to use <=, not <.  The next two for-loops are initialization */
	for(ii = 0; ii <= n; ++ii) {
		S[ii][0] = 0;
		R[ii][0] = UP;
	}
	for(jj = 0; jj <= m; ++jj) {
		S[0][jj] = 0;
		R[0][jj] = LEFT;
	}



	/* This is the main dynamic programming loop that computes the score and */
	/* backtracking arrays. */
	for(ii = 1; ii <= n; ++ii) {
		for(jj = 1; jj <= m; ++jj) { 

			if( a[ii-1] == b[jj-1] ) {
				S[ii][jj] = S[ii-1][jj-1] + 1;
				R[ii][jj] = UP_AND_LEFT;
			}

			else {
				S[ii][jj] = S[ii-1][jj-1] + 0;
				R[ii][jj] = NEITHER;
			}

			if( S[ii-1][jj] >= S[ii][jj] ) {	
				S[ii][jj] = S[ii-1][jj];
				R[ii][jj] = UP;
			}

			if( S[ii][jj-1] >= S[ii][jj] ) {
				S[ii][jj] = S[ii][jj-1];
				R[ii][jj] = LEFT;
			}
		}
	}

	/* The length of the longest substring is S[n][m] */
	ii = n; 
	jj = m;
	pos = S[ii][jj];
	lcs[pos--] = '\0';


	/* Trace the backtracking matrix. */
	while( ii > 0 || jj > 0 ) {
		if( R[ii][jj] == UP_AND_LEFT ) {
			ii--;
			jj--;
			lcs[pos--] = a[ii];
		}
	
		else if( R[ii][jj] == UP ) {
			ii--;
		}

		else if( R[ii][jj] == LEFT ) {
			jj--;
		}
	}


	for (i = 0; i < n+1; i++){    
		free(S[i]);
		free(R[i]); 
	}
	free(S);
	free(R);
}