Code: Select all
for(direction=0; (step = steps[piece][direction]); direction++) {
int to = from + step;
if(board[to] == EMPTY) { // sort of 50-50
GenerateNonCapture(from, to);
}
}
Code: Select all
int todo = 0;
for(direction=0; (step = steps[piece][direction]); direction++) {
todo |= (board[from+step] == EMPTY) << direction;
}
while(todo) {
unsigned int next = todo & -todo;
todo -= next;
direction = bit2nr[next*DEBRUIJN >> 27];
GenerateNonCapture(from, from + steps[piece][direction]);
}
The lookup in bit2nr[] could be optimized away by supplying a copy of steps[piece][direction] where the elements are ordered in 'DEBRUIJN' order, so that next*DEBRUIJN>>27 could be used to index it directly.
Code: Select all
int todo = 0;
for(direction=0; (step = steps[piece][direction]); direction++) {
todo |= (board[from+step] == EMPTY) << direction;
}
while(todo) {
unsigned int next = todo & -todo;
todo -= next;
GenerateNonCapture(from, from + shuffledSteps[piece][next*DEBRUIJN >> 27]);
}