int main() { board_position *spot; value *now; int i,j; sudoku_board * f; f = (sudoku_board *) sudokucreator(); srand(time(NULL)); random_board(f); /*j=0; for(i=0;i<1000;i++) { value_filler(f); j +=random_board(f); } printf("%d out of %i",j,i); *///generic_board(f); //spot = (board_position *) get_unfilled_space(f); //fill_with_random_sudoku_value(spot); //remove_same_from_row(f,spot); /*for(i=0;i<10000000;i++) { fill_with_random_sudoku_value(spot); j = spot->value+j; } printf("j/%lf = %lf",i,j/i); fflush(stdout); */ /* printf("\nRemoving %d\n",spot->value); for(i=0;i<9;i++) { printf("\n %d ",i); for(now=f->values[i][spot->j]->first; now != NULL; now = (value *) now->next) { printf("%d",now->available); } } */ //generic_board(f); boardprint(f); return 0; }
int main(int argc, string argv[]) { // ensure proper usage if (argc != 2) { printf("Usage: fifteen d\n"); return 1; } // ensure valid dimensions d = atoi(argv[1]); if (d < DIM_MIN || d > DIM_MAX) { printf("Board must be between %i x %i and %i x %i, inclusive.\n", DIM_MIN, DIM_MIN, DIM_MAX, DIM_MAX); return 2; } // open log FILE* file = fopen("log.txt", "w"); if (file == NULL) { return 3; } // GOD_MODE activated? bool gm = false; // greet user with instructions greet(); // initialize the board init(); // randomize board random_board(); // accept moves until game is won while (true) { // clear the screen clear(); // draw the current state of the board draw(); // log the current state of the board (for testing) for (int i = 0; i < d; i++) { for (int j = 0; j < d; j++) { fprintf(file, "%i", board[i][j]); if (j < d - 1) { fprintf(file, "|"); } } fprintf(file, "\n"); } fflush(file); // check for win if (won()) { if (gm) printf("That's easy! (;\n"); else printf("ftw!\n"); break; } // Get user input int tile; do { // prompt for move printf("Tile to move: "); char* input = GetString(); // start the GOD mode if (strcmp(input, GOD_MODE) == 0) { tile = 0; if (d > 4) { printf("\nThat is too big for me!\n"); usleep(500000); break; } gm = true; solve(); free(input); break; } else if (strcmp(input, NEW_GAME) == 0) { random_board(); free(input); break; } else { tile = atoi(input); } if (tile > 0 && tile < d*d) { free(input); break; } } while (1); // log move (for testing) fprintf(file, "%i\n", tile); fflush(file); // move if possible, else report illegality if (tile > 0) { if (!move(tile)) { printf("\nIllegal move.\n"); usleep(500000); } } // sleep thread for animation's sake usleep(500000); } // close log fclose(file); // success return 0; }