Compute set of neighbour fields
| 187 | } |
| 188 | /// Compute set of neighbour fields |
| 189 | IntSet neighbors(int i) { |
| 190 | static const int moves[8][2] = { |
| 191 | {-2,-1}, {-2,1}, {-1,-2}, {-1,2}, {1,-2}, {1,2}, {2,-1}, {2,1} |
| 192 | }; |
| 193 | int nbs[8]; int n_nbs = 0; |
| 194 | for (int m=0; m<8; m++) { |
| 195 | int nx = x(i) + moves[m][0], ny = y(i) + moves[m][1]; |
| 196 | if ((nx >= 0) && (nx < n) && (ny >= 0) && (ny < n)) |
| 197 | nbs[n_nbs++] = f(nx,ny); |
| 198 | } |
| 199 | return IntSet(nbs,n_nbs); |
| 200 | } |
| 201 | /// Constructor |
| 202 | Knights(const SizeOptions& opt) |
| 203 | : Script(opt), n(opt.size()), succ(*this,n*n,0,n*n-1) { |