AQA A-Level Computer Science AS Paper 1, June 2025: Question 17
13 marks · Hard difficulty · Programming
Extend the Skeleton Program by writing subroutines WestOfHut and GetClue, modifying PirateWalks, and providing a screenshot of test execution.
Practise this questionQuestion
Question text
17 This question extends the functionality of the Skeleton Program. If the pirate stands
one square to the west of the hut (H), a clue about where the treasure is buried will be
displayed.
What you need to do:
Task 1
Write a new subroutine WestOfHut that checks the pirate’s position.
If the pirate is one square to the west of the hut the subroutine should return true;
otherwise it should return false.
Your solution should work for any map, not just the map provided in the data files.
Task 2
Write a new subroutine GetClue that finds the position of the rock (R) on the map
and the position of the treasure (T) on the hidden map. The distances (number of
squares) between the rock and the treasure are to be calculated in the north-south
direction and the east-west direction. The subroutine should display these distances
with suitable messages.
For example, in Figure 7, the distance between the rock and the treasure is
1 square in the north-south direction and 3 squares in the east-west direction.
Figure 7
… T …
...R …
Your solution should work for any map, not just the map provided in the data files.
A map always has one rock and one treasure.
Task 3
Amend the subroutine PirateWalks so that it calls the WestOfHut subroutine
after the pirate has finished walking to check whether the pirate is one square to the
west of the hut and, if so, calls the GetClue subroutine.
Task 4
Test that the changes you have made work by conducting the following test:
• run your amended Skeleton Program
• if you have answered Question 16, select for the pirate to land where the X is
located on the map.
• enter W
• enter 9NE
• enter W 15
• enter 6E
Evidence that you need to provide
Include the following evidence in your Electronic Answer Document.
17.1 Your PROGRAM SOURCE CODE:
• for the entire subroutine WestOfHut
• for the entire subroutine GetClue
• for the entire subroutine PirateWalks.
[12 marks]
17.2 SCREEN CAPTURE(S) showing the requested test described in Task 4.
The SCREEN CAPTURE(S) must show the map with the pirate’s position as well as
the displayed clue.
[1 mark]
Mark scheme
Show the mark scheme
17 1 3 marks for AO3 (design) and 9 marks for AO3 (programming) 12
Mark
Level Description
Range
A line of reasoning has been followed to arrive at a logically
3 structured working or almost fully working programmed solution. 9–12
All of the appropriate design decisions have been taken.
There is evidence that a line of reasoning has been partially
2 followed. There is evidence of some appropriate design work. 5–8
This is a partially working programmed solution.
An attempt has been made to amend the subroutine
PirateWalks or to create one of the other two subroutines.
Some appropriate programming statements have been written.
There is little evidence to suggest that a line of reasoning has been
1 followed or that the solution has been designed. The statements 1–4
written may or may not be syntactically correct and the subroutines
will have very little or none of the extra required functionality. It is
unlikely that any of the key design elements of the task have been
recognised.
Marking guidance:
Evidence of AO3 design – 3 marks:
Evidence of design to look for in response:
1. Attempt to test for pirate west of hut as a subroutine.
2. Recognise the need for a nested loop to find the rock/treasure in the hidden map.
3. Attempt to calculate distance of treasure from rock in one direction.
Note: AO3 (design) points are for selecting appropriate techniques to use to solve the
problem, so should be credited whether the syntax of programming language
statements is correct or not and regardless of whether the solution works.
Evidence of AO3 programming – 9 marks:
Evidence of programming to look for in response:
4. Correct parameters and return values for WestOfHut.
5. Correct parameters for GetClue.
6. Correctly search for rock.
7. Correctly search for treasure.
8. Correctly calculate distance of treasure from rock in NS and EW direction within
subroutine GetClue
9. Output distance in NS and EW direction within subroutine GetClue DPT if in wrong
subroutine
10. Ensure distances are positive.
11. Call WestOfHut in correct place in PirateWalks.
12. Call GetClue under correct conditions–. – –
Max 11 if code does not function correctly
17 2 Mark is for AO3 (evaluate) 1
**** SCREEN CAPTURE ****
Must match code from 17.1, including prompts on screen capture matching those in
code.
Code for 17.1 must be sensible.
Screen capture showing:
012345678901234567890123456789012345678901
0 WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
1 WWWWWWW … WWWWWWWWWW
2 WWWWW … WWWWWWWW N
3 WWWW … WWWWWW NW | NE
4 WW … R … WWWW \ | /
5 W … WWW W -----|----- E
6 W … WW / | \
7 W … *..*...* … W SW | SE
8 W … W S
9 W … * … * … PH … W
0 W … * … W
1 W … * … * … W
2 WW … BBWW
3 WWW … BBWWW
4 WWWWW … BBBBBB...BBWWWW
5 WWWWWW … BBWWWWWBBBBWWWWW
6 WWWWWWW … BBBWWWWWWWWWWWWWWWW
7 WWWWWWWWWW … BBWWWWWWWWWWWWWWWWWW
8 WWWWWWWWWWW … X … BBWWWWWWWWWWWWWWWWWWW
9 WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
The treasure is 2 squares away from the rock in the North -
South direction
The treasure is 4 squares away from the rock in the East–– - West–
direction
17 1 boolean WestOfHut(String[][] Map, PirateRecord Pirate) { 12
return Map[Pirate.Row][Pirate.Column + 1].equals(HUT); // MP1 MP4 Task 1
}
void GetClue(String[][] Map, MapSizeRecord MapSize, String[][] HiddenMap,
PirateRecord Pirate) { // MP5 Task 2
int RockRow = 0, RockColumn = 0, TreasureRow = 0, TreasureColumn = 0;
for (int row = 0; row < MapSize.Rows; row++) {
for (int column = 0; column < MapSize.Columns; column++) { // MP2
if (Map[row][column].equals(ROCK)) { // MP6
RockRow = row;
RockColumn = column;
}
}
}
for (int row = 0; row < MapSize.Rows; row++) {
for (int column=0; column < MapSize.Columns; column++) {
if (HiddenMap[row][column].equals(TREASURE)) { // MP7
TreasureRow = row;
TreasureColumn = column;
}
18 }
}
int DistanceFromRock_NS = TreasureRow - RockRow; // MP3
if (DistanceFromRock_NS < 0) {
DistanceFromRock_NS *= -1;
}
int DistanceFromRock_WE = TreasureColumn - RockColumn; // MP6
if (DistanceFromRock_WE < 0) {
DistanceFromRock_WE *= -1; // MP10
}
Console.writeLine("The treasure is " + DistanceFromRock_NS + " squares
away from the rock in the North - South direction");
Console.writeLine("The treasure is " + DistanceFromRock_WE + " squares
away from the rock in the East - West direction"); // MP9
}
void PirateWalks(String[][] Map, MapSizeRecord MapSize, String[][]
HiddenMap, PirateRecord Pirate) {
boolean ObstacleInPath = true;
boolean ValidDistance = false;
boolean ValidDirection = false;
int Row = 0, Column = 0, NumberOfSquares = 0;
String Direction = "";
while (ObstacleInPath || !ValidDistance || !ValidDirection) {
Console.write("Enter length (1 to 9) and direction (N, NE, E, SE, S, SW,
W, NW): ");
String WalkData = Console.readLine();
Row = Pirate.Row;
Column = Pirate.Column;
MoveCheckRecord DistanceData =
CheckDistance(String.valueOf(WalkData.charAt(0)));
ValidDistance = DistanceData.valid;
NumberOfSquares = DistanceData.numberOfSquares;
Direction = WalkData.substring(1);
MoveCheckRecord DirectionData = CheckDirection(Direction, Row, Column,
NumberOfSquares);
ValidDirection = DirectionData.valid;– – –
Row = DirectionData.row;
Column = DirectionData.column;
if (Row >= MapSize.Rows || Column >= MapSize.Columns || Row < 0 ||
Column < 0) {
ValidDirection = false;
Console.writeLine("Error");
}
if (ValidDirection) {
ObstacleInPath = CheckPath(Map, Pirate.Row, Pirate.Column, Row,
Column, Direction);
if (ObstacleInPath) {
Console.writeLine("Pirate can't walk this way as there is an
obstacle in the way");
}
}
}
Move(Map, MapSize, Pirate, Row, Column);
if (WestOfHut(Map, Pirate)) { // MP11 Task 3
GetClue(Map, MapSize, HiddenMap, Pirate); // MP12
}
}
How to answer it
Question 17: Treasure Island Skeleton Program – Clue Mechanism
This question assesses practical programming skills (AO3 Design and Implementation) via the modification of the Skeleton Program:
- Writing custom subroutines that accept structured records and 2D arrays as parameters.
- Spatial grid navigation and coordinate checking relative to existing entities (relative positioning: one square West of Hut).
- 2D array linear search using nested loops to locate coordinates of target characters ( 'R' and 'T' ).
- Calculating positive distances across 2D axes (Manhattan component distance / absolute difference).
- Integration: invoking new subroutines conditionally from an existing procedure ( PirateWalks ).
- Testing and capturing correct program evaluation via exact terminal inputs.
Subroutine Implementation & Integration
Creating WestOfHut, GetClue, and modifying PirateWalks
💡 Key Knowledge & Parameter Passing
- Coordinate Relative Check: If the pirate is 1 square west of the hut, the hut must be immediately to the pirate's east:
Map[Pirate.Row][Pirate.Column + 1] == HUT . - 2D Array Linear Search: You must traverse rows (0 to MapSize.Rows - 1 ) and columns (0 to MapSize.Columns - 1 ) to locate:
- The Rock ( ROCK / 'R' ) in Map .
- The Treasure ( TREASURE / 'T' ) in HiddenMap .
- Ensuring Positive Distance: Distances cannot be negative. If diff < 0 , negate it ( diff *= -1 ) or use Math.Abs() .
🧠 Exam Technique & Mark Scheme Breakdown
- Design Marks (3 marks):
• Design a subroutine to test if pirate is west of hut.
• Use nested loops for 2D array search.
• Attempt distance calculation between rock & treasure. - Programming Marks (9 marks):
• Correct parameter passing and return types.
• Finding correct coordinates for both entities.
• Absolute distance calculation in both NS and EW axes.
• Correct output formatting directly within GetClue .
• Calling subroutines at the end of PirateWalks after moving. - Cap Rule: Maximum 11 marks if code does not function fully.
✅ Model Implementation (C# / Java style)
// Task 1: Check if Pirate is 1 square west of the hut boolean WestOfHut(String[][] Map, PirateRecord Pirate) { // If pirate is west of hut, hut is at pirate's column + 1 return Map[Pirate.Row][Pirate.Column + 1].equals(HUT); } // Task 2: Locate Rock & Treasure, calculate distances, and display clue void GetClue(String[][] Map, MapSizeRecord MapSize, String[][] HiddenMap, PirateRecord Pirate) { int RockRow = 0, RockColumn = 0; int TreasureRow = 0, TreasureColumn = 0; // Search for Rock on Map for (int row = 0; row < MapSize.Rows; row++) { for (int column = 0; column < MapSize.Columns; column++) { if (Map[row][column].equals(ROCK)) { RockRow = row; RockColumn = column; } } } // Search for Treasure on HiddenMap for (int row = 0; row < MapSize.Rows; row++) { for (int column = 0; column < MapSize.Columns; column++) { if (HiddenMap[row][column].equals(TREASURE)) { TreasureRow = row; TreasureColumn = column; } } } // Calculate North-South and East-West distances int DistanceFromRock_NS = Math.abs(TreasureRow - RockRow); int DistanceFromRock_WE = Math.abs(TreasureColumn - RockColumn); // Display messages Console.WriteLine("The treasure is " + DistanceFromRock_NS + " squares away from the rock in the North - South direction"); Console.WriteLine("The treasure is " + DistanceFromRock_WE + " squares away from the rock in the East - West direction"); } // Task 3: Amend PirateWalks subroutine (added at the end) // ... [existing PirateWalks code] ... Move(Map, MapSize, Pirate, Row, Column); // Newly added check: if (WestOfHut(Map, Pirate)) { GetClue(Map, MapSize, HiddenMap, Pirate); } ❌ Common Traps & Mistakes
- Checking the wrong array: Searching for TREASURE in Map rather than HiddenMap . The treasure is hidden!
- Off-by-one or direction confusion: Thinking "west of hut" means Pirate.Column - 1 . If the pirate is west of the hut, the hut is to the right ( +1 column) of the pirate.
- Missing Absolute Value: Forgetting that subtracting indices can yield negative numbers (e.g. 2 - 4 = -2 ). Distances must always be positive integers.
- Calling at the wrong point: Calling WestOfHut inside the loop or before Move(...) has executed.
📐 Coordinate Distance Logic (Figure 7 Example)
Given the coordinate grid in the specification:
- Rock ('R') Position: Row 3, Column 3
- Treasure ('T') Position: Row 2, Column 6
- North-South Distance: |Row_T - Row_R| = |2 - 3| = 1 square
- East-West Distance: |Col_T - Col_R| = |6 - 3| = 3 squares
Program Testing & Screen Capture Evaluation
Executing Task 4 with specified inputs
🧠 Test Execution Walkthrough
Run your amended program and enter the exact sequence of commands provided in the prompt:
- Start game (land where X is located).
- Enter W to walk.
- Enter 9NE (move 9 steps North-East).
- Enter W to walk again.
- Enter 6E (move 6 steps East).
✅ Expected Output Capture
The final screenshot must show the pirate standing directly next to the Hut ( PH ) and the resulting printed clue:
... 8 W . . . . . * . . . . . . . . . . . . . W 9 W . . . . . * . . . . . . . . . PH. . . . W 0 W . . . . . * * . . . . . . . . . . . . . W ... The treasure is 2 squares away from the rock in the North - South direction The treasure is 4 squares away from the rock in the East - West direction Topics
4.1 Fundamentals of programming · 4.2 Fundamentals of data structures · 4.13 Systematic approach to problem solving · 4.1.1 Programming · 4.2.1 Data structures and abstract data types · 4.13.1 Aspects of software development
Question and mark scheme from the AQA A-Level Computer Science examination, AS Paper 1, June 2025. QuestionVault is an independent revision resource; questions remain the copyright of the awarding body.