Photo AI

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

Question icon

Question 6

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

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 ident... show full transcript

Worked Solution & Example Answer: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

Answer

The returned value is "FREE" because there is no block placed by players A or B at that position.

Step 2

checkblock(3,0)

99%

104 rated

Answer

The returned value is "B" since player B has placed a block at that coordinate.

Step 3

checkblock(2,3)

96%

101 rated

Answer

The returned value is "FREE" as this position has not been filled by either player.

Step 4

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

98%

120 rated

Answer

One feature that indicates checkblock() is a function is that it returns a value to the caller. Procedures typically do not return values.

Step 5

State why this function call will produce an error.

97%

117 rated

Answer

The function call checkblock(-1, 6) will produce an error because the parameters -1 and 6 are outside the valid index range of the gamegrid array.

Step 6

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

97%

121 rated

Answer

Validation can be added by checking if r (row) and c (column) are within the bounds of the array. For example:

if r < 0 or r >= 5 or c < 0 or c >= 5 then
   return "INVALID"
endif

This checks if the coordinates are valid before accessing the array.

Step 7

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

96%

114 rated

Answer

  1. Prompt the player for the position (r, c) of their block on the board.
  2. Call checkblock(r, c) to check if the position is free.
  3. If the return value is "FREE":
    • Update gamegrid[r][c] to "A".
  4. If the return value is not "FREE":
    • Display a message indicating the position is taken.
    • Repeat steps 1-4 until a free position is chosen.

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

;