44 using namespace Gecode;
47 extern const char *specs[];
48 extern const unsigned int n_examples;
49 int spec_size(
const char *s);
50 int mineField(
const char *s,
int n,
int i,
int j);
83 for (
int ix =
std::max(0, x-1); ix<=x+1 && ix<
size; ix++)
84 for (
int iy =
std::max(0, y-1); iy<=y+1 && iy<
size; iy++)
89 for (
int ix =
std::max(0, x-1); ix<=x+1 && ix<
size; ix++)
90 for (
int iy =
std::max(0, y-1); iy<=y+1 && iy<
size; iy++)
91 if (ix != x || iy != y)
92 b[count++] = m(ix,iy);
100 : spec(specs[opt.
size()]),
101 size(spec_size(spec)),
106 for (
int h=0; h<
size; h++)
107 for (
int w=0; w<
size; w++) {
108 int v = mineField(spec, size, h, w);
122 for (
int h = 0; h <
size; ++h) {
124 for (
int w = 0; w <
size; ++w) {
125 int v = mineField(spec, size, h, w);
128 else if (
pos(h,w).val() == 1)
141 b.update(*
this, share, s.b);
159 opt.
parse(argc,argv);
160 if (opt.
size() >= n_examples) {
161 std::cerr <<
"Error: size must be between 0 and "
162 << n_examples-1 << std::endl;
165 Script::run<MineSweeper,DFS,SizeOptions>(
opt);
183 const char* specs[] = {
282 const unsigned int n_examples =
sizeof(specs)/
sizeof(
char*);
286 int l = std::strlen(s);
287 int res =
static_cast<int>(
std::sqrt(static_cast<float>(l)));
293 assert(spec_size(s) == n);
294 assert(i >= 0 && i < n);
295 assert(j >= 0 && j < n);
297 if (!std::isalnum(c))
302 c =
static_cast<char>(std::toupper(c));
304 int res = (c -
'A') + 10;
305 if (res > n)
return 0;