Langton's Ant
Project Description
For this project, we created a simple Langton's Ant game, and displayed it on the uLCD-144-G2 128 by 128 Smart Color LCD. We also added 2 push buttons to allow user to select different colors for the ant. A third push button is added for the user to start the game.
Schematic
Langton's ant is a two-dimensional Turing machine with a very simple set of rules but complicated emergent behavior. In this game, we wrote the algorithm that follows the straightforward rules of Langton's Ant:
- Squares on a plane are either colored or white. We arbitrarily identify one square as the "ant", the initial starting location is at the center of the LCD display.
- 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.
Several things can be added to make the game more interesting, such as creating an initial state with both white and colored tiles; adding more user input to allow user to select initial direction of the ant; adding a speaker to play some music from the microSD card, etc.
Program running, displayed on the LCD
For more information about Langton's Ant, check out its wikipedia page: http://en.wikipedia.org/wiki/Langton's_ant
Source Code
Import programLangtonsAnt
This code includes the basic algorithm for Langton's Ant, and displays the ant's movement on the LCD. It also has several pushbuttons, allowing the user to select the color of the ant, as well as when to start the game.
Please log in to post comments.