Well last night I got most of the check rules working. It was not easy, but I had so many tests that every time I broke something I found it right away. The biggest time sink was debugging a test that was bad. I was testing for check when no check existed, but I was sure it did. Visualizing chess positions without a graphic has always been difficult for me. I am still enamored with TDD. I have a total of 692 NCLOC with a whopping 384 of it in test code!
The most difficult thing for me is still writing code that I know needs to be refactored. When writing the check rules for bishop the straight forward way was so bloated. I had over a page worth of code just for bishop. Once I got all the tests passing, I focused on refactoring and came up with a function that could be used for both bishop and rook. The rook code took about a dozen lines and these were just minor changes from copying the bishop logic. Only time will tell, but I have gotten further than before with less code (not counting tests). The key is that I did it in less time. I don't remember how long it took me before, but I know I spent more then the dozen or so hours I have expended this time. Tonight I hope to get queen checks (just a combo of rook and bishop) and then moves into check and castling across check.
No comments:
Post a Comment