61 class Bishops :
public Space {
66 return (i >= 0 && i <
n) && (j >= 0 && j <
n);
69 :
n(size), k(*
this,
n*
n,0,1) {
71 for (
int l =
n; l--; ) {
72 const int il = (
n-1) - l;
74 for (
int i = 0; i <= l; ++i) {
77 d3[i] = kb((
n-1)-i-il, i);
78 d4[i] = kb((
n-1)-i, i+il);
97 return new Bishops(*
this);
104 Bishops* prob =
new Bishops(size);
111 while (Bishops*
s = e.
next()) {
112 for (
int i = size*size; i--; )
113 ia[i] =
s->k[i].val();
207 return (i >= 0 && i <
n) &&
213 static const int kmoves[4][2] = {
214 {-1,2}, {1,2}, {2,-1}, {2,1}
217 for (
int x =
n; x--; )
218 for (
int y =
n; y--; )
219 for (
int i = 4; i--; )
220 if (
valid_pos(x+kmoves[i][0], y+kmoves[i][1]))
224 kb(x+kmoves[i][0], y+kmoves[i][1]),
243 const int nkval =
sizeof(
kval)/
sizeof(int);
244 const int nn =
n*
n, q =
n, r =
n, b = (2*
n)-2,
246 const int e = nn - (q + r + b + k);
248 assert(nn == (e + q + r + b + k));
263 for (
int i = 0; i <
n; ++i) {
285 for (
int l =
n; l--; ) {
286 const int il = (
n-1) - l;
287 IntVarArgs d1(l+1), d2(l+1), d3(l+1), d4(l+1);
288 for (
int i = 0; i <= l; ++i) {
291 d3[i] = m((
n-1)-i-il, i);
292 d4[i] = m((
n-1)-i, i+il);
308 for (
int i =
s.
size(); i--; )
315 for(
int i =
n*
n; i--; )
326 for (
int i =
n; i--; )
362 names[
E] =
'.'; names[
Q] =
'Q'; names[
R] =
'R';
363 names[
B] =
'B'; names[
K] =
'K';
364 const char* sep =
n < 8 ?
"\t\t" :
"\t";
366 for (
int r = 0; r <
n; ++r){
369 for (
int c = 0; c <
n; ++c) {
370 if (m(r, c).assigned()) {
371 os << names[m(r, c).val()];
377 for (
int p = 0; p <
PMAX; ++p) {
378 if (p ==
E)
continue;
380 for (
int c = 0; c <
n; ++c) {
381 if (m(r, c).assigned()) {
382 if (m(r, c).val() == p)
406 "Use extensional propagation for bishops-placement");
409 "Use decomposed propagation for bishops-placement");
412 opt.
parse(argc,argv);
413 if (opt.size() < 5) {
414 std::cerr <<
"Error: size must be at least 5" << std::endl;
int main(int argc, char *argv[])
Main function.
void knight_constraints(void)
Post knight-constraints.
CrowdedChess(CrowdedChess &e)
Constructor for cloning e.
void init_bishops(int size)
Initialize bishops.
IntVarArray queens
Row of queen in column x.
enum CrowdedChess::@263340023323302220154063075062255036254004010355 piece
@ PMAX
Number of pieces (including empty squares).
virtual void print(std::ostream &os) const
Print solution.
@ PROP_DECOMPOSE
Propagate bishops placement with decomposition.
@ PROP_TUPLE_SET
Propagate bishops placement extensionally.
bool valid_pos(int i, int j)
CrowdedChess(const SizeOptions &opt)
The model of the problem.
IntVarArray rooks
Row of rook in column x.
TupleSet bishops
Set of valid positions for the bishops.
virtual Space * copy(void)
Copy during cloning.
BoolVarArray knights
True iff the corresponding place has a knight.
Passing Boolean variables.
Depth-first search engine.
static void run(const Options &opt, Script *s=nullptr)
Passing integer arguments.
static IntArgs create(int n, int start, int inc=1)
Allocate array with n elements such that for all .
Passing integer variables.
Matrix-interface for arrays.
Slice< A > col(int c) const
Access column c.
Slice< A > row(int r) const
Access row r.
virtual T * next(void)
Return next solution (nullptr, if none exists or search has been stopped).
Options for scripts with additional size parameter
Class representing a set of tuples.
TupleSet & add(const IntArgs &t)
Add tuple t to tuple set.
void finalize(void)
Finalize tuple set with dense support data.
void init(int a)
Initialize an uninitialized tuple set.
int size(void) const
Return size of array (number of elements).
void update(Space &home, VarArray< Var > &a)
Update array to be a clone of array a.
void parse(int argc, char *argv[])
Parse commandline arguments.
Driver::ScriptBase< Driver::IgnoreStepOption< Space > > Script
Base-class for scripts.
void branch(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatValBranch vals, FloatBranchFilter bf=nullptr, FloatVarValPrint vvp=nullptr)
Branch over x with variable selection vars and value selection vals.
void linear(Home home, const FloatVarArgs &x, FloatRelType frt, FloatVal c)
Post propagator for .
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
void extensional(Home home, const IntVarArgs &x, DFA d, IntPropLevel ipl=IPL_DEF)
Post domain consistent propagator for extensional constraint described by a DFA.
@ EPK_AUTO
Select dense or compressed representation automatically.
@ IRT_LQ
Less or equal ( ).
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Space(void)
Default constructor.
Gecode toplevel namespace
void count(Home home, const IntVarArgs &x, int n, IntRelType irt, int m, IntPropLevel ipl=IPL_DEF)
Post propagator for .
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
IntVar expr(Home home, const LinIntExpr &e, const IntPropLevels &ipls=IntPropLevels::def)
Post linear expression and return its value.
void distinct(Home home, const IntVarArgs &x, IntPropLevel ipl=IPL_DEF)
Post propagator for for all .
void element(Home home, IntSharedArray n, IntVar x0, IntVar x1, IntPropLevel ipl=IPL_DEF)
Post domain consistent propagator for .
BoolValBranch BOOL_VAL_MAX(void)
Select largest value.
IntValBranch INT_VAL_MIN(void)
Select smallest value.
BoolVarBranch BOOL_VAR_DEGREE_MAX(BranchTbl tbl=nullptr)
Select variable with largest degree.
IntVarBranch INT_VAR_MIN_MIN(BranchTbl tbl=nullptr)
Select variable with smallest min.