Tag Archives: code-kata c#

Code Kata: Langton’s Ant in C#

I’ve been itching to give code katas a try after listening to people like Uncle Bob talk about them in podcasts and reading about them on blogs. However, it wasn’t until I (half) watched a screencast by Micah Martin on solving a very small and simple problem that I actually went and did my own properly.

The problem space in this instance is Langton’s Ant. The problem is very simple:

Squares on a plane are colored variously either black or white. We arbitrarily identify one square as the “ant”. The ant can travel in any of the four cardinal directions at each step it takes. The ant moves according to the rules below:

  • At a white square, turn 90° right, flip the color of the square, move forward one unit
  • At a black square, turn 90° left, flip the color of the square, move forward one unit

This should be a fairly straightforward thing to map out in C# I thought. If I forego the graphical aspect of it (as can be seen in the Wikipedia page on this) then the actual logic should be fairly easy to test. In the end this little test took me a couple of hours to do which simply proves that a) I’m not as good a programmer as I thought and b) I have plenty to learn about using my IDE more efficiently (VS2008 with Resharper).

I’ve attached the project to this post.