Stories about Software


Chess TDD 55: Got the Hang of Castling

In this episode, it seems I finally got the hang of castling.  It’s been a relatively long journey with it, but I can now successfully detect castling situations that involve any combination of rook/king prior movement, as well as interceding pieces.  The only thing left to go is the relative edge case of a castling through check scenario, but I’ll consider that to be part of the implementation of the check concept.

What I accomplish in this clip:

  • Re-hydrated the acceptance test that I’d left off with last time and got it passing.
  • Refactored toward a less naive implementation of blocking, and then got it passing for all cases on both sides.

Here are some lessons to take away:

  • If you’ve written a failing acceptance test and are struggling to see how to get it to pass, see if you can express the same scenario with a more granular unit test.  This can focus you and help prevent your brain from spinning.
  • If you have the feeling that you’ve implemented something before (or a teammate has), it is definitely worth pausing to investigate.  You don’t want oddball solutions to the same problem, which can be as damaging as copy and paste programming.
  • You’ll never get away from making mistakes of all sorts.  Take note how in this episode, I probably got a bit too ambitious with solving the whole problem at once, which led to a lot of staring at the screen.  I probably should have made use of more failing tests to get there more gradually.
  • When you feel that you have coder’s block and aren’t sure what to do next, that’s the best time to implement something naive and ugly.  There’s no need to be afraid, since you’ll refactor shortly, but just getting anything out there can un-stick you.

newest oldest most voted
Notify of
Colin Higgins

I’d argue there are no edge cases in the rules of chess!

Erik Dietrich

I would distinguish based on the likelihood of a move to happen in a given game, I suppose. Castling, en passant, castling through check… these aren’t things that necessarily happen in all, or even most, games (I suspect — don’t know the actual data). Contrast that with advancing pawns or moving knights, I’d say.

Of course, I see the argument that it’s kind of all or nothing — either you have all the moves or it’s not chess.

Colin Higgins

The depends on the skill level of the respective players, but yeah, I was more speaking to them being “hard business rules”. The minimum viable product if you will.