NYJC 2026 Prelim P2
Uploaded by Kozak327 · 4 October 2026
Preview
Text from the first pagesThis document consists of 12 printed pages and 1 insert. © NYJC 2026 [Turn over NANYANG JUNIOR COLLEGE JC2 PRELIMINARY EXAMINATIONS Higher 2 COMPUTING 9569/02 Paper 2 (Lab-based) 11 August 2026 3 hours Additional Materials: Electronic version of MEMBERS.txt file Electronic version of FACILITIES.txt file Electronic version of BOOKINGS.txt file Electronic version of COMBATANTS.txt file Electronic version of EQUIPMENT.txt file Electronic version of STYLES.css file Electronic version of CLIENT.py file Electronic version of GAME_LOGIC.py file Insert Quick Reference Guide READ THESE INSTRUCTIONS FIRST Answer all questions. All tasks must be done in the computer laboratory. You are not allowed to bring in or take out any pieces of work or materials on paper or electronic media or in any other form. Approved calculators are allowed. Save each task as it is completed. The use of built-in functions, where appropriate, is allowed for this paper unless stated otherwise. Note that up to 6 marks out of 100 will be awarded for the use of common coding standards for programming style. The number of marks is given in brackets [ ] at the end of each question or part question. The total number of marks for this paper is 100.
2 9569/02/2026 Instruction to candidates: Your program code and output for each of Task 1 to 4 should be saved in a single .ipynb file. For example, your program code and output for Task 1 should be saved as: TASK1_<your name>_<centre number>_<index number>.ipynb Make sure that each of your .ipynb files shows the required output in Jupyter Notebook. Task 1 (34 marks) Name your Jupyter Notebook as: TASK1_<your name>_<centre number> <index number>.ipynb A prototype for a turn-based combat game needs to be created using Object-Oriented Programming and a linked-list priority queue. The game has a player and a series of enemies. Each combatant has a cooldown that determines how frequently they can act. Combatants act in order of readiness — the one closest to acting goes first. For each of the sub-tasks, add a comment statement at the beginning of the code, using the hash symbol '#', to indicate the sub-task the program code belongs to, for example: In [1]: #Task 1.1 Program code Output: Task 1.1 The class Combatant contains four attributes: • name — a string for the combatant's name • health — an integer for the combatant's current health points • damage — an integer for the amount of damage the combatant deals per attack • cooldown — an integer representing the number of turns between the combatant's actions The class Combatant has the following methods: • A constructor that takes name, health, damage, and cooldown as parameters. • take_damage() that takes an integer points as a parameter and reduces health by that amount. • is_dead() that returns True if health is less than or equal to zero, and False otherwise. Write program code to declare the class Combatant and its methods. [3]
3 9569/02/2026 [Turn over Task 1.2 A priority queue is implemented as a linked list using two classes: Slot and PriorityQueue. A missing node is represented by None. Each node in the priority queue has its priority represented by an integer: smaller integers represent higher priority. The class Slot represents a single node in the linked list and contains the following attributes: • combatant — the Combatant object stored in this slot • turns_before_ready — an integer initialised to the combatant's cooldown value, representing how many turns must pass before this combatant can act • next — a reference to the next Slot, initialised to None It also contains the following methods: • get_priority() returns turns_before_ready as the node’s priority value. • update_priority() that decrements turns_before_ready by 1 if it is greater than 0. turns_before_ready must not end up with a value less than 0. Write program code to declare the class Slot and its methods. [3] The class PriorityQueue manages the linked list and contains the following attributes: • head — a reference to the first Slot in the list, initialised to None • count — an integer tracking the number of combatants in the queue, initialised to 0 It also contains the following methods: • get_combatants() traverses the linked list and returns a list of all Combatant objects currently in the queue, without removing them. • add() takes a Combatant as a parameter and inserts it into the linked list in ascending order of priority. If other nodes in the linked list have the same priority, the combatant is added after all existing slots with the same priority. • remove() takes a string name as a parameter and removes the Slot whose combatant has that name from the linked list. • pop_highest_priority() removes and returns the highest -priority Combatant, only if its turns_before_ready value is 0. The method returns None if the queue is empty or the highest- priority combatant is not yet ready. • update_slots() calls update_priority() on every Slot in the linked list. Write program code to declare the class PriorityQueue and its methods. [9]
4 9569/02/2026 Task 1.3 Two classes inherit from Combatant: Player and Enemy. Player represents the human-controlled combatant and contains: • the method get_opponent_choice() that takes a list of Combatant objects as a parameter, displays each with a numbered index, prompts the user to choose an opponent by inputting a number, re-prompts until a valid integer index is entered, and returns the chosen Combatant. Enemy represents a computer-controlled combatant and contains: • the method get_opponent_choice() that takes a list of Combatant objects as a parameter and returns the first Combatant in the list that is an instance of Player. Write program code to declare the Player and Enemy classes and their methods. [5] Task 1.4 The text file combatants.txt stores data about all combatants in the game in comma -separated format. The first row is a header. Each subsequent row contains: • name — the combatant's name; the value "player" identifies the human player • health — an integer • damage — an integer • cooldown — an integer Write program code to: • read the data from combatants.txt • create a Player object for the row where name is "player", and an Enemy object for all other rows • store a global reference to the Player object in a variable called player • add each combatant (Player or Enemy) to a global PriorityQueue [5]
5 9569/02/2026 [Turn over Task 1.5 When the game is played, combatants act in turn order determined by the priority queue. On each turn: 1. If pop_highest_priority() returns None, no combatant is ready — skip to step 6. 2. Otherwise, the active combatant chooses an opponent from the queue. 3. The active combatant deals its damage value to the chosen opponent, and a message is printed, for example: player dealt 8 damage to mosquito! 4. If the opponent is dead, an appropriate message is printed (e.g. mosquito dies!) and the opponent is removed from the queue. 5. The active combatant is re-added to the queue at the end of the turn. 6. Call update_slots() on the queue to advance time forward. 7. Repeat from Step 1 until all ready combatants have acted. The game continues until the player is dead or is the only combatant remaining. After the game ends, print "You died!" if the player is dead, otherwise print "You won!". Write program code for the game loop and run it. [8] Test your program by providing inputs until the game ends. [1] Save your Jupyter Notebook for Task 1.
6 9569/02/2026 Task 2 (12 marks) A grid-based computer game is played over the network on a 5 x 5 board where a player navigates blindly through coordinate updates to collect items or trigger hidden effects. (0,0) (0,4) (4,0) (4,4) Objects on the grid can be classified into four categories as follows: Object Symbol E
Content continues in the PDF. Download PDF
Related notes
- NYJC 2026 Prelim P1Exam Papers · 2026
- DHS 2026 Y6 H2 Computing Prelim Paper 2_finalExam Papers · 2026
- ACJC 2026 JC2 Computing Prelim Paper 2 (Practical)Exam Papers · 2026
- 2026_NJC Prelim_Computing_P2.pdfExam Papers · 2026
- 2026_JPJC_Computing_Prelim_P2_finalExam Papers · 2026
- 2026_JPJC_Computing_Prelim_P1_markschemeExam Papers · 2026
- 2026_JPJC_Computing_Prelim_P1_finalExam Papers · 2026
- 2026 ACJC Prelim Computing Paper 2Exam Papers · 2026
- 2024 ACJC Computing PromoExam Papers · 2024
- 2023 ACJC Promo QPExam Papers · 2023
- 2022 ACJC Computing Promo Paper 2Exam Papers · 2022
- 2021 ACJC Computing Promo Paper 2Exam Papers · 2021
- See all H2 Computing notes

