|
|
|
|
|
by mtlmtlmtlmtl
1384 days ago
|
|
I'm not a JS programmer, but I didn't find that code terribly readable. And from a performance point of view, I would not want to copy the board state n times, though that's beside the point. It's a bit of a contrived example of course. But what this looks like in a real engine would be something like(no language in particular): pseudo_legal = move_generator(pos, PSEUDOLEGAL);
while true {
mv = pseudo_legal.next();
if !mv {
break;
}
if mv == tt.excluded_move || !pos.legal(mv){
continue;
}
pos.make_move(mv);
...
pos.unmake_move();
}
The pseudolegal stuff and all that has to do with various performance considerations. This is roughly what Stockfish' move loop looks like. It looks overly verbose because abstracting away these things with functions adds runtime overhead.With macros you can have your cake and eat it too. While it's technically true you're passing around unevaluated code, none of this is happening at runtime but at compile-time(technically macro-expansion time but that's beyond the scope of this comment). Think of it as the ability to inline pretty much anything you want. |
|