Reorganizing the code to make more sense.
This commit is contained in:
4 files changed
+65
-44
No files matched your search
+5
-41
@@ -58,49 +58,13 @@ int32_t node_pool_usage() {
|
||||
return pool_ptr;
|
||||
}
|
||||
|
||||
static void make_move(char move, Node* curr) {
|
||||
int128_t na = curr->a, nb = curr->b, nc = curr->c;
|
||||
|
||||
/* Calculate the new triplet based on the move type */
|
||||
if (move == 'A') {
|
||||
na = 2 * (curr->b + curr->c) - curr->a;
|
||||
} else if (move == 'B') {
|
||||
nb = 2 * (curr->a + curr->c) - curr->b;
|
||||
} else if (move == 'C') {
|
||||
nc = 2 * (curr->a + curr->b) - curr->c;
|
||||
}
|
||||
|
||||
/* Validation and Enqueue */
|
||||
if (safe_val(na) && safe_val(nb) && safe_val(nc)) {
|
||||
if (visit_and_mark(na, nb, nc)) {
|
||||
if (pool_ptr >= pool_capacity) return; /* Pool safety */
|
||||
Node* n = &pool[pool_ptr++];
|
||||
n->a = na; n->b = nb; n->c = nc;
|
||||
n->move = move;
|
||||
n->parent = curr;
|
||||
n->next = NULL;
|
||||
queue_push(n);
|
||||
}
|
||||
}
|
||||
int32_t node_pool_capacity() {
|
||||
return pool_capacity;
|
||||
}
|
||||
|
||||
void try_push_children(Node* curr) {
|
||||
char last = curr->move;
|
||||
|
||||
if (last == '\0') {
|
||||
make_move('A', curr);
|
||||
make_move('B', curr);
|
||||
make_move('C', curr);
|
||||
} else if (last == 'A') {
|
||||
make_move('C', curr);
|
||||
make_move('B', curr);
|
||||
} else if (last == 'B') {
|
||||
make_move('C', curr);
|
||||
make_move('A', curr);
|
||||
} else if (last == 'C') {
|
||||
make_move('B', curr);
|
||||
make_move('A', curr);
|
||||
}
|
||||
Node* node_pool_next() {
|
||||
if (pool_ptr >= pool_capacity) return NULL; /* Pool safety */
|
||||
return &pool[pool_ptr++];
|
||||
}
|
||||
|
||||
bool visit_and_mark(int128_t a, int128_t b, int128_t c) {
|
||||
|
||||
Reference in new issue
Block a user