37 lines
1.0 KiB
C
37 lines
1.0 KiB
C
#include "interference.h"
|
|
|
|
// Convert a two-dimensional coordinate into a one-dimensional cell index.
|
|
#define PACK(x, y) ((y * SZ) + x)
|
|
|
|
interference_t interference;
|
|
|
|
void interference_init() {
|
|
for (uint8_t y = 0; y < SZ; y++) {
|
|
for (uint8_t x = 0; x < SZ; x++) {
|
|
uint8_t cell = PACK(x, y);
|
|
cellset_t *row = &interference.rows[cell];
|
|
cellset_init(row);
|
|
|
|
// rows
|
|
for (uint8_t ox = 0; ox < SZ; ox++) {
|
|
cellset_add_exclude(row, cell, PACK(ox, y));
|
|
}
|
|
|
|
// columns
|
|
for (uint8_t oy = 0; oy < SZ; oy++) {
|
|
cellset_add_exclude(row, cell, PACK(x, oy));
|
|
}
|
|
|
|
// boxes
|
|
uint8_t box_x = (x / 3) * 3;
|
|
uint8_t box_y = (y / 3) * 3;
|
|
|
|
for (uint8_t oy = box_y; oy < box_y + 3; oy++) {
|
|
for (uint8_t ox = box_x; ox < box_x + 3; ox++) {
|
|
cellset_add_exclude(row, cell, PACK(ox, oy));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|