CrowdedChess Class Reference
Example scripts (models)

Example: Crowded chessboard More...

## Public Types

enum | { PROP_TUPLE_SET , PROP_DECOMPOSE }

## Public Member Functions

| CrowdedChess (const SizeOptions &opt)
| The model of the problem.
| CrowdedChess (CrowdedChess &e)
| Constructor for cloning e.
virtual Space * | copy (void)
| Copy during cloning.
virtual void | print (std::ostream &os) const
| Print solution.
Public Member Functions inherited from Gecode::Driver::ScriptBase< Driver::IgnoreStepOption< Space > >
| ScriptBase (const Options &opt)
| Constructor.
| ScriptBase (ScriptBase &e)
| Constructor used for cloning.
virtual void | compare (const Space &home, std::ostream &os) const
| Compare with s.
Public Member Functions inherited from Gecode::Driver::IgnoreStepOption< BaseSpace >
| IgnoreStepOption (const Options &)
| Constructor.
| IgnoreStepOption (BaseSpace &e)
| Constructor used for cloning.

## Protected Types

enum | { Q , R , B , K , E , PMAX }

## Protected Member Functions

bool | valid_pos (int i, int j)
void | knight_constraints (void)
| Post knight-constraints.

## Protected Attributes

const int | n
| Board-size.
IntVarArray | s
| The board.
IntVarArray | queens
| Row of queen in column x.
IntVarArray | rooks
| Row of rook in column x.
BoolVarArray | knights
| True iff the corresponding place has a knight.
enum CrowdedChess:: { ... } | piece

## Related Symbols

(Note that these are not member symbols.)
TupleSet | bishops
| Set of valid positions for the bishops.
void | init_bishops (int size)
| Initialize bishops.
int | main (int argc, char *argv[])
| Main function.

## Additional Inherited Members

Static Public Member Functions inherited from Gecode::Driver::ScriptBase< Driver::IgnoreStepOption< Space > >
static std::ostream & | select_ostream (const char *sn, std::ofstream &ofs)
| Choose output stream according to sn.
static void | run (const Options &opt, Script *s=NULL)

## Detailed Description

Example: Crowded chessboard

You are given a chessboard together with 8 queens, 8 rooks, 14 bishops, and 21 knights. The puzzle is to arrange the 51 pieces on the chessboard so that no queen shall attack another queen, no rook attack another rook, no bishop attack another bishop, and no knight attack another knight. No notice is to be taken of the intervention of pieces of another type from that under consideration - that is, two queens will be considered to attack one another although there may be, say, a rook, a bishop, and a knight between them. It is not difficult to dispose of each type of piece separately; the difficulty comes in when you have to find room for all the arrangements on the board simultaneously. Dudeney, H.E., (1917), Amusements in Mathematics, Thomas Nelson and Sons.

This puzzle can be generalized to chess-boards of size , where the number of pieces to place are:

- queens
- rooks
- bishops
- knights where k is a number to maximize.

The maximum k for some different values of are presented below (from Jesper Hansen and Joachim Schimpf, ECLiPSe solution

n | k
8 | 21
9 | 29
10 | 37
11 | 47
12 | 57
13 | 69
14 | 81
15 | 94
16 | 109

A solution for n = 8 is:

Q | B | K | . | K | B | K | R
. | K | . | K | Q | K | R | B
B | . | K | R | K | . | K | Q
B | K | R | K | . | Q | . | B
B | R | Q | . | K | . | K | B
R | K | . | K | . | K | Q | B
B | Q | K | . | K | R | K | .
B | K | B | Q | R | K | B | B

Definition at line 185 of file crowded-chess.cpp.

## Member Enumeration Documentation

## anonymous enum

anonymous enum

protected

Symbolic names of pieces. The order determines which piece will be placed first.

Enumerator
Q | Queen.
R | Rook.
B | Bishop.
K | Knight.
E | Empty square.
PMAX | Number of pieces (including empty squares).

Definition at line 196 of file crowded-chess.cpp.

## anonymous enum

anonymous enum

Enumerator
PROP_TUPLE_SET | Propagate bishops placement extensionally.
PROP_DECOMPOSE | Propagate bishops placement with decomposition.

Definition at line 230 of file crowded-chess.cpp.

## Constructor & Destructor Documentation

## CrowdedChess() [1/2]

CrowdedChess::CrowdedChess | ( | const SizeOptions & | opt | ) |

inline

The model of the problem.

Definition at line 236 of file crowded-chess.cpp.

## CrowdedChess() [2/2]

CrowdedChess::CrowdedChess | ( | CrowdedChess & | e | ) |

inline

Constructor for cloning e.

Definition at line 343 of file crowded-chess.cpp.

## Member Function Documentation

## valid_pos()

bool CrowdedChess::valid_pos | ( | int | i,
|  | int | j )

inline protected

Definition at line 206 of file crowded-chess.cpp.

## knight_constraints()

void CrowdedChess::knight_constraints | ( | void |  | ) |

inline protected

Post knight-constraints.

Definition at line 212 of file crowded-chess.cpp.

## copy()

virtual Space * CrowdedChess::copy | ( | void |  | ) |

inline virtual

Copy during cloning.

Definition at line 353 of file crowded-chess.cpp.

## print()

virtual void CrowdedChess::print | ( | std::ostream & | os | ) | const

inline virtual

Print solution.

Reimplemented from Gecode::Driver::ScriptBase< Driver::IgnoreStepOption< Space > >.

Definition at line 359 of file crowded-chess.cpp.

## Friends And Related Symbol Documentation

## bishops

TupleSet bishops

related

Set of valid positions for the bishops.

Definition at line 57 of file crowded-chess.cpp.

## init_bishops()

void init_bishops | ( | int | size | ) |

related

Initialize bishops.

Definition at line 103 of file crowded-chess.cpp.

## main()

int main | ( | int | argc,
|  | char * | argv[] )

related

Main function.

Definition at line 401 of file crowded-chess.cpp.

## Member Data Documentation

## n

const int CrowdedChess::n

protected

Board-size.

Definition at line 187 of file crowded-chess.cpp.

## s

IntVarArray CrowdedChess::s

protected

The board.

Definition at line 188 of file crowded-chess.cpp.

## queens

IntVarArray CrowdedChess::queens

protected

Row of queen in column x.

Definition at line 189 of file crowded-chess.cpp.

## rooks

IntVarArray CrowdedChess::rooks

protected

Row of rook in column x.

Definition at line 190 of file crowded-chess.cpp.

## knights

BoolVarArray CrowdedChess::knights

protected

True iff the corresponding place has a knight.

Definition at line 191 of file crowded-chess.cpp.

## []

enum { ... } CrowdedChess::piece

Symbolic names of pieces. The order determines which piece will be placed first.

The documentation for this class was generated from the following file:

- examples/crowded-chess.cpp