Exemple #1
0
int main(int argc, char** argv)
{
    FILE * stream = stdin; //Default stream
    SUDOKU_TYPE type = NORMAL_SUDOKU;
    bool result;

    Sudoku *spiel = NULL;
    spiel = malloc(sizeof(Sudoku));

    spiel->field = malloc(sizeof(int) * SUDOKU_SIZE * SUDOKU_SIZE);

    if(!spiel) 
    {
        printf("Speicher konnte nicht angefordert werden.\n");
        return EXIT_FAILURE;
    }

    if(argc > 1)
    {
        if(strstr(argv[1], "x"))
        {
            type = X_SUDOKU;
        }
        if(strstr(argv[1], "h"))
        {
            printf("Verwendung: \n");
            printf("csudoku [x] < file\n");
        }
    }

    spiel->type = type;
    //raetsel aus stream einlesen
    read_sudoku(stream, spiel);
    write_sudoku(stdout, spiel);
    printf("\n");

    //raetsel loesen
    result = solve(spiel);

    printf("Geschaft? %s\n", result? "true":"false");

    //raetsel ausgeben
    write_sudoku(stdout, spiel);
    printf("\n");

    fclose(stream);
    free(spiel);

#ifdef DEBUG
    printf("\n");
    printf("\n");
    printf("\n");
    printf("\n");
    printf("\n");
#endif

    return EXIT_SUCCESS;
}
Exemple #2
0
/********* Main function ************/
int main()
{
	/* Initialise random number generator */
	init_random_seed();
	
	/* read sudoku from a file */
	read_sudoku();			
	/* Fill cells with random digits so each 3 × 3 square contains each of the integers 1 through 9 exactly once */
	fill_rand_cells();


	cost = evaluate_cost();
	printf("COST: %d\n",cost);
	int number_nonfixed=number_nonfixed_cells();
	MCL=pow(number_nonfixed,2);

printf("MCL: %d\n",MCL);


	int m,n;
	int cycle = 0;

while(cost != 0) {
printf("CYCLE: %d\t COST: %d\n",++cycle,cost);

	T=2.5;

	for (n=1;n<=N;n++) 
	{
		for (m=1;m<=MCL;m++)
		{
			choosing_neighbour();

			if (cost==0)
			{
				break;
			}		
		}
		if (cost==0)
		{
			break;
		}
            printf("COST: %d\n",cost);

	T=alpha*T;	
	}
}
	

   printf("FINAL Cost: %d\t CYCLES: %d\n",cost, cycle);
	/* write sudoku */
	write_sudoku();	
}