### 3.7.163. n-Amazons

modelling: n-Amazons A constraint that can be used for modelling the $n$-Amazons problem. Place $n$ Amazons on an $n$ by $n$ chessboard in such a way that no Amazon attacks another. We say that two columns (respectively two rows) of a chessboard are almost adjacent if and only if the two columns (respectively the two rows) are separated by a single column (respectively a single row). Two Amazons attack each other if at least one of the following conditions holds:

1. They are located on the same column, on the same row or on the same diagonal.

As shown by these conditions, an Amazon combines the movements of a queen and of a knight. FigureΒ 3.7.43 illustrates the movements of an Amazon. The $n$-Amazons problem has no solution when $n$ is smaller than 10.
We now show how to model the $n$-Amazons problem with six global constraints. We start from the model that is used for the n-queens problem. We associate to the ${i}^{th}$ column of the chessboard a domain variable ${X}_{i}$ that gives the row number where the corresponding queen is located.
If we combine the constraints of the form $\left(1\beta €i\beta €n-1\right)$ with the three $\mathrm{\pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi \pi }$ constraints we get the conjunction of constraints $\beta §$ $\beta §$ $\left(1\beta €i\beta €n-1\right)$. This conjunction of three disequalities can be expressed as a single inequality of the form $|{X}_{i}-{X}_{i+1}|>2$ $\left(1\beta €i\beta €n-1\right)$. Furthermore all these inequalities can be combined into a single $\mathrm{\pi \pi \pi \pi \pi \pi }$ constraint of the form $\mathrm{\pi \pi \pi \pi \pi \pi }$$\left(n-1,2,\beta ©{X}_{1},{X}_{2},\beta ―,{X}_{n}\beta ͺ\right)$.Since we enforce for all pairs of consecutive variables ${X}_{i}$, ${X}_{i+1}$ $\left(1\beta €i\beta €n-1\right)$ the constraint $|{X}_{i}-{X}_{i+1}|>2$, the name $\mathrm{\pi \pi \pi \pi \pi \pi }$ seems odd. However the name $\mathrm{\pi \pi \pi \pi \pi \pi }$ stands from the situation where the number of inequalities constraints should be minimised. Similarly we get the constraints $|{X}_{2Β·i+1}-{X}_{2Β·i+3}|>2$ $\left(0\beta €i\beta €\beta \frac{n-3}{2}\beta \right)$ and $|{X}_{2Β·i}-{X}_{2Β·i+2}|>2$ $\left(1\beta €i\beta €\beta \frac{n-2}{2}\beta \right)$. Again we obtain two $\mathrm{\pi \pi \pi \pi \pi \pi }$ constraints of the form $\mathrm{\pi \pi \pi \pi \pi \pi }$$\left(\beta \frac{n-1}{2}\beta ,2,\beta ©{X}_{1},{X}_{3},\beta ―,{X}_{n-1+n\mathrm{mod}2}\beta ͺ\right)$ and $\mathrm{\pi \pi \pi \pi \pi \pi }$$\left(\beta \frac{n-2}{2}\beta ,2,\beta ©{X}_{2},{X}_{4},\beta ―,{X}_{n-n\mathrm{mod}2}\beta ͺ\right)$.
Finally, the $\mathrm{\pi \pi \pi \pi \pi \pi \pi }$ constraint can also be used as a channelling constraint if we want to create an additional variable for each row. This may be for instance the case if we want to have a heuristics for selecting first the column or the row that has the smallest number of possibilities.
FigureΒ 3.7.44 shows the unique solution, modulo symmetries, to the $n$-Amazons problem for $n=10$. We have the following conjunction of constraints: