Implement probes
This commit is contained in:
parent
cf84ae2017
commit
78c0ad81e2
41
puzz.c
41
puzz.c
@ -5,12 +5,16 @@
|
|||||||
|
|
||||||
#include "puzz.h"
|
#include "puzz.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
enum { NO = 0, YES = 1 };
|
||||||
|
|
||||||
static puzz_t soln;
|
static puzz_t soln;
|
||||||
|
static puzz_t scanned;
|
||||||
|
|
||||||
void gen(void)
|
void gen(void)
|
||||||
{
|
{
|
||||||
@ -50,3 +54,40 @@ void print(void)
|
|||||||
}
|
}
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void scan_copy(int x, int y, puzz_t out)
|
||||||
|
{
|
||||||
|
assert(x >= 0 && x < WIDTH);
|
||||||
|
assert(y >= 0 && y < HEIGHT);
|
||||||
|
|
||||||
|
out[x][y] = soln[x][y];
|
||||||
|
scanned[x][y] = YES;
|
||||||
|
|
||||||
|
if (soln[x][y] != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (int yp = y - 1; yp < y + 2; ++yp) {
|
||||||
|
for (int xp = x - 1; xp < x + 2; ++xp) {
|
||||||
|
if (xp < 0 || xp >= WIDTH || yp < 0 || yp >= HEIGHT
|
||||||
|
|| scanned[xp][yp] == YES)
|
||||||
|
continue;
|
||||||
|
scan_copy(xp, yp, out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
status_t probe(int x, int y, puzz_t out)
|
||||||
|
{
|
||||||
|
printf("Probing: %d,%d\n", x, y);
|
||||||
|
|
||||||
|
assert(x >= 0 && x < WIDTH);
|
||||||
|
assert(y >= 0 && y < HEIGHT);
|
||||||
|
|
||||||
|
if (soln[x][y] == MINE)
|
||||||
|
return DEAD;
|
||||||
|
|
||||||
|
memset(scanned, NO, sizeof(scanned));
|
||||||
|
scan_copy(x, y, out);
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
2
puzz.h
2
puzz.h
@ -15,8 +15,10 @@
|
|||||||
enum { MINE = 0xff };
|
enum { MINE = 0xff };
|
||||||
|
|
||||||
typedef uint8_t puzz_t[WIDTH][HEIGHT];
|
typedef uint8_t puzz_t[WIDTH][HEIGHT];
|
||||||
|
typedef enum { DEAD, OK } status_t;
|
||||||
|
|
||||||
void gen(void);
|
void gen(void);
|
||||||
void print(void);
|
void print(void);
|
||||||
|
status_t probe(int x, int y, puzz_t out);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user