CPSC 217: Assignment 4
Due at 4 PM. For assignment due dates see the main
schedule on
the course webpage. The program must be written and run under python version
3.X.
New Concepts to be applied for the assignment
Only new concepts that need to be applied in the assignment are
listed, concepts previously applied in other assignments may be needed in the
implementation of your solution.
All instructions must be enclosed within the
body of a function, you must write at least 5 functions (JT's solution to A4 had
9 functions written) of your own. Functions that I have created in the starting code isn't
included in the count. The functions you write must be properly implemented. No
global variables may be employed.
The exceptions to including all code inside the body of a function could
include: import statements (not really needed for this assignment), the creation
of global constants (e.g. ATTIC = 1), a global
debugging flag and the call to the initial start or main function.
-
You will be penalized heavily if functions are not used or
improperly used.
- No functions or a single function
employed then the max assignment
grade = 1.0 grade points
- Two functions properly implemented then the max
assignment grade = 1.5 grade points
- Three functions properly implemented then the max
assignment grade = 2.5 grade points
- Four functions properly implemented then the max
assignment grade = 3.0 grade points
- In order to qualify as properly
implemented the function must include instructions (functionality) that
are appropriate to that function (e.g. anything related to the attic
should not be implemented in a function that includes functionality for
the bedroom) and the functions should not be 'empty' (e.g. it just includes a pass instruction)
or a token implementation (e.g. a few output statements or
declarations).
-
In a similar fashion you will be penalized heavily if you
define or use global variables (global
constants are okay, if you don't know the difference refer to the "Intro
programming" lectures covered at the start of the term).
- What happens if you ignore both of
these requirements (sufficient/proper use of functions and the prohibition
on the use of global variables).
- If you define no functions or just
a single function and your program includes any global variables then
you will be awarded no credit for this assignment.
- The function-related & global variable
penalties are applied on top of other style penalties but the lowest
grade that may be awarded is a GPA of 0 (no negative scores will be
awarded).
Contrary to student rumors these penalties are not specified in order to "curve
the grades down" or to only allow a certain number of students to pass the
course. Besides learning the mechanics of defining and calling functions you
need to use them properly. For instances you shouldn't complete a course that
teaches you how to write short stories and pen tales that are grammatically
correct and may even use metaphorical references and include multiple characters
if they include hackneyed metaphors and shallow character development. Because
the penalties are quite strict then typically most/all (hopefully the latter)
students will implement their solutions in the correct fashion.
Resources:
- You must use this code in order be awarded credit
[Starting code]. You can (and really
must) change the code in the start()
function but you cannot change the code in the functions that initialize the
list to the different starting positions. The predefined starting positions
are needed for testing. It allows the markers (and you) if your program is
producing the correct results at the correct point in time (turn).
- Sample output files
- Although all the examples dealing with lists can
help you with the assignment there is [one
particular lecture example] that illustrates the difference between list
variables and the list it refers to. This point is illustrated by showing
the correct and incorrect way to copy a list.
Summary:
You are to implement a text-based biological simulation: Conway's "Game of
Life". Given a starting pattern of life forms in the simulation ('biosphere')
the program will update
the pattern according to new births and deaths that
occur during that time period (turn). Each location (element in
a 2D list) in a biosphere either contains: an empty space or a life form ("Critter"). As each
turn passes in the simulation a new life form may be born into an empty square or
an existing Critter may die off in an occupied location. To
get any credit for your submission your program must be able to initialize
the two lists using any of the 6 starting patterns and
it must display the
before/after state of the world with the same appearance as the code provided in
the display function.
Important grading
point:
One requirement in order to get any credit for this assignment your program
must, at a minimum, use
the six starting patterns: oneEmpty(), twoSingleCritter(), threeSingleBirth(), fourthSimpleBirth(),fifthCreateListEdgeCases() and sixthComplexCases(). The
more of the initial six cases that your program can correctly process, the
higher will be your grade. Each of the functions will initialize a 10x10 list.
Your program does not have to handle lists of other sizes. When it first runs
your program must allow the user to
choose via a menu which of the 6 starting patterns will be used for the
simulation. You
can write additional functions with different initial patterns but your program
must handle the 6 starting cases.
Although additional test cases won't increase your grade it may reduce the
likelihood of bugs in your program (increased testing should decrease the
probability of a bug).
The choice of starting pattern will only appear once at the beginning. After the
choice has been made the program will apply the rules of births and deaths.
Important grading
point: Your program functionality marks will only be awarded if your program
produces the same results as these outputs. For example, function "oneEmpty()"
starts out empty and shouldnever contain a Critter in the pattern.
Function "sixthComplexCases()"
will produce a stable pattern of 4 Critters in a square by turn 20. Partial
marks will not be awarded if your pattern of
Critters is 'close' to the pattern produced my program. In addition you need to
correctly and comprehensively document which starting patterns that your program
will handle. Both of these requirements (producing the same patterns in
your output and documenting which cases that your program correctly handles are
necessary to make the marking process reasonable - don't expect the marker
to expend time hand tracing code to figure out if things are working). However,
providing the results that your program must display is also an advantage for
you. You will know if your program is "working or not" based on the pattern
match (immediate and continuous feedback about your progress). But looking at the patterns is not a
substitute for implementing and employing a debugging mode. The debugging mode
can be very useful for helping you determine why and how your
program is malfunctioning (if you have good debugging
output messages)
The code in the starting program is extremely simple and
just initializes the references to the lists ('newWorld'
and 'oldWorld') to an
empty world and displays the result for these lists. The
program that you submit will not do things this way. The
old world is the state of the biosphere before the birth/death
rules have been applied during that turn while the new world is the state after
those rules were applied. The starting code does apply those rules, you need to
write the code yourself to get credit.
Important grading
point:
As mentioned another requirement to get any credit for
your assignment is that the display of the grid must be done using the display() function
Even the grid is required because it makes the display of world easier to read
and interpret for both you and the marker.
Running the simulation
After initializing the starting positions, the program will simulate the births
and deaths of the critters over time on a turn-by-turn basis. The user can
either hit <enter>
to advance the simulation by another turn, 'q'
or 'Q'
to end the simulation. A hidden feature (not displayed as a menu option), the [debug
mode] can be toggled by entering 'd'
or 'D'
when prompted to proceed to another turn.
The births and deaths of critters is based solely upon the number of neighbors
in adjacent/neighboring squares. Each square will have from 3 - 8 neighboring
squares (inner squares have 8, outer squares can have 3 at the corners or 5 on
the top/bottom/left/right edges). The square where the possibility of a birth or
death is being examined is marked with a question mark ? in
the examples below.
|
|
|
|
|
|
Bottom right corner |
|
An inner square |
|
Top row |
|
Births (square is currently empty)
A birth can occur in an empty square if that square has exactly 3 neighbors,
some (non-exhaustive) examples:
Deaths (square currently contains a Critter).
A Critter can die of loneliness if it has no neighbors or only one neighbor.
A Critter can die of overcrowding if it has four or more neighbors
(non-exhaustive number of examples below):
The Critter will continue living if it has 2 or 3
neighbors.
Births and deaths will occur simultaneously in
the simulation. How do the rules of births and deaths relate to the 10x10
world? Each turn the check for births and deaths must be made in each of
the 100 squares with the rules apparently being applied at the same time.
Hint for how things appear simultaneous: As mentioned the 'old' world contains the state of the
biosphere for that turn before the rules have been applied and the 'new'
world will track the after state.
Links to online web-based executable
versions of the Game of Life:
Entering 'd'
or 'D' will toggle
debugging mode (False becomes True, True becomes False). The flag 'debugOn'
will track whether debugging message are to appear or not and by default the
mode is 'off'.
debugOn = False
When the flag is set to '
True'
debugging messages will appear, otherwise they will not:
if(debugOn == True):
print("<<<Some debugging message>>>")
The exact content of the debugging messages is left to
your discretion. As the name implies the debugging tool should be used to help
you test and debug your program. Here are examples of debugging messages: 1) Display
greater details: the neighbor count as well as births and deaths for each square 2) More
sparse annoucements specifying only where births and deaths have occurred.
Again you are not bound to produce these exact messages in order to get credit
for the debugging feature but they are provided to give you an idea of how you
can use this feature to test your program.
This global variable for the debugging flag is the sole exception on the
prohibition on the use of global variables in your program. No penalty will be
applied for using this debugging flag but the usual
penalty will be applied for other global variables e.g
turn= 1
def display(oldWorld,newWorld):
print("Turn #%d" %turn)
Global
constants (e.g. SIZE = 10) should be used when appropriate. Penalties
for lack of constants may be applied when it's appropriate to define one and one
hasn't been defined for that program.
In addition to grading on whether the above functionality was correctly
implemented TAs will also look at documentation and style.
- Python documentation: contact
information (your name, student identification number and tutorial number).
This should be specified in the header of the program (very top of your
program in the form of Python documentation).
-
Identifying
information:
All assignments should include contact information (full name, student
ID number and tutorial section) at the very top of your program.
-
Program version (dates are an acceptable
alternative)
Under the version you should specify which assignment
features were implemented in that version.
-
Any program
limitations or weaknesses.
- If
you don't know how to document a program then refer to the "Intro
to programming" section of the course.
-
New documentation requirement starting with A3 and
applies to all successive assignments:
[Inline documentation]
(specified just before each function is defined): list the features of
the program that were implemented in a particular function,
the return type(s) as well as the type(s) of the arguments.
Style requirements (-0.1
penalty for each now violation of a category there is no maximum cap on the
number of style penalties that may be applied (5 categories of penalties
means that a maximum penalty of -0.5 may be applied)
- Naming conventions: You should employ
good naming conventions for identifiers (variables, constants, function
names, program file names).
- Named
constants should be used as appropriate (i.e. if they aren't
defined and used when they should be then a penalty will be incurred).
-
Yes do it this way! |
No. Not this way! |
#Defining 3
named constants LEFT = 0
RIGHT = 1
CENTER = 2 #Using the named constant 'RIGHT' if (silverLockPosition == RIGHT): |
if (silverLockPosition
== 0): #What does 0 stand
for??? |
- The program code should have
appropriate white space (specified in the "Intro to programming
lecture') and alignment (specified throughout the lecture notes).
- Code is self documenting e.g. Clear
expressions (e.g. mathematical, Boolean). Good variable names and the
use of named constants are examples of writing self documenting code but
specifying clear expressions is important enough to be included in a
separate category.
- Of course if a student implements an extreme
case of inefficient code (e.g. multiple loops or branches are used when
one will do) then penalties may be applied but this is generally rare.
- Your program should follow the 5 rules of
thumb for designing user friendly software (distilled from Jakob
Nielsen's 10 usability heuristics) which were included in the notes on
'Repetition' e.g. good error handling (such as prompts to the user to
enter the required information clearly indicate what is required, good
error messages should be provided for erroneous input) minimizing the
user's memory load, being consistent, providing clearly marked exits &
providing feedback as appropriate.
- Having at least one violation
in one of the above general style requirements will result in -0.1
penalty to marking. Multiple violations in one category still
results in a single penalty (e.g. 3 bad variable names will still result
in a -0.1 penalty). However violations between categories will
result in cumulative penalties (e.g. a program that includes poor
variable names, messy program layout and poor error handling will
receive a -0.3 penalty)
Function specific style requirements (principles of good design for
functions) -0.2 penalty will be applied for each of the 3 function
specific style requirements that have been violated.
- Functions are one screen in length
(normal screen resolution say ~30 lines max of code (excludes whitespace
and documentation).
-
Functions implement one well defined task (Appropriate: processLivingRoomCommands() vs.
something that's not appropriate processlivingRoomRunIntroductionRunConclusion()).
-
Code in one function is not duplicated in another
function (not in the notes but this is just common sense that you don't
write two functions where there's overlapping code - the overlap should
likely be taken out of both functions and moved to another separate
function). In some assignments there may appear to be some overlap (e.g.
each room displays a menu of options but the specific options displayed
will not be identical.
- Violating any of
the function specific style requirements will result in a -0.2 penalty
for a violation in each of the 3 categories. E.g. a program that
includes a function that exceeds the maximum length and implements two
or more tasks would incur a -0.4 penalty.
Reminder of critical style requirements
Don't forget that [critical
design requirements] (proper use of functions, no global variables) must
also be followed.
-
What to submit: In a typical semester submitted
programs must run on the computer science network running Python 3.x. If you
write you code in the lab and work remotely using a remote login program
such as Putty or SSH then you should be okay (assuming you don't login to a
non-Linux computer). If you choose to install Python on your own computer
then it is your responsibility to ensure that your program will run properly
here. Remote learning version: If it won't run using Python 3.x on any
computer then it won't be awarded credit. It's up to you if you wish use
the graphical program builder IDLE (or another development environment
rather than a simple text editor) to write/run your programs but if you do
you submit your program in the form of text ".py"
file or files.
-
Late assignments or
components of assignments: will not be accepted for marking without
approval for an extension beforehand. Alternate submission mechanisms (non
exhaustive list of examples: email, uploads to cloud-based systems such as
Google drive, time-stamps, TA memories) cannot be used as alternatives if
you have forgotten to submit work or otherwise have not properly submitted
into D2L. Only files submitted into D2L by the due date is what
will be marked, everything else will be awarded no credit. The final cut
off date after which full assignments will not be accepted is after the maximum
progressive penalty (listed below) can be applied. The final cut off
date for mini-assignments is the due date because no late submissions are
allowed for these smaller programs.
-
Extensions may
be granted for reasonable cases by the course instructor with the receipt of
the appropriate documentation (e.g., a sworn declaration with a commissioner
of oaths). Typical examples of reasonable cases for an extension include:
illness or a death in the family. Example cases where extensions will not be
granted include situations that are typical of student life: having multiple
due dates, work commitments etc. Tutorial instructors (TAs) will not be able
to provide extension on their own and must receive permission from the
course instructor first. If
you request an extension from me let me know the name of your tutorial
instructor and the tutorial number because the markers won't accept
late submissions without directly getting an email from me.
-
How you will be graded for full assignments. As
mentioned, as well as being marked on whether "your program works" you will
also be marked on non-functional requirements such as style and
documentation. Consequently this assignment will include a separate [marking
checklist]. Besides seeing your grade point in D2L you can also see the
detailed feedback that your TA will enter for each student. You can access
the grading sheet in D2L under Assessments->Dropbox and
then clicking on the appropriate assignment link. If you still cannot find
the grading sheet then here is a [help
link]
-
Questions about
grading afterward: Assignments will be marked by your tutorial
instructor (the "Teaching Assistant" or "TA") for your [tutorial
section]. When you have questions about marking this is the first person
that you should be directing your questions towards. If you still have
question after you have talked to your TA, then you can talk to your [course
(lecture) instructor] but please indicate in your email that you first
contacted your TA.
Method of submission:
You are to submit your
assignment using D2L [help
link]. Make
sure that you [check
the contents of your submitted files]
(e.g., is the file okay or was it corrupted, is it the correct version etc.).
It's your responsibility to do this! (Make sure that you submit your
assignment with enough time before it comes due for you to do a check). If don't
check and there were problems with the submission then you should not expect
that you can "learn your lesson" and simply resubmit.
-
Multiple submissions are allowed for this assignment (all versions are kept
in D2L): You can (and really should) submit work as many times as you wish
before the due date. However
only the latest version of all the files is what will be marked, everything
else will be ignored (because it is not fair to your marker to sort through
multiple versions of your files).
-
Do
not use compression utilities (such as zip) or archiving utilities (such as
tar) otherwise your submission may not be marked. The space savings in D2L
is not worth the extra time required by the marker to process each
submission.
Late
submissions for full assignments when there is no extension granted: Make
sure you give yourself enough time to complete the submission process so
you don't get cut off by D2L's deadline (or your submission will be
automatically flagged as late by D2L and it will be graded appropriately)..
Submission received: |
On time |
Hours late : >0 and <=24 |
Hours
late: >24
and <=48 |
Hours
late: >48
and <=72 |
Hours
late: >72
and <=96 |
Hours
late: >96 |
Penalty: |
None |
-1 GPA |
-2 GPA |
-3 GPA |
-4 GPA |
No credit
(not accepted) |
Collaboration:
Assignments must
reflect individual work;
group work is not allowed in this class nor can you copy the work of others.
Some "do nots" for your solution: don't publically
post it, don't email it out, don't show it to other students.
For more detailed information as to what constitutes academic misconduct (i.e.,
cheating) for this course please read the following [link].
Unless otherwise told
you are to write the code yourself and not use any pre-created functions (or
methods). For most assignments the usual acceptable functions include: print(), input() and
the 'conversion' functions such as int(), float(), str().
Look at the particular assignment description for a list of other
functions/methods that you are allowed to use and still get credit in an
assignment submission. If it's not listed then you should assume that you won't
be able use the function and still be awarded credit. Note: This is a
prohibition on using functions that someone else has wrote. You can (actually
must) define your own functions for this assignment.