Photo AI

6. OCRBlocks is a game played on a 5 x 5 grid - OCR - GCSE Computer Science - Question 6 - 2021 - Paper 1

Question icon

Question 6

6.-OCRBlocks-is-a-game-played-on-a-5-x-5-grid-OCR-GCSE Computer Science-Question 6-2021-Paper 1.png

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

Give the returned value when the following statements are called.

96%

114 rated

Answer

Function callReturned value
checkblock(2,1)FREE
checkblock(3,0)FREE
checkblock(2,3)FREE

Step 2

State one feature of checkblock() that shows that it is a function and not a procedure.

99%

104 rated

Answer

The checkblock() returns a value (the outcome) which indicates that it is a function. Procedures typically do not return values.

Step 3

State why this function call will produce an error.

96%

101 rated

Answer

The function call checkblock(-1,6) produces an error because the indices are out of the valid range for the 5 x 5 grid, which only allows values between 0 and 4.

Step 4

Describe how validation could be added in to the checkblock() function to stop this error from occurring.

98%

120 rated

Answer

Validation can be added by checking the values of r and c before accessing gamegrid. For instance:

if r < 0 or r >= 5 or c < 0 or c >= 5 then
    return "ERROR: Invalid position"
endif

This ensures that only valid indices are used.

Step 5

Write an algorithm to allow player A to select a position for their next block on the game board.

97%

117 rated

Answer

Algorithm allowPlayerAToSelectPosition
    repeat
        ask player for position (r, c) of their block on the board
        if checkblock(r, c) == "FREE" then
            gamegrid[r,c] = "A"
        else
            print "Position is not free. Please choose another position."
        endif
    until checkblock(r, c) == "FREE"
endAlgorithm

Join the GCSE students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

Other GCSE Computer Science topics to explore

;