Fence post Problems

Only a subset of developers suffer from this – but I’m one of them.  I always create bugs involving fence post problems.  You know the fence post problem?  You’ve got 100 feet to be fenced-in.  Fence posts are to be spaced 10 feet apart.  How many fence posts do you need?  100/10=10, right?  Wrong.  You need 11.



As background, I just created a new game.  It’s based on a paper game every parent who has ever been to a chain restaurant knows.  You enter “Chotskie’s” and your kids are dutifully issued their paper menu and crayons.  Often the back of the menu contains a game with a matrix of dots.  The objective of the game is to connect dots, forming boxes.  Each player must create a new connection between adjacent dots during their turn.   If the player completes a square they color that square with “their” crayon, and create one more line.  If another box is closed – repeat.  The object is to close more boxes than your opponent (brother, sister, mean-dad, etc).

So back to fence post problems.  Developers are used to dealing with arrays.  Arrays start at 0?  No sweat.  We warped our brains into starting at “0” years ago.  But consider the sophisticated mock-up of the game below:



In “dot units”, it is 2×2.  That’s the rub.  Describing the system in terms of the intersections vs. the lines messes with traditional array thinking (at least for me).  I also decided to record lines (to tell if someone can create a new line) in arrays.  Since the lines aren’t directional in this game, I decided on the convention of “Left to Right” (horizontal) and “Top to Bottom” (vertical).  Connecting the first horizontal dot with the second (or vice versa) would be recorded at index “0”.   So for the above picture I need a 2×2 array?  Nope:



So my puny brain needs a 3×3 array to handle a “2×2” game.  Auggg.  After a few “+1”, “-1” bugs, I did get it working.  Emma actually sought me out to play a few rounds last night.  Nice.