MCPcopy Create free account
hub / github.com/Gecode/gecode / neighbors

Method neighbors

examples/knights.cpp:189–200  ·  view source on GitHub ↗

Compute set of neighbour fields

Source from the content-addressed store, hash-verified

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) {

Callers

nothing calls this directly

Calls 3

fFunction · 0.85
IntSetClass · 0.85
xFunction · 0.50

Tested by

no test coverage detected