Sokoban/C: Difference between revisions

m
replace asserts
(various bugs)
m (replace asserts)
Line 5:
#include <unistd.h>
#include <stdint.h>
#include <assert.h>
#include <stdbool.h>
 
#define ensure(x) { if (!(x)) printf("\nabort: line %d\n", __LINE__); }
 
int w, h, n_boxes;
Line 41 ⟶ 42:
if (!block_head) {
block_size *= 2;
state_t *p = malloc(block_size * state_size);
ensure(p = malloc(block_size * state_size));
alloced += block_size - 1;
assert(p);
p->next = block_root;
block_root = p;
Line 92 ⟶ 93:
{
w = x, h = y;
assertensure( board = calloc(w * h, sizeof(uint8_t)) );
assertensure( goals = calloc(w * h, sizeof(uint8_t)) );
assertensure( live = calloc(w * h, sizeof(uint8_t)) );
assertensure( dist = calloc(w * h, sizeof(int)) );
 
n_boxes = 0;
Line 181 ⟶ 182:
fill_limit *= 4;
}
 
buckets = realloc(buckets, sizeof(state_t*) * hash_size);
assert(buckets);
 
// rehash
ensure(buckets = realloc(buckets, sizeof(state_t*) * hash_size));
memset(buckets + old_size, 0, sizeof(state_t*) * (hash_size - old_size));
 
Line 236 ⟶ 235:
}
 
inline bool success(const state_t *s)
{
for (int i = 1; i <= n_boxes; i++)
Anonymous user