当前位置: 首页>>代码示例>>C++>>正文


C++ Puzzle::resetCandidates方法代码示例

本文整理汇总了C++中Puzzle::resetCandidates方法的典型用法代码示例。如果您正苦于以下问题:C++ Puzzle::resetCandidates方法的具体用法?C++ Puzzle::resetCandidates怎么用?C++ Puzzle::resetCandidates使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Puzzle的用法示例。


在下文中一共展示了Puzzle::resetCandidates方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main


//.........这里部分代码省略.........
    //printf("step 1\n");
    // step 1
    if (hasCandidate) {
      //printf("step 3\n");
      // step 3
      bool succeeded;
      if (p.assign(p.getCurrentRow(), p.getCurrentCol())) {
        if (testLevel > 0) 
          printf("step 3: on (%i, %i), assigned %i\n", p.getCurrentRow(), p.getCurrentCol(), p.getCurrentAssigned(p.getCurrentRow(), p.getCurrentCol()));
        //printf("step 3: assignment succeeded\n");
        //printf("calling updateNeighborConflicts with %i, %i, %i\n", p->getCurrentRow(), p->getCurrentCol(), p->getCurrentAssigned(p->getCurrentRow(), p->getCurrentCol()));
        //printf("pre-assign candidate list: \n"); 
        //p->printInitCandidates();
        // deprecated
        //p->updateNeighborConflicts(p->getCurrentRow(), p->getCurrentCol(), p->getCurrentAssigned(p->getCurrentRow(), p->getCurrentCol()), true);
        //printf("post-assign candidate list: \n"); 
        //p->printInitCandidates();    
        //printf("step 3: updateNeighborConflicts succeeded\n");
        succeeded = p.checkNeighborAssignments(p.getCurrentRow(), p.getCurrentCol());
      }
      else {
        printf("error: reached slot with no candidates. shouldn't happen. exiting.\n");
        exit(1);
      }

      if (succeeded) {
        //printf("step 5\n");
        // step 5
        if (testLevel > 0) printf("step 5: next slot\n");
        p.nextSlot();
        p.copyCandidates(p.getCurrentRow(), p.getCurrentCol());
      }
      else {
        //printf("step 4\n");
        // step 4
        if (testLevel > 0) 
          printf("step 4: on (%i, %i), unassigning %i\n", p.getCurrentRow(), p.getCurrentCol(), p.getCurrentAssigned(p.getCurrentRow(), p.getCurrentCol()));
        //printf("pre-update candidate list: \n"); 
        //p.printInitCandidates();
        //deprecated
        //p->updateNeighborConflicts(p->getCurrentRow(), p->getCurrentCol(), p->getCurrentAssigned(p->getCurrentRow(), p->getCurrentCol()), false);
        //printf("post-update candidate list: \n"); 
        //p->printInitCandidates();
        p.removeAndInvalidate(p.getCurrentRow(), p.getCurrentCol());
        // loops back to front
      }
    }
    else {
      //printf("step 2\n");
      // step 2
      if (testLevel > 0) printf("step 2: reversing slot\n");
      p.resetCandidates(p.getCurrentRow(), p.getCurrentCol());
      bool reversedSlot = p.prevSlot();

      if (reversedSlot) {
        //printf("step 4\n");
        // step 4
        if (testLevel > 0) 
          printf("step 4: on (%i, %i), unassigning %i\n", p.getCurrentRow(), p.getCurrentCol(), p.getCurrentAssigned(p.getCurrentRow(), p.getCurrentCol()));
        //printf("pre-update candidate list: \n"); 
        //p.printInitCandidates();
        //deprecated
        //p.updateNeighborConflicts(p.getCurrentRow(), p.getCurrentCol(), p.getCurrentAssigned(p.getCurrentRow(), p.getCurrentCol()), false);
        //printf("post-update candidate list: \n"); 
        //p.printInitCandidates();
        p.removeAndInvalidate(p.getCurrentRow(), p.getCurrentCol());
        // loops back to front
      }
      else {
        //printf("step 2 failed\n");
        break;
      }
    }
  }
  
  if (p.isSolved()) {
    printf("solution found!\n");
    p.printGrid();
  }
  else {
    printf("no solution found\n");
  }
  
  
  //printf("deinitializing\n");
  p.deinitialize();
  //printf("deinitialized\n");
  delete2dIntArray(grid, atoi(argv[2]));
  //printf("deleted original array.\n");

  //timer
  double seconds_since_start = difftime( time(0), startTime);
  printf("%f seconds to run program\n", seconds_since_start);

  gettimeofday(&end, NULL);
  seconds  = end.tv_sec  - start.tv_sec;
  useconds = end.tv_usec - start.tv_usec;
  mtime = ((seconds) * 1000 + useconds/1000.0) + 0.5;
  printf("Elapsed time: %ld milliseconds\n", mtime);
}
开发者ID:haotianwang,项目名称:cs194_proj,代码行数:101,代码来源:candidate_vector_sudoku_solver.cpp


注:本文中的Puzzle::resetCandidates方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。