This page last changed on Sep 10, 2009 by celliso2.
Assignment 1.3 – Refactoring and Expanding the Neighbor Processor
This is the third part of a three part assignment that will span over the course of three weeks. Look over this page frequently for Update markers with clarifications or changes.
Language: C/C++ (whichever you wrote assignment 1.1 in)
Recommended Reading: Code Complete Chapter 24 – Refactoring
- Apply refactorings suggested by your moderator and discussion section members during week 1.1
- Expand the neighbor processor to support new features
- Learn to write highly modular code
Goal: Apply suggestions given during discussion for assignment 1.1 and then expand the neighbor processor to process new data.
During discussion for assignment 1.1, your moderator and other students in your discussion section should have given you some suggestions on ways that you could improve your code. See the comments left on your gradesheet or email your moderator to have him remind you of what needed to be improved. Part I of this assignment is to apply those suggestions and refactor your code to make it better.
In particular, here are a few common errors or improvements to apply that were noticed on the majority of code for assignment 1.1:
- magic numbers were used on bit masks rather than DEFINEs or constants
- commenting was limited
- duplicate code was found, especially in the different neighbor checks (hint: generalize each check and extract that out into a function that can be called)
Well our neighbor processor was great and all, but we have decided that it would be much more useful if it was more of a general tool rather than something used just for this specific application. For part II of this assignment, we will convert our neighbor processor to process neighbors in 3D.
Given a cell in 3D, it will have 26 adjacent neighbors to it:
We will be doing the exact same thing as we did in 2D, but expanding our processor to consider all three dimensions. Remember, we do not care what each individual cell is, just what is its relation to its neighbors. A 1 for a particular bit signifies that that cell has a neighbour that is different from it, a 0 signifies that that is the same type of cell.
We will pack our neighbor data into a 32 bit integer. The layout will be as follows (The offsets are the difference in x,y,z from the cell we are checking to its neighbor):
| Offsets (x,y,z)
|| Bit Number
Bits 0-5 will be ignored. This layout is somewhat arbitrary, so if you feel you have a better one, use it and post it on the newsgroup.
3x3x3 Sample Input
4x4x4 Sample Input
3x4x5 Sample Input (cols then rows then planes)
3x4x5 Sample Input (using rows THEN cols, like previous assignments)
17x30x45 Sample Input (cols then rows then planes)
17x30x45 Sample Input (using rows THEN cols, like previous assignments)
- Modularize your code as much as possible. Apply Information Hiding where possible to simplify your program.
- Do you hard code in special cases? Is there a more general approach that you can apply to neighbor checking?
- Does your program still work on 2D maps? It should! Either have your code automatically detect the map type or require some sort of command line flag.
- Since your code has to work on two types of maps, make sure that you extract out any similar functionality needed for both 2D and 3D maps into general functions that can work on both. If you are copying and pasting, stop and think about how to avoid doing that. We shouldn’t see any duplicate code in your assignment.
- Did you modify your test script to generate 3D maps?
- Did you remember to include a README file describing how to compile and run your program along with its limitations and bugs, if any?
This assignment is due at 8:00 AM on Wednesday, September 16th 2009 in subversion in a folder named Assignment1.3. That is, you should be able to bring up https://csil-projects.cs.uiuc.edu/svn/fa09/cs242/NETID/Assignment1.3 and view your code (replacing NETID with your netid of course).
- Did you apply the suggestions that your moderator and fellow students gave you during discussion for assignment 1.1?: 10
- Can your program properly read in and store the 3D map?: 4
- Can your program properly generate a neighbor grid for 3D maps?: 4
- Can your program properly write the new neighbor grid out to file?: 4
- Can your program sill be run on 2D maps without recompiling?: 6
- There were no Code Smells in your code: 10
- You used adequate and meaningful comments: 4
- Your code was modular and adaptable to change: 6
- Your variable naming convention was consistent and meaningful: 4
- You asked questions in discussion section: 4
- You turned in your assignment on time and to the correct directory in svn: 4
- You came to class prepared to discuss the assigned code reading: 4