6. OCRBlocks is a game played on a 5 x 5 grid - OCR - GCSE Computer Science - Question 6 - 2021 - Paper 1
Question 6
6. OCRBlocks is a game played on a 5 x 5 grid. Players take it in turns to place blocks on the board. The board is stored as a two-dimensional (2D) array with the id... show full transcript
Worked Solution & Example Answer:6. OCRBlocks is a game played on a 5 x 5 grid - OCR - GCSE Computer Science - Question 6 - 2021 - Paper 1
Step 1
checkblock(2,1)
96%
114 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The returned value will be "FREE" because the square at (2,1) is empty.
Step 2
checkblock(3,0)
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The returned value will be "B" because there is a block from player B in that position.
Step 3
checkblock(2,3)
96%
101 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The returned value will be "FREE" because the square at (2,3) is empty.
Step 4
One feature of checkblock() that shows that it is a function and not a procedure.
98%
120 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The function checkblock() has a return statement, which allows it to provide a value back to the caller, indicating it is a function.
Step 5
State why this function call will produce an error.
97%
117 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The function call checkblock(-1,6) will produce an error because the indices are out of the bounds of the gamegrid, which validly ranges from 0 to 4.
Step 6
Describe how validation could be added in to the checkblock() function to stop this error from occurring.
97%
121 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Validation could check the values of r and c before accessing gamegrid. For example, the function can include an if condition that verifies if r and c are within the range 0 to 4. If not, it could return an "INVALID" message or similar.
Step 7
Write an algorithm to allow player A to select a position for their next block on the game board.
96%
114 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Ask the player for the position of their block on the board (row and column).
Use the checkblock() function to check if this position is free.
If the position is free, update gamegrid with "A" at the chosen position.
If the position is not free, repeat steps 1 to 3 until a free position is chosen.