//========================================================================= #define PROGRAMMER "BAHN, William" #define PROG_CODE "bahw" #define COURSE "ECE-1021" #define YEAR (2003) #define TERM "Fall" #define SECTION (0) #define ASSIGNMENT "RWA 5.9" #define REVISION (0) #define TITLE "Real World Application from Section 5.9" #define SUBTITLE "Recursive Tiling" #define EMAIL "wbahn@eas.uccs.edu" #define FILENAME "rwa0509.c" //========================================================================= //== INCLUDE FILES ======================================================== #include // putchar() #include // gotoxy() #include // pow() //== FUNCTION PROTOTYPES ================================================== void PrintHeader(void); void tile(int x, int y, int size, int xm, int ym); int GetOrder(void); int GetXmiss(void); int GetYmiss(void); //== MAIN FUNCTION ======================================================== int main(void) { int order, size; int xmiss, ymiss; PrintHeader(); printf("\n"); // Print a blank line order = GetOrder(); xmiss = GetXmiss(); ymiss = GetYmiss(); size = pow(2, order); tile(60, 9, size, 60+xmiss, 9+ymiss); return(0); } //== SUPPORT FUNCTIONS ==================================================== void PrintHeader(void) { printf("========================================" "=======================================\n"); printf("Course....... %s-%i (%s %i)\n", COURSE, SECTION, TERM, YEAR); printf("Programmer... %s (%s)\n", PROGRAMMER, PROG_CODE); printf("Assignment... %s (Rev %i) (Source Code in %s)\n", ASSIGNMENT, REVISION, FILENAME); printf("Description.. %s\n", TITLE); printf(" %s\n", SUBTITLE); printf("========================================" "=======================================\n"); return; } int GetOrder(void) { int i; printf("Enter the 'n' value (size is 2^n per side): "); scanf("%i", &i); printf("\n"); printf("NOTE: Tile (0,0) is the upper left corner.\n"); printf("\n"); return(i); } int GetXmiss(void) { int i; printf("Enter the x value of the missing tile: "); scanf("%i", &i); return(i); } int GetYmiss(void) { int i; printf("Enter the y value of the missing tile: "); scanf("%i", &i); return(i); } void tile(int x, int y, int size, int xm, int ym) { static char gsym = ' '; int r, c; int xmlh, ymuh; if (2 == size) // Base Case { gsym++; for(r = y; r < y + size; r++ ) for(c = x; c < x + size; c++ ) { gotoxy(c, r); if(! ((c == xm) && (r == ym)) ) putchar(gsym); } } else { size /= 2; // Set offsets xmlh = xm < x + size; // tile is missing in Left Half ymuh = ym < y + size; // Tile is missing from Upper Half // Tile the lateral half that the missing tile is NOT in tile(x+size * xmlh, y, size, x+size, y+size-1); // Upper tile(x+size * xmlh, y+size, size, x+size, y+size); // Lower // Tile the Quadrant with the Missing Tile tile(x+size * !xmlh, y+size * !ymuh, size, xm, ym); // Tile the Quadrant without the Missing Tile tile(x+size * !xmlh, y+size * ymuh, size, x+size-xmlh, y+size-!ymuh); // Tile the Overlap of the three full quadrants tile(x+size-1, y+size-1, 2, x+size-xmlh, y+size-ymuh); } return; }