Module Title: Programming Coursework Using Python
Assessment Title: Written Assessment
Submission date and Time: 19th August 2020 at 9:30AM
This assignment is worth 100% of the total marks available for this module. If coursework is submitted late (and where there are no extenuating circumstances):
• If the assessment is submitted no later than 24 hours after the deadline, the mark for the assessment will be capped at the minimum pass mark;
• If the assessment is submitted more than 24 hours after the deadline, a mark of 0 will be given for the assessment.
Submission Instructions
All coursework should be submitted via email.
Description
Type
Name
Cover sheet
One pdf file
[Student number].pdf
Code for Q1
One Python file
Q1 [Student number].py
Code for Q2
One Python file
Q2 [Student number].py
Code for Q3
One Python file
Q3 [Student number].py
Code for Q4
One Python file
Q4 [Student number].py
Any code submitted will be run on a system equivalent to that available on the laptops provided to the students, using Python3, and must be submitted as stipulated in the instructions above. The code should run without any change.
Any deviation from the submission instructions above (including the number and types of files submitted) may result in a mark of zero for the assessment or question part.
Staff reserve the right to invite students to a meeting to discuss coursework submissions.
Assignment
This coursework is comprised of four questions which represent programming challenge. Answer the following questions by implementing the program described in each of them.
Question 1 – Contact Book
Write a command line program for storing contacts’ details. For each contact, the program should store the following information in a SQLite database: first name, last name, address, phone number, email address, and contact creation date. Previous contact information should be loaded when the program starts. On top of storing contact information, the program allows to: delete contacts, update contact information, and list saved contacts using different parameters, e.g., alphabetical order or contact creation date. Also, the program allows the user to display all the contacts that have duplicated consecutive characters either in the first name or in the last name. For example, ’William Shakespeare’ and ’Virginia Woolf’ comply with the rule, while ’Charles Dickens’ does not. It is mandatory to use regular expressions to implement this last feature.
Question 2 – File System Display
Write a command line program that prints the directory and file system tree structure that originates in the current directory. The algorithm used to explore the tree must be recursive. Sample output:
./
—-picture1.png
—-slideShow.pptx
—-UniProject
——–doc1.docx
——–doc2.docx
——–old files
————doc1.old
—-personalstuff
——–holidays.xlsx
In the example, the current folder containts two files (i.e., ”picture1.png” and ”slideShow.pptx”) and two directories (i.e., ”UniProject” and ”personalstuff”). Directory ”UniProject” contains two file (i.e., ”doc1.docx” and ”doc2.docx”) and one folder (i.e., ”old files”) with one file. Directory ”personalstuff” contains only one file, i.e., ”holidays.xlsx”.
Question 3 – Amoeba Wars
Write a command line program that allows to play the game of Amoeba Wars for two human players. A description of the game is given below.
……………………………………………………………..
The game is played on a square grid. The first player is ’O’ and the other is ’X’. The game starts with an ’O’ amoeba in the bottom left corner, and an ’X’ amoeba in the top right corner (all the examples suppose a game played on an 8×8 board):
’O’ plays first and has one move. Then, the players take turns in making three consecutive moves. Each move can be to:
• Create a new amoeba, by writing the player’s symbol in an accessible empty cell, or
• Kill one of the opponent’s amoebas in an accessible cell, by shading the cell. A shaded cell is not empty and is not an amoeba.
A cell is accessible if it is next to one of the player’s live amoebas, horizontally, vertically, or diagonally.
For example, in the following opening firstly ’O’ played at B2, secondly ’X’ created three new Amoebaes (i.e., G7, F6, and E5), and finally ’O’ created two (i.e., C3 and D4) and killed one of ’X’s (i.e., E5):
A player must make all the moves. The game ends when a player cannot make all the moves. The score of a player is the number of live amoebas they have when the game ends, plus the number of opponent’s amoebas killed. The player with the higher score wins.
……………………………………………………………..
Your program should allow to play a two-players game of Amoeba War from the command line. Initially, the game asks for the size of the board. The board must be square (e.g., 6×6, 7×7, 8×8). Once the size has been entered, the initial board is drawn and the ’O’ player starts. The drawing displays the board, the column and row references (i.e., A, B, C,… and 1, 2, 3,…, respectively), and the current score on top of the board, as illustrated (supposing an 8×8 board):
O 01 – 01 X
——————
8| | | | | | | |X|
7| | | | | | | | |
6| | | | | | | | |
5| | | | | | | | |
4| | | | | | | | |
3| | | | | | | | |
2| | | | | | | | |
1|O| | | | | | | |
——————
|A|B|C|D|E|F|G|H|
On each turn, the program informs the current player of the moves left and provides a list of feasible moves. For example, the feasible moves for player ’O’ in the above board are: A2, B2, and B1. The players can make their moves one at the time by entering the coordinates of the chosen cell (e.g., A2). The program recognises invalid moves and informs the player in case of a mistake. After each move, the program draws the state of the board, informs the current player of the moves left, and provides a list of feasible moves. Finally, the program recognises when the game is over and a message is displayed to show the final score and congratulate the winner. After that, the program asks if the players want to play another game.
Question 4 – Amoeba Wars with AI
This question builds upon Question 3 and is intended to award the students that are up for a challange.
Program a simple AI player for the game of Amoeba Wars. On each turn, the AI player should choose the set of moves (one move in the first turn of the ’O’ player and three moves in any subsequent turn) that increases the difference between its score and the opponent’s score the most. Ties are broken by randomly choosing one among the best set of moves.
Your program should allow to play a single-player game of Amoeba Wars versus the AI. The game should run exactly as described in Question 3, with the difference that it is single-player and that the human player can choose to be the the ’O’ player, ’X’ player, or a randomly assigned player.
On the AI’s turn, the AI player makes all the moves and then the updated board is displayed.
The code for question 4 should run as-is, i.e., it should not require the code from Question 3.
Learning Outcomes Assessed
• LO1: Use the Python programming language to complete programming tasks.
• LO2: Demonstrate familiarity with basic programming concepts and data structures
• LO3: Implement Abstract Data Structures in an Object-Oriented style
• LO4: Contrast common algorithms for searching and sorting.
• LO5: Contrast, select and use data structures appropriate to a given problem.
• LO6: Apply regular expressions.
• LO7: Design, implement and utilise relational databases.
Criteria for assessment
Credit will be awarded against the criteria of functionality and code quality:
Functionality: Does the code perform the required task correctly, accurately, and efficiently?
Code quality: Is the code elegant and well-written; easy to run; simplified by the use of built-in languages features where appropriate; readable and easy to follow; properly commented? Are appropriate functions defined and written to enable reuse? Are classes defined and used effectively? Is the code ’pythonized’?
The mark breakdown for each part is given in the following.
Question 1 [Total: 30 marks]
• Functionality: User interface. 5 marks
• Functionality: Contact creation. 5 marks
• Functionality: Contact deletion. 5 marks
• Functionality: Ordered contacts listing. 5 marks
• Functionality: Display of contacts with duplicated consecutive characters. 5 marks
• Code quality. 5 marks
Question 2 [Total: 30 marks]
• Functionality: Recursive definition. 10 marks
• Functionality: Output as expected. 5 marks
• Functionality: Program correctly displays the directory and file tree structure of the current directory. 10 marks
• Code quality. 5 marks
Question 3 [Total: 30 marks]
• Functionality: User interface. 5 marks
• Functionality: Game flow. 10 marks
• Functionality: Feasible moves. 5 marks
• Functionality: Ending condition and score calculation. 5 marks
• Code quality. 5 marks
Question 4 [Total: 10 marks]
• Functionality: AI logic. 8 marks
• Code quality. 2 marks
For each item evaluated, partial marks can be assigned as illustrated in the following table.
Distinction
(70-100%)
Merit (60-69%)
Pass (50-59%)
Fail (0-49%)
Functionality
Fully working functionality, implemented
efficiently, and
achieved using a relevant python approach.
Functionality working correctly but implemented in a non-efficient fashion.
Faulty functionality which works
similarly yet not exactly as
described in the
question, and/or presents at least an error, and/or wrong output.
Functionality not implemented or
completely faulty
implementation with wrong
behaviour and/or output.
Code Quality
Code is elegant, with no
redundancies,
well commented, easy to run,
perfectly modular (i.e., appropriate functions and/or classes defined), pythonized, and
makes smart use of built-in
language features and classes.
The code complies with less than seven of the characteristics required for distinction.
The code complies with less than five of the characteristics required for distinction.
The code complies with less than tree of the characteristics required for distinction.
Feedback and suggestion for future learning
Feedback on your coursework will address the above criteria. Feedback and marks will be returned on the return date via Learning Central.