Chess TDD 57: Finished Threat Evaluator
Once again, it’s been a while since the last episode in the series. This time the culprit has been a relocation for the remainder of the winter, which meant I was dealing with moving-like logistics. However I’m holed up now in the south, where I’ll spend the winter working on my book, working remotely, and hopefully wrangling this Chess TDD series to a conclusion. In this episode, I finished threat evaluator, or at least got pretty close. I called it a wrap around the 20 minute mark and without having written additional unit or acceptance tests to satisfy myself that it works in a variety of cases. It now correctly understands that some moves aren’t threatening (e.g. pawn moving straight ahead) and that pieces of the same color do not threaten one another.
Also, a quick editorial note. There’s been some pretty intense wind here in Louisiana, and the power went out around the 18:00 minute mark. I was surprised that all of the screencasting was saved without issue, but that VS barfed and filled my source file with all sorts of nulls. I had to revert changes and re-do them by hand prior to picking up where I left off. So it’s conceivable that a word might be spelled slightly differently or something. I’m not pulling a fast one; just dealing with adverse circumstances.
What I accomplish in this clip:
- Finished threat evaluator (initial implementation).
- Won a decisive battle in the age old, man vs nature conflict.
Here are some lessons to take away:
- Save early and often.
- Writing a test is a good, exploratory way to get back up to speed to see where you left off with an implementation. Write a test that needs to pass, and then, if it fails, make it pass. If it passes, then, hey, great, because it’s a good test to have anyway. This (writing tests to see where you left off) is not to be confused with writing a test that you expect to fail and seeing it pass.
- Anything you can do to tighten up the automated test feedback loop is critical (like NCrunch). The idea here is to get in the habit of using unit tests as the quickest, most efficient way to corroborate or disprove your understanding of the code. Run experiments!
- If, while getting a red test green, you have an idea for a more elegant refactoring, store that away until you’ve done something quick and simple to get to green. Don’t go for the gold all at once. Get it working, then make it elegant.