38 lines
No EOL
1.1 KiB
C
38 lines
No EOL
1.1 KiB
C
#include <stdlib.h>
|
|
#include "../include/utils.h"
|
|
#include "../include/generator.h" // add you are GameBoard definition
|
|
static unsigned int next = 1;
|
|
|
|
void init_random(unsigned int seed) {
|
|
next = seed;
|
|
}
|
|
|
|
int random_int(int min, int max) {
|
|
next = next * 1103515245 + 12345;
|
|
return min + (int)((next / 65536) % (max - min + 1));
|
|
}
|
|
|
|
void set_cell(struct GameBoard *board, uint8_t x, uint8_t y, uint8_t value) {
|
|
board->cells[y * board->width + x] = value;
|
|
}
|
|
|
|
uint8_t get_cell(const struct GameBoard *board, uint8_t x, uint8_t y) {
|
|
return board->cells[y * board->width + x];
|
|
}
|
|
|
|
int is_valid_coord(const struct GameBoard *board, int8_t x, int8_t y) {
|
|
return x >= 0 && x < board->width && y >= 0 && y < board->height;
|
|
}
|
|
|
|
Point get_symmetric_point(const struct GameBoard *board, Point center, Point p) {
|
|
(void)board; // ado you are suppressed
|
|
Point sym;
|
|
sym.x = 2 * center.x - p.x;
|
|
sym.y = 2 * center.y - p.y;
|
|
return sym;
|
|
}
|
|
|
|
int is_symmetric(const struct GameBoard *board, Point center, Point p1, Point p2) {
|
|
Point sym = get_symmetric_point(board, center, p1);
|
|
return sym.x == p2.x && sym.y == p2.y;
|
|
} |