October 2009
Intermediate to advanced
288 pages
5h 2m
English
This example involves refactoring and test-driven design.[1]
[1] The source code for this example is at http://github.com/kevinrutherford/rrwb-code.
Suppose we’ve decided to develop an application to play games in the tic-tac-toe family: squares occupied by different markers. In tic-tac-toe you have a 3 × 3 grid, and you try to put your mark in three boxes in a row. In Connect Four by Hasbro you have a rectangular grid and try to get four boxes in a row, but columns have to be filled from bottom to top. We’ll start with a simplified version of tic-tac-toe and work our way up to the general case.
Here are some tests and the first version of the code:
Notice that the winner method is simplified: You win by ...
Read now
Unlock full access