Skip to content

Commit

Permalink
Cleanup some crap
Browse files Browse the repository at this point in the history
  • Loading branch information
Tadeusz Sośnierz committed May 13, 2012
1 parent be11910 commit 8ae4e8e
Showing 1 changed file with 4 additions and 31 deletions.
35 changes: 4 additions & 31 deletions wyliczator.cpp
Expand Up @@ -50,60 +50,33 @@ void find_segments(struct Point *red, struct Point *green,
int *green_iter, *green_taken;
unsigned long backtracks = 0;

// bit field: does point n already have its pair
green_iter = (int *)calloc(n, sizeof(int));
green_taken = (int *)calloc(n, sizeof(int));
green_iter = (int *)calloc(n, sizeof(int));

while (step < n) {
int i;
// try to mate the next red point with any remaining green point
res[step].start = &red[step];
// pick the smallest green_iter that we haven't checked before
// (initially this is 0)
//printf("## Step %d ##\n", step);

/*printf("Green status (step %d):\n", step);
for (int i = 0; i < n; i++) {
printf("Green [%d]: %s\n", i, green_taken[i] ? "taken"
: "free");
}*/

for (i = green_iter[step]; i < n; i++) {
// skip if it's taken
if (green_taken[i]) {
//printf("Green %d already taken\n", i);
continue;
}
// try to match and check for intersections. Skip if any
if (green_taken[i]) continue;
res[step].end = &green[i];
/*
printf("Trying (%d,%d) and (%d, %d) (step %d): ",
res[step].start->x, res[step].start->y,
res[step].end->x, res[step].end->y,
step);*/
if (find_any_intersection(&res[step], res, step)) {
//puts("It collides");
continue;
}/* else {
puts("It's fine");
}*/
// If we got this far we're fine
}
break;
}
// if the loop was never interrupted then we have to backtrack
// (we didn't find anything working)
if (i == n) {
//puts("Match not found, backtracking");
//printf("Freeing green #%d\n", green_iter[step - 1]);
// backtrack
green_taken[green_iter[step - 1]] = 0;
green_iter[step] = 0;
step--;
green_iter[step]++;
assert(step >= 0);
backtracks++;
} else {
//printf("## Step %d SUCCESSFUL ##\n", step);
//printf("Matched red #%d with green #%d\n", step, i);
green_taken[i] = 1;
green_iter[step] = i;
step++;
Expand Down

0 comments on commit 8ae4e8e

Please sign in to comment.