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

checkblock(2,1)

96%

114 rated

Answer

The returned value will be "FREE" because the square at (2,1) is empty.

Step 2

checkblock(3,0)

99%

104 rated

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

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

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

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

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

Answer

  1. Ask the player for the position of their block on the board (row and column).
  2. Use the checkblock() function to check if this position is free.
  3. If the position is free, update gamegrid with "A" at the chosen position.
  4. If the position is not free, repeat steps 1 to 3 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

;