Esempio n. 1
0
void set_solving(int s) {
  if (s == solving) return;
  if (s) {
    menu->child(0)->label("stop solving");
    puzzle_window->cursor(FL_CURSOR_WAIT);
    Fl::flush();
    if (solvePuzzle()) {solving = 1; changeState(); return;}
  }
  freeSolutions();
  solving = 0;
  menu->child(0)->label("solve it for me");
  puzzle_window->cursor(FL_CURSOR_DEFAULT);
  movingPiece = 0;
  changeState();
}
Esempio n. 2
0
void
toggleSolve(void)
{
    if (solving) {
      freeSolutions();
      solving = 0;
      glutChangeToMenuEntry(1, "Solving", 1);
      glutSetWindowTitle("glpuzzle");
      movingPiece = 0;
    } else {
      glutChangeToMenuEntry(1, "Stop solving", 1);
      glutSetWindowTitle("Solving...");
      if (solvePuzzle()) {
        solving = 1;
      }
    }
    changeState();
    glutPostRedisplay();
}
Esempio n. 3
0
int main(int argc, char *argv[])
{
  FILE *fp = fopen(argv[2], "r");
  int height = countLines(fp);
  int width = numCharsPerLine(fp);
  WBCell **cells = initializeCells(fp, height, width);
  fclose(fp);
  // printCells(cells, height, width);


  FILE *lexiconFilePtr = fopen(LEXICON_FILENAME, "r");
  TreeNode *lexTree = buildTreeFromFile(lexiconFilePtr);
  fclose(lexiconFilePtr);

  solvePuzzle(lexTree, cells, height, width, atoi(argv[1]));

  freeCells(cells, height, width);
  freeTree(lexTree);
  return 0;
}
Esempio n. 4
0
/* Takes an unsolved sudoku matrix and sovles it */
int solvePuzzle(int twoDimArray[][9], int row, int col)
{
    int num;

    /* Check if an empty block exits */
    if(findEmptyBlock(twoDimArray,row,col)) return 1;

    /* not start checking digits 1 - can be placed */
    for(num = 1; num <=9; num++)
    {
        if (safe(twoDimArray,row,col,num))
        {
            twoDimArray[row][col] = num;

            if (solvePuzzle(twoDimArray,row,col)) return 1;
            /* reassing and try again */
            else twoDimArray[row][col] = EMPTY;
        }
    }


}