Recent Question/Assignment

Programming Principles (CSP1150)
Assignment 1: Individual programming assignment (“Loot Box Simulator” program)
Assignment Marks: Marked out of 20, worth 20% of unit
Due Date: 6 April 2020, 9:00AM Extended to 14 April 2020, 9:00am
Background Information
This assignment tests your understanding of and ability to apply the programming concepts we have covered in the unit so far, including the usage of variables, input and output, data types and structures, selection, iteration and functions. Above all else, it tests your ability to design and then implement a solution to a problem using these concepts.
Assignment Overview
In many modern video games, players can use real money to purchase “in-game currency”, which can be used to purchase “loot boxes” – a virtual package containing a number of random in-game items. The loot box can be opened to receive the items, some of which are much more desirable (and hence less likely to be received) than others. Loot boxes are similar to buying packets of trading cards or capsule toys, and have been criticised as a form of gambling.
In this assignment you are required implement a “Loot Box Simulator” that allows the user to simulate the process of buying in-game currency (“gems”), spending it on loot boxes, opening the loot boxes, and tracking information about the items received. As well as testing your programming ability, this assignment aims to highlight the frivolity of loot boxes and make you think twice before spending a lot of money on a slim chance of receiving a virtual item. If you struggle to control or track how much you spend on in-game purchases, please seek help from a service such as Gambling Help Online (1800 858 858).
The entirety of this program can be implemented in under 115 lines of code (although implementing optional additions may result in a longer program). This number is not a limit or a goal – it is simply provided to prompt you to ask your tutor for advice if your program significantly exceeds it.
Tip: You can (and should) make a start on this assignment as early as the end of Week 2.
When starting out with programming, it is common to encounter difficulties that temporarily slow or stop your progress. The sooner you start, the more time you have to work through difficulties.
Program Output Example
To help you visualise the program, here is an example screenshot of the program being run:
Pseudocode
As emphasised by the case study of Module 5, it is important to take the time to properly design a solution before starting to write code. Hence, this assignment requires you to write and submit pseudocode of your program design as well as the code for the program. Furthermore, while your tutors are happy to provide help and feedback on your assignment work throughout the semester, they will expect you to be able to show your pseudocode and explain the design of your code.
You will gain a lot more benefit from pseudocode if you actually attempt it before trying to code your program – even if you just start with a rough draft to establish the overall program structure, and then revise and refine it as you work on the code. This back and forth cycle of designing and coding is completely normal and expected, particularly when you are new to programming. The requirements detailed on the following pages should give you a good idea of the structure of the program, allowing you to make a start on designing your solution in pseudocode.
See Reading 3.3 and the Blackboard Discussion Board for tips and advice regarding pseudocode.
Write a separate section of pseudocode for each function you define in your program so that the pseudocode for the main part of your program is not cluttered with function definitions. Ensure that the pseudocode for each of your functions clearly describes any parameters that the function receives and what the function returns back to the program. Pseudocode for functions should be presented after the pseudocode for the main part of your program.
It may help to think of the pseudocode of your program as the content of a book, and the pseudocode of functions as its appendices: It should be possible to read and understand a book without necessarily reading the appendices, however they are there for further reference if needed.
Only one function is required in this assignment (detailed later in the assignment brief).
Tip: Do not attempt to implement the entire program at once. Work on one small part (a single requirement or even just part of a requirement) and only continue to another part once you have made sure that the previous part is working as intended and that you understand it.
It can also be useful to create separate little programs to work on or test small sections of code.
This allows you to focus on just that part without the rest of the program getting in the way, and allows you to work on a section without necessarily having completed prior sections.
Program Requirements
In the following information, numbered points describe a core requirement of the program, and bullet points (in italics) are additional details, notes and hints regarding the requirement. Ask your tutor if you do not understand the requirements or would like further information.
1. Print a “Welcome to Loot Box Simulator” message, and create the following variables:
? Variables named “gems”, “boxes”, “boxes_opened” and “total_spent”, all set to 0. These variables will keep track of how many gems the user currently has, how many loot boxes they currently have, how many loot boxes they have opened, and how much they have spent.
? An “items” variable, set to an empty list. This will keep track of the items that the user has obtained by opening loot boxes. Each item is simply a string of “Common”, “Rare”, “Epic” or “Legendary”.
2. Start a while loop that will repeat until the user chooses to quit. The body of this loop must…
2.1. Print the current gems and loot boxes, e.g. “You have 350 gems and 2 loot boxes.”
2.2. Print a list of options for the user to choose from, and then prompt them for their choice:
? Note that you do not need to convert the user’s choice to an integer since we are not treating the value numerically. See the Task 2 recording of Workshop 2 on Blackboard for further discussion.
2.3. If the user chooses ‘1’ (buy gems), add 550 to gems and 19.95 to total_spent, then print a “Thank you for your purchase” message.
? In this program, assume that the user can always afford to buy gems – you do not need to keep track of how much money the user has or implement any kind of payment processing system.
2.4. If the user chooses ‘2’ (buy loot box), check if the user has at least 100 gems. If so, subtract 100 from gems, add 1 to boxes, and print a “Loot box purchased” message. Otherwise, print an “Insufficient gems” message.
2.5. If the user chooses ‘3’ (open loot box), check if boxes is more than 0. If so, subtract 1 from boxes, add 1 to boxes_opened, and call the “open_box()” function (detailed below). Extend the items list with the list of items returned by the open_box() function. If the user has no loot boxes, print an “Insufficient loot boxes” message.
? The open_box() function requires a parameter value to tell it how many items are in the loot box (i.e. how many items to randomly select). In this assignment, all loot boxes contain 4 items.
? The open_box() function returns a list of items, e.g. ['Epic', 'Common', 'Rare', 'Common'].
The “.extend()” method can be used to add these items to the end of the items list.
? Check the Blackboard Discussion Board for help and advice regarding the function and items list!
2.6. If the user chooses ‘4’ (view statistics), display the total_spent and the number of boxes_opened. If boxes_opened is more than 0, also display how many of the user’s items are Legendary, and what percentage of their total number of items are Legendary.
? The “.count()” method can be used to count the number of times something appears in a list.
? Round the percentage of Legendary items to two decimal places.
2.7. If the user chooses ‘5’ (quit), print a “Goodbye” message. The while loop started in Requirement 2 should then end.
? Since there is no more code needed after the body of this loop, the program ends at this point.
2.8. If the user enters any other value, print an “Invalid choice” message.
Tip: Check the Blackboard Discussion Board on a regular basis – extra tips, examples and advice regarding the assignment will be posted there throughout the semester. You are also welcome to
make your own posts if you have questions – but don’t upload your work to the discussion board!
Email your work to your tutor at least once while working on your assignment, so that they can give you advice and feedback on it. This will definitely help you to improve your work (and your mark)!
The “open_box” Function
You must create a function named “open_box” and use it to implement Requirement 2.5. The function requires one parameter named “num_items”, which is an integer specifying how many items are in the loot box (i.e. how many items to randomly select). In this assignment, all loot boxes contain 4 items – specify a parameter value of 4 when calling the function.
The function must do the following:
1. Print an “Opening loot box” message.
2. Select num_items items of random rarities using the probabilities in the table below, and print a message about each item. The message should include “Item # of #”, as per the image.
? This is likely to involve a loop, the “random.randint()” function and an if/elif statement, but other approaches are possible including one using the “random.choices()” function.
3. Return a list consisting of the rarities of the selected items.
? e.g. If the rarities of the random items were Common, Rare, Common, Legendary, the list would contain ['Common', 'Rare', 'Common', 'Legendary']. This list is sent back to the main program, so that it can keep track of all of the items that the user has received from opening loot boxes.
This table specifies the probabilities of the different item rarities. Your function must apply these probabilities to each item it selects. e.g. There should be a 5% chance of an item being Legendary…
Item Rarity Probability Range in 1-100
Legendary 5% 1-5
Epic 10% 6-15
Rare 35% 16-50
Common 50% 51-100
Since a likely approach involves generating a random number between 1 and 100, I have also indicated the range of each rarity on a 1 to 100 scale.
The definition of the function should be at the start of the program, and it should be called where needed in the program. Revise Module 4 if you are uncertain about defining and calling functions.
Ensure that the function does exactly what is specified above and nothing more – it is important to adhere to the stated specifications of a function, and deviating from them will impact your marks.
Optional Additions and Enhancements
Below are some suggestions for minor additions and enhancements that you can make to the program to further test and demonstrate your programming ability. They are not required and you can earn full marks in the assignment without implementing them.
? Use variables to store the cost of gems, the amount of gems received, and how many gems a loot box costs. This makes the program more flexible, allowing you to tweak the values as desired. Make sure to refer to the variables when printing the menu, so that the correct costs and amounts are always shown!
? Enhance the “open_box()” function so that it makes the process of opening a loot box more exciting. For example, add short delays when revealing items to build anticipation
(import the “time” module and use “time.sleep()” to achieve this), and include a congratulatory message when the user receives an Epic or Legendary item.
? Enhance the “open_box()” function to make it so that a loot box cannot contain four Common items. This is likely to involve checking if the list of items from the current loot box contains thee Common items when selecting the final item.
? When printing the user’s current number of gems and loot boxes, make sure that the message says “loot box” instead of “loot boxes” if boxes is 1. Alternatively, use Unicode characters such as “?” and “?” to represent gems and loot boxes, e.g.
? When the user enters ‘4’ to view statistics, ensure that the total amount spent is always shown with two decimal places. e.g. “$39.90” rather than “$39.9”. See Reading 2.2 for help.
? When the user enters ‘4’ to view statistics, also include the total amount of gems that they have purchased. You do not need a variable to keep track of this – it can be calculated using other variables and values that you already have in the program, particularly if you have also implemented the first of the features listed above.
? When the user enters ‘4’ to view statistics, include the number and percentage for all item rarities, rather than just Legendary items. Consider defining a function that can be passed the item list and a string of a desired rarity, and will print or return the appropriate statistics.
? When the user enters ‘5’ to end the program, print information for gambling support services if total_spent is at least 100. One such service would be Gambling Help Online (gamblinghelponline.org.au, 1800 858 858).
Submission of Deliverables
It is strongly recommended that you send your work to your tutor for feedback at least once prior to submitting it. Once your assignment is complete, submit both your pseudocode (in PDF format) and source code (“.py” file) to the appropriate location in the Assessments area of Blackboard. Zipping the files is not required. An assignment cover sheet is also not required, but be sure to include your name and student number at the top of both files (not just in the filenames).
Academic Integrity and Misconduct
The entirety of your assignment must be your own work (unless otherwise referenced) and produced for the current instance of the unit. Any use of unreferenced content you did not create constitutes plagiarism, and is deemed an act of academic misconduct. All assignments will be submitted to plagiarism checking software which includes previous copies of the assignment, and the work submitted by all other students in the unit.
Remember that this is an individual assignment. Never give anyone any part of your assignment – even after the due date or after results have been released. Do not work together with other students on individual assignments – you can help someone by explaining a concept or directing them to the relevant resources, but doing any part of the assignment for them or alongside them, or showing them your work, is inappropriate. An unacceptable level of cooperation between students on an assignment is collusion, and is deemed an act of academic misconduct. If you are uncertain about plagiarism, collusion or referencing, simply contact your tutor, lecturer or unit coordinator.
You may be asked to explain and demonstrate your understanding of the work you have submitted. Your submission should accurately reflect your understanding and ability to apply the unit content.
Marking Key
Criteria Marks
Pseudocode
These marks are awarded for submitting pseudocode which suitably represents the design of your source code. Pseudocode will be assessed on the basis of whether it clearly describes the steps of the program in English, and whether the program is well structured. 5
Functionality
These marks are awarded for submitting source code that implements the requirements specified in this brief, in Python 3. Code which is not functional or contains syntax errors will lose marks, as will failing to implement requirements/functions as specified. 10
Code Quality
These marks are awarded for submitting well-written source code that is efficient, wellformatted and demonstrates a solid understanding of the concepts involved. This includes appropriate use of commenting and adhering to best practise. 5
Total: 20

Looking for answers ?