Minesweeper coding help

Write a function called check_surrounds with 4 inputs:
 dim (a positive integer)
 grid (a 2D numerical array containing only 1s and 0s of size dimxdim).
 i (a positive integer between 1 and dim)
 j (a positive integer between 1 and dim)

The variable dim is used to represent the number of rows/columns in a square grid in the game
minesweeper. The variable grid has a 1 in positions containing a mine and a 0 everywhere else. The
variables i and j represent the row and column respectively that the function is assessing. The function
should have one output called number. The output number should be an integer representing the
number of mines that exist in all elements adjacent to (i,j) including diagonally adjacent.

I don’t know how to write this code

can anyone help to do this?

Hello and welcome to the forum! Great to have you here!

Unfortunately we are not allowed to provide full code solutions to homework.

Instead we try to lead you through. (That’s actually more time consuming for us but should help you learn.)

Please look at the basic textual tutorials and at the tutorial for arrays.

see https://www.processing.org/tutorials/

Do you know about setup() and draw()? Do you know how to write a function?

Then please show your attempt and we work from there.

Thank you.

Warmest regards,

Chrisir

P.S.
Here is an explanation of functions: https://github.com/Kango/Processing-snippets/wiki/programming-and-functions

4 Likes