int main(int argc, char* argv[]) { coord_t c; c.x = 3; c.y = 4; print_coord(c); return 0; }
void ModelObject::print_face(const face * my_face) { for (unsigned int i = 0; i < my_face->coords.size(); i++) { print_coord(my_face->coords[i]); if (i < my_face->coords.size() - 1) std::cout << ", "; } }
int check_results(t_info *info, int found) { int chosen_one; if (found) { chosen_one = closest_index(info); print_coord(info->pos[chosen_one], info); } else { ft_putstr("0 0\n"); return (0); } return (1); }
void ModelObject::print_data() { std::cout.precision(9); for (unsigned int i = 0; i < object->vertices.size(); i++) { std::cout << "\tV: "; print_coord(object->vertices[i]); std::cout << std::endl; } std::cout.precision(9); for (unsigned int i = 0; i < object->faces.size(); i++) { std::cout << "\tF: "; print_face(object->faces[i]); std::cout << std::endl; } }
int backtrack(Puzzle *puz, Solution *sol) { Hist *h; //color_t z, oldn, newn; //dir_t k; if (VB) printf("B: BACKTRACKING TO LAST GUESS\n"); /* Undo up to, but not including, the most recent branch point */ if (undo(puz,sol, 1)) { if (VB) printf("B: CANNOT BACKTRACK\n"); return 1; } if (VB) print_solution(stdout,puz,sol); /* This will be the branch point since undo() backed us up to it */ h= HIST(puz, puz->nhist-1); if (VB || WC(h->cell)) { printf("B: LAST GUESS WAS "); print_coord(stdout,puz,h->cell); printf(" |"); dump_bits(stdout,puz,h->bit); printf("| -> |"); dump_bits(stdout,puz,h->cell->bit); printf("|\n"); } /* If undoing a solved cell, uncount it */ if (h->cell->n == 1) solved_a_cell(puz, h->cell, -1); /* Reset any bits previously set */ #ifdef LIMITCOLORS h->cell->bit[0]= ((~h->cell->bit[0]) & h->bit[0]); #else for (z= 0; z < fbit_size; z++) h->cell->bit[z]= ((~h->cell->bit[z]) & h->bit[z]); #endif h->cell->n= h->n - h->cell->n; /* Since the bits set in h are always a superset of those in h->cell, this should always work */ /* If inverted cell is solved, count it */ if (h->cell->n == 1) solved_a_cell(puz, h->cell, 1); if (VB || WC(h->cell)) { printf("B: INVERTING GUESS TO |"); dump_bits(stdout,puz,h->cell->bit); printf("| (%d)\n",h->cell->n); } /* Now that we've backtracked to it and inverted it, it is no * longer a branch point. If there is no previous history, delete * this node. Otherwise, convert it into a non-branch point. * Next time we backtrack we will just delete it. */ if (puz->nhist == 1) puz->nhist= 0; else h->branch= 0; /* Remove everything from the job list except the lines containing * the inverted cell. */ if (maylinesolve) { flush_jobs(puz); add_jobs(puz, sol, -1, h->cell, 0, h->bit); } backtracks++; return 0; }
int solve(Puzzle *puz, Solution *sol) { Cell *cell; line_t besti, bestj; color_t bestc; int bestnleft; int rc; int sprint_clock= 0, plod_clock= PLOD_INIT; /* One color puzzles are already solved */ if (puz->ncolor < 2) { puz->nsolved= puz->ncells; return 1; } /* Start bookkeeping, if we need it */ if (mayprobe) probe_init(puz,sol); else bookkeeping_on(puz,sol); while (1) { /* Always start with logical solving */ if (VA) printf("A: LINE SOLVING\n"); rc= logic_solve(puz, sol, 0); if (rc > 0) return 1; /* Exit if the puzzle is complete */ if (rc == 0) { /* Logical solving has stalled. */ if (VA) { printf("A: STUCK - Line solving failed\n"); print_solution(stdout,puz,sol); } if (maycontradict) { /* Try a depth-limited search for logical contradictions */ if (VA) printf("A: SEARCHING FOR CONTRADICTIONS\n"); rc= contradict(puz,sol); if (rc > 0) return 1; /* puzzle complete - stop */ if (rc < 0) continue; /* found some - resume logic solving */ /* otherwise, try something else */ } /* Stop if no guessing is allowed */ if (!maybacktrack) return 1; if (hintlog) { printf("STARTING SEARCH: EXPLANATION SHUTTING DOWN...\n"); hintlog= 0; } /* Shut down the exhaustive search once we start searching */ if (maylinesolve) mayexhaust= 0; /* Turn on caching when we first start searching */ if (maycache && !cachelines) { cachelines= 1; init_cache(puz); } if (mayprobe && (!mayguess || sprint_clock <= 0)) { /* Do probing to find best guess to make */ if (VA) printf("A: PROBING\n"); rc= probe(puz, sol, &besti, &bestj, &bestc); if (rc > 0) return 1; /* Stop if accidentally completed the puzzle */ if (rc < 0) continue; /* Resume logic solving if found contradiction */ /* Otherwise, use the guess returned from the probe */ cell= sol->line[0][besti][bestj]; if (VA) { printf("A: PROBING SELECTED "); print_coord(stdout,puz,cell); printf(" COLOR %d\n",bestc); } /* If a lot of probes have not been finding contradictions, * consider triggering sprint mode */ if (mayguess && --plod_clock <= 0) { float rate= probe_rate(); if (rate >= .12) { /* More than 10% have failed to find contradiction, * so try heuristic searching for a while */ bookkeeping_on(puz,sol); sprint_clock= SPRINT_LENGTH; nsprint++; /*printf("STARTING SPRINT - probe rate=%.4f\n",rate);*/ } else { /* Success rate of probing is still high. Keep on * trucking. */ plod_clock= PLOD_LENGTH; nplod++; /*printf("CONTINUING PLOD - probe rate=%.4f\n", rate);*/ } } } else { /* Old guessing algorithm. Use heuristics to make a guess */ cell= pick_a_cell(puz, sol); if (cell == NULL) return 0; bestc= (*pick_color)(puz,sol,cell); if (VA || WC(cell->line[0],cell->line[1])) { printf("A: GUESSING SELECTED "); print_coord(stdout,puz,cell); printf(" COLOR %d\n",bestc); } if (mayprobe && --sprint_clock <= 0) { /* If we have reached the end of our sprint, try plodding * again. */ probe_init(puz,sol); plod_clock= PLOD_LENGTH; nplod++; /*printf("ENDING SPRINT\n");*/ } } guess_cell(puz, sol, cell, bestc); guesses++; } else { /* We have hit a contradiction - try backtracking */ if (VA) printf("A: STUCK ON CONTRADICTION - BACKTRACKING\n"); guesses++; /* Back up to last guess point, and invert that guess */ if (backtrack(puz,sol)) /* Nothing to backtrack to - puzzle has no solution */ return 0; if (VB) print_solution(stdout,puz,sol); if (VB) dump_history(stdout, puz, VV); } } }