Haskell-WIRING UP WIREWORLD First assignment for Introduction to Programming and Algorithms

A cellular automaton is a regular grid of cells which may be in any of a finite number of states that evolve in discrete time steps. All cel- lular automata have rules which dictate how many dimensions their grid is, what the different states are and how they evolve at each time step. Some famous cellular automata include Rule 30 (a 1 di- mension cellular automaton) and Conway s game of life (a 2 dimen- sional cellular automaton). For a more detailed explanation of cellular automata, see http://en.wikipedia.org/wiki/Cellular_automaton
The goal for this assignment is to implement the Wireworld cel- lular automaton in Haskell. The Wireworld cellular automaton is a 2 dimensional cellular automaton, with 4 cell states. Each cell is either Empty (black), an electron Head (red), an electron Tail (blue) or a Conductor (yellow). Each cell transitions as follows:
Empty & Empty
Head & Tail
Tail & Conductor
Conductor & )Head ; if 1 or 2 of the 8 adjacent cells are Heads Conductor ;otherwise
Note: The code you are given simplifies this by not keeping track of the empty cells. They will never be anything but an empty cell, so there is no need to observe them. For more infor- mation, see http://en.wikipedia.org/wiki/Wireworld
Setting up your computer for the assignment
Firstly, if you have not already done so, download the source code for the assignment from the course web-site. Secondly, install the gloss and bitmap libraries for Haskell. This can be done by running
> cabal update > cabal install gloss- bmp
from the terminal (or command prompt on windows). You can check if it works by opening Main.hs and replacing (_ _ -> transitionWorld) with
(_ _ -> id) (all this will do is stop the world from transitioning), compiling it with > ghc –make -O2 -W -o Wireworld Main.hs
where -O2 stands for Optimize level 2 (basically telling the compiler to put some effort into it), -o Wireworld specifies the name of the object (executable) file, and -W activates all Warnings
(which gives you more hints about things which might be wrong).
… and then running the newly made Wireworld program.You can drag with the mouse to move the screen, or right-click drag to rotate the screen.You can also re-size the window if the
1 | ANU College of Engineering and Computer Science March
world does not quite fit or press to reset the view. If this all works, you are ready to begin the assignment (remember to change Main.hs back to how it was).
The code
The code you are given models this cellular automaton by us- ing a list of all the non empty cells. A cell is a coordinate and a state. The code also reads in the starting state at compile time, from either a text file, or a bitmap image. (note if you modify the initial starting state, but not the code, you ll need to recompile with
> ghc –make -O2 -W -o Wireworld Main.hs -fforce-rec- omp
as the compiler doesn t know how to check if that s been changed or not). Anything in the Drawing or Load folders should only need to be changed if you do an extension that requires adding new cells (more details later).
The task
The code for reading in an initial starting state, and for drawing the world has already been done for you. The world is all there waiting for you to make it move. What you need to do is to define the transition for an individual cell. This will be applied to all cells in the world and things will become interesting.
The only files you ll need to look at to do this are Cell.hs, ListWorld.hs and Wireworld.hs. Inside them you ll find some function definitions which are not yet defined:
isHeadandisNeighbourinsideCell.hs getNeighbours inside ListWorld.hs cellTransition inside Wireworld.hs
Defining those functions is the base part of your assignment.You may want to look at all re- quired functions first, and then start with a simple one like e.g. isHead. Feel free to define more functions than just these if you find you need to. With the last function (cellTransition) you will implement the specific rules of Wireworld. Before you start typing you might want to think how to formulate the rules as simply as possible “ or in other words: How can you distinguish which case applies to this cell in the most concise form?, Can you do it in one shot or should you define supporting functions first?
Marks will be awarded for functionality, clarity of code, style, and efficiency.
Testing your code
GHCi will be too slow for all but the most trivial of all starting states. Compile it with
> ghc –make -O2 -W -o Wireworld Main.hs and then run Wireworld.
If you do only the task as specified above, your maximum mark will be a distinction. To be able to get a high distinction you must do one of the following extensions:
a. Instead of using a list of cells and coordinates, use a binary search tree. The code required to do this is already included.
b. Implement a new kind of cell with its own rules.You ll have to make minor changes to Drawing/ Cell.hs and Load/LoadWorld.hs, but nothing too difficult.
2 | ANU College of Engineering and Computer Science March
c. Any other idea that is approved by your tutor. If you have a good idea, we d like to hear it. However, please mention it early, so if necessary, we can write the required code to read it in or draw it.
Take every module which you changed or added (only the *.hs files) and archive them into a .gz, .tar, .tgz, .tar.gz, or .zip archive by the name Student_Modules, i.e. your submittable
code file will for instance have the name Student_Modules.tgz. Also write a brief report about your assignment which addresses all of the following questions:
What makes your solution(s) efficient and/or elegant? or: is/are your solution(s) less efficient but more readable?
Did you test your code and how? Which extensions did you think of or implement? (new cell kinds, new rules, …) Which problems did you encounter during the assignment and how did you address them?
Feel free to add diagrams or any other graphic to your report if you think that this explains your concepts better. There are no templates or forms, so you can use your preferred Word-proces- sor for the job, as long as your system is able to produce a pdf file with embedded fonts in the end. Submit your report as Assignment_1.pdf.
While you are free in the form of your report, please keep in mind that a report which makes our eyes tear (incomprehensible or unstructured English, horrible font, low quality typesetting) will be marked down.

Still stressed from student homework?
Get quality assistance from academic writers!