예제 #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();
}
예제 #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();
}
예제 #3
0
파일: solver.c 프로젝트: jneighbs/wordbrain
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;
}
예제 #4
0
파일: sudoku.c 프로젝트: csanchez256/Sudoku
/* 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;
        }
    }


}