It's enumerating all of the boards, legal or not. Judging by the letters, it's doing one player's moves at first, in a way that's trying to avoid repeats. If I were to do this, I'd have, well, menace_x and menace_o, and build move n from move n-1. Depth-first would also work, really, as we're talking about only 300-ish boards.