Teemu Pudas wrote:H.G.Muller wrote:I could find no way to cast it in a structured form; I could only do it by a number of conditional backward gotos.
I hide it behind a bunch of macros:
- Code: Select all
enum { RETURN, NEW_NODE };
#define be_recursive() \
switch (state) { \
case NEW_NODE
#define end_recursion() \
default:assert(false); return best; }
#define return(foo) return best = foo, RETURN
#define recurse() return(best), NEW_NODE
#define search(depth,alpha,beta) do { \
next->init(NEW_NODE,depth,alpha,beta); \
state = __LINE__; \
recurse(); \
case __LINE__:; } while (0)
inline int Node::do_search() {
// any variable not declared inside this function is a member of Node
Node *const next = this + 1;
be_recursive(): // Please.
gen_moves(list);
if (list.empty()) return(in_check?MATE_IN_ONE:DRAW);
while (move = list.next()) {
make(move);
search(depth-1,-beta,-alpha);
unmake();
if (ret_val > best) {
best = ret_val;
if (best >= beta) return(best);
}
}
return(best);
end_recursion();
}
int drive_search(int depth, int alpha, int beta) { // called from root_search()
Node stack[MaxPly];
Node *node = &stack[1]; // stack[0] would be root
node->init(NEW_NODE,depth,alpha,beta);
while (true) {
switch (node->do_search()) {
case RETURN:
node--;
node->ret_val = -node[1].best;
if (node == stack) return node->ret_val;
break;
case NEW_NODE:
node++;
}
}
}
That's pretty clean Teemu, very interesting design. I like your use of the LINE macro, though I use the name of the tag in other places so I can't steal it. When are we going to see this engine released?
It seems everyone's iterative search implementation is very different. ZCT looks mostly like a traditional search, Scorpio is, well honestly Scorpio is very weird. I never understood its search. And yours is pretty cool, it should allow for a very clean design (i.e. you can use separate search and qsearch functions).
ZCT and Zappa also use iterative search for DTS. Personally that was the only reason. I might be able to speed up my iterative design, but I think overall it is slower than recursive. I can see somebody like H.G. or Vincent making iterative faster than recursive, but I usually don't deal with that kind of low level detail, and I think it would make my code way messier.
BTW I'm pretty sure that I just fixed my last bug and ZCT is 100% stable on 4 processors. Idle time is way down to a couple percent usually, and it's now played 15 1'0" games with no problems (knock on wood). I don't know about the scaling, but that's peanuts compared to getting DTS bug free...