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)),
102 b(*this,size*size,0,1) {
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)
140 Script(share,s), spec(s.spec), size(s.size) {
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;
void size(unsigned int s)
Set default size.
Options for scripts with additional size parameter
IntVarBranch INT_VAR_NONE(void)
Select first unassigned variable.
void linear(Home home, const FloatVarArgs &x, FloatRelType frt, FloatNum c)
Post propagator for .
int main(int argc, char *argv[])
Main-function.
const FloatNum max
Largest allowed float value.
void parse(int &argc, char *argv[])
Parse options from arguments argv (number is argc)
bool pos(const View &x)
Test whether x is postive.
virtual void print(std::ostream &os) const
Print solution.
Parametric base-class for scripts.
void update(Space &, bool share, VarArray< Var > &a)
Update array to be a clone of array a.
Gecode::FloatVal c(-8, 8)
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
void sqrt(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
unsigned int size(I &i)
Size of all ranges of range iterator i.
MineSweeper(bool share, MineSweeper &s)
Constructor for cloning s.
int spec_size(const char *s)
Compute the size of a specification.
Passing Boolean variables.
Boolean integer variables.
virtual Space * copy(bool share)
Copy space during cloning.
IntValBranch INT_VAL_MAX(void)
Select largest value.
int mineField(const char *s, int n, int i, int j)
Return value at position (i,j) in the example s of size n.
Node * x
Pointer to corresponding Boolean expression node.
void count(Home home, const IntVarArgs &x, int n, IntRelType irt, int m, IntConLevel)
Post propagator for .
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Matrix-interface for arrays.
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
MineSweeper(const SizeOptions &opt)
Actual model.
BrancherHandle branch(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatValBranch vals, FloatBranchFilter bf, FloatVarValPrint vvp)
Branch over x with variable selection vars and value selection vals.