# Minesweeper coding help

**URL:** <https://discourse.processing.org/t/minesweeper-coding-help/19027>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [March 26, 2020, 8:07am UTC](https://discourse.processing.org/t/minesweeper-coding-help/19027 "2020-03-26T08:07:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![quadri](https://avatars.discourse-cdn.com/v4/letter/q/b77776/32.png) [@quadri](https://discourse.processing.org/u/quadri)\
**Post date:** [March 26, 2020, 8:07am UTC](https://discourse.processing.org/t/minesweeper-coding-help/19027/1 "2020-03-26T08:07:26Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 26, 2020, 10:01am UTC](https://discourse.processing.org/t/minesweeper-coding-help/19027/2 "2020-03-26T10:01:16Z")

</div>

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

Unfortunately we are not allowed to provide full code solutions to [homework](https://discourse.processing.org/faq#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/](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](https://github.com/Kango/Processing-snippets/wiki/programming-and-functions)
