Update roofus.c

This commit is contained in:
Racoonicorn 2016-12-24 12:27:20 +01:00 committed by GitHub
parent 609942c44c
commit 6fd15c56cc
1 changed files with 38 additions and 22 deletions

View File

@ -1,4 +1,4 @@
#define VERSION "0.20" #define VERSION "0.21"
#define N 9 #define N 9
#include <stdio.h> #include <stdio.h>
@ -33,7 +33,7 @@ int main () {
menu (); menu ();
} }
fclose (fp); fclose (fp);
printf ("\n\n\n\nv%s", VERSION); printf ("\n\n\n\nRoofus v%s", VERSION);
return 0; return 0;
} }
@ -72,34 +72,50 @@ void settings () {
} }
void ranking () { void ranking () {
int i = 0, j ,a; int i = 0, j;
int best[1000] = {0}; struct res {
int grid_val[1000]; int best;
time_t res_time[1000]; int grid;
time_t res_time;
};
struct res result[1000];
struct res temp;
char *time_string[1000]; char *time_string[1000];
system("clear"); int grid_val = 1;
int printed;
rewind (fp); rewind (fp);
getchar (); getchar ();
do { do {
fscanf (fp, "%d %li %d", &best[i], &res_time[i], &grid_val[i]); fscanf (fp, "%d %li %d", &result[i].best, &result[i].res_time, &result[i].grid);
i++; i++;
} while (best[i-1] > 0); } while (result[i-1].best > 0);
for (i = 0; best[i] != 0; i++) { for (i = 0; result[i].best != 0; i++) {
for (j = i + 1; best[j] !=0; j++) { for (j = i + 1; result[j].best != 0; j++) {
if (best[i] > best[j]) { if (result[i].best > result[j].best) {
a = best[i]; temp = result[i];
best[i] = best[j]; result[i] = result[j];
best[j] = a; result[j] = temp;
} }
} }
} }
printf ("Best results: \n\n"); do {
for (i=0; i < 10 && best[i] != 0; i++) { system("clear");
time_string[i] = ctime(&res_time[i]); printf ("Best results: \n\n");
// printf ("#%d: %3d moves\t- %dx%d matrix\t- %s", i + 1, best[i], grid_val[i], grid_val[i], time_string[i]); printed = 0;
printf ("#%d: %3d moves\n", i + 1, best[i]); for (i = 0; result[i+1].best != 0; i++) {
} if ((result[i].grid == grid_val || grid_val == 1) && printed < 10) {
getchar (); time_string[i] = ctime(&result[i].res_time);
printf ("# %d\t%3d moves\t- %dx%d matrix\t- %s", printed + 1, result[i].best, result[i].grid, result[i].grid, time_string[i]);
printed++;
}
}
if (printed == 0) {
printf ("Nothing to show...\n");
}
printf ("\n0: Menu; 3, 5, 7 or 9 to filter by matrix size; 1: No filter ");
scanf ("%d", &grid_val);
getchar();
} while (grid_val != 0);
} }
int play () { int play () {