Gerd,That is really cool. Reminds me on coroutines. It seems Yield need to safe some state variables to "remember" which yield occurred last and to restore its scope and context later recursively on an extra stack for all those iterator objects along the current path searched.
How is Moves defined? List<Move>?
From what I've read about coroutines, they don't fit well into traditional stack-based languages, which favor subroutines (execute routine, return to caller, execute next instruction in caller).
The yield keyword instructs the C# compiler to add some "syntactic sugar" to enable the enumerator to "pick up where it left off," so to speak. So yes, yield must save and restore state. This is done, of course, so the programmer doesn't have to do it himself.
I am unsure of the performance penalty of yield in C# because I've never measured it. Frankly, I didn't want to write messy state-management code. Yield was free and easy, so I wrote an enumerator with yield and moved on to other problems.
Yes, Moves is defined as List<Move>.