Lovely story of my development experience and getting completely stone walled.
After several years of professional development, I am finding there are certain things that are guaranteed in programming. Things such as motivational spikes, finding needles in haystacks, and just about every time; nothing works the first time you complete it(in reference to large modules not simple tasks).
That being said time and time again it is important to stay positive, and if it permits, move on. A prime example of this I ran into the last couple weeks. I just jumped to XNA from raw Direct X and I had the need to write a simple game to test out all my ported framework code. So I decided to write a TicTacToe game since I love it and it will use all of the aspects of my framework such as sprites, particles, etc etc and find any defects in said framework. And for the hell of it...and quite frankly I didn't think it was possible I thought I would implement the MiniMax algorithm. I mean, I thought I knew how to always win TicTacToe so I had to see for myself that this algorithm made it impossible for me to win.
So off I went into my usual style...white boarding, listing milestones and than hammering away at them. In roughly 8 hours I got a full game running with menu screens, a state machine, a persistent back ground, the board, easy and moderate difficulties, and all game logic implemented. Now the only thing left was the MiniMax algorithm and polish. I felt pretty good at this point, most of my framework code was solid and I found a couple nasty bugs or lack of functionality in my existing classes that had now been upgraded and all I really had left was simple polish and the algorithm. Off I went reading everything I could about this algorithm, simple MiniMax....complex implementations....alpha beta pruning etc etc, and watched a couple lectures on game trees.
Than came time to write it. Surprisingly I got the algorithm running based on all of the descriptions I have seen in a few hours. However, it didn't work properly. After 2 weeks (literally) of reading material, debugging my code and trying to rewrite the implementation I just couldn't figure out what the problem was. Than last night as my wife was going to the gym she asked why I was so grumpy and I said "I cannot figure this fucking algorithm out, everything I have read and watched matches what I am doing" and as her supportive self, she said "You will figure it out, you always do". Sure enough in my pessimistic state at this time I exclaimed "No I wont, there is nothing wrong with my implementation...I am not going to figure it out I am going to paste my code somewhere in a minute and get someone to tell me what is wrong and I wont learn shit all". So off she went to the gym and off I went spinning my wheels. Well after a few hours of this on yet another night I said you know what, I am going to go knock out some of the simple polish tasks and I will come back to this.
Here is the kicker. Over the years of my development career I know and recognize that it is important to get up and walk away sometimes. What I never really thought about was; move on, and come back. You know in your day to day work this really isn't an option, but as a personal project it is. So I said screw the algorithm, closed its classes and went to my mile stones of phase 2 and looked at what polishing tasks to tackle. After tackling a couple polishing tasks quite fast and making the game look a lot better I went back to the algorithm and thought I would give it a couple more rounds of debugging. Still pessimistic that I might not even have it implemented properly I bit the bullet and went through with it. To my surprise and shock I found a couple problems. One I have never run into before was using the == comparison operation on an Enum opposed to a Constant.equals(enum) comparison. Sure enough I saw in my debugging that even though I was saying turn == COMPUTERS_TURN this was only sometimes equating to true even when the turn was indeed the computers turn. So I thought wtf?!?!? I flipped it to a .equals and sure enough now the states were being determined correctly. But there was still a problem......I could still beat the algorithm. Just as a whim I thought you know what....I bet the test data I have setup (4 squares already populated) is the problem, I bet the algorithm from the start would NEVER let this scenario arise. So I removed the test data and sure enough the algorithm was running 100%....kicking my ass granted.
The important thing here is that if you are able to and are completely stuck on a task.....move on to something else to take your mind off of it and than come back. For me I usually just go for a quick walk or something and that usually does the trick but even for this, that was not working, but apparently moving on to something much simpler and mundane was enough to reset my brain just enough to want to and figure out the problem.
**EDIT** Forgot to mention when my wife got home I did say "You were right babe, I did figure it out" and got the told you response.
Thank you for reading my entry and I hope you enjoyed it and find it useful if you ever find yourself in a similar predicament.