Tuesday, April 25, 2006

Moving on

I fixed it! Yes, I couldn't stop thinking about it. It had to be done. It's ok, I got a few hours of sleep. I'll be regretting it after work I'm sure. The problem actually made no sense. I had a loop to grab the best move that looks for the first move in a stack (I keep the currentline/bestline in a stack so I can push/pop to put moves on it and take them off since it follows nicely the iterative nature of moving through the chess tree).

for (int idx = 0; idx < bestLine.Count - 1; idx++) {
bestLine.Pop();
}
//this should leaves us with the 1st move from the line, which is what we want to play
bestMove = bestLine.Peek();

This worked fine until I hit 7+ ply, then it didn't. Oddly enough, all I could see when I added some debugging was that once it hit 7 ply, there were more than one move left on the stack... it was very weird. I changed it to this:

ival = bestLine.Count - 1;
for (int idx = 0; idx < ival; idx++) {
bestLine.Pop();
}
bestMove = bestLine.Peek();

And it worked fine. All the way to ply 20, when I finally said this is good.

I don't get it, but at least it's working.

Now it's time to get ready for work!

Ed.

[NOTE: It just hit me why it didn't work! Having (bestLine.Count-1) in the "for" expression eval is bad because bestLine.Count is also being decremented each loop because of the Pop() within the for loop. So it really needs to be assigned outside the loop and that variable used... like how I ended up fixing it. I'm glad to have an answer, it was bugging me. Now, back to my day!]

No comments: