CS 242 Fall 2009 : Assignment 1.3

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

Objectives:

  1. Apply refactorings suggested by your moderator and discussion section members during week 1.1
  2. Expand the neighbor processor to support new features
  3. 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.

Part I

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)

Part II

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
(0,0,1) 31
(0,1,0) 30
(0,1,1) 29
(1,0,0) 28
(1,0,1) 27
(1,1,0) 26
(1,1,1) 25
(0,0,-1) 24
(0,1,-1) 23
(1,0,-1) 22
(1,1,-1) 21
(0,-1,0) 20
(0,-1,1) 19
(1,-1,0) 18
(1,-1,1) 17
(-1,0,0) 16
(-1,0,1) 15
(-1,1,0) 14
(-1,1,1) 13
(0,-1,-1) 12
(1,-1,-1) 11
(-1,0,-1) 10
(-1,1,-1) 9
(-1,-1,0) 8
(-1,-1,1) 7
(-1,-1,-1) 6

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.

Sample Files

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)

Suggestions/Hints

  • 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?

Submission

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).

Grading

Total 64 Points

Screenshot.png (image/png)

3x3x3.in (application/octet-stream)

4x4x4.in (application/octet-stream)

3x4x5.in (application/octet-stream)

17x30x45.in (application/octet-stream)

17x30x45-b.in (application/octet-stream)

3x4x5-b.in (application/octet-stream)
Document generated by Confluence on Feb 22, 2012 18:18

  1. No comments yet.

  1. No trackbacks yet.