Hi, I am wondering if anybody has any suggestions in to how to create a numerical matrix of a given length and height and with the values within containing only certain numbers and can be adjusted for gradients and attractors. I have attached an image of the classic game minesweeper in here as it looks a lot like I want my end goal to be. The other picture that I have included shows two manually created and very rudimentary matrix within a multi-line panel, which is a basic version of my end goal. This image also shows my attempt at a starting point in Grasshopper, which I am not even sure if I am on the right path or not with.
Creating a Minesweeper-like matrix would require attractors, although I’m not sure how to do this with numbers only.
I’m sure there are a wide variety of approaches, so I am hoping for suggestions into a range of options on how to achieve this.
I suppose the easiest way I can see be of doing this would be to:
Create a Square Grid
Select some random cells to be the “mines”
Then for each cell check up to 8 cells around it so if I am looking at {0;1}(i) - I need to access the items in the relevant rows and columns - each time I find a mine I increase the number associated with that cell by 1.
Here’s a rather simple approach that uses a Python script to generate the numerical grid and allows you to turn certain cells - selected by their indices - into mines (or attractors) that then increment their neighbouring cell values by 1.
Mines have a default value of -1 and other cells are initialized as 0s.
Since, the placement of the mines can be randomized, it’s rather easy to do lots of iterations quickly.
As mentioned before, the grid only consists of integer numbers, which can be remapped and used as data to manipulate really any grid or geometry that is composed of the same number of elements as there are cells in the grid.
Hey, thanks for the reply!! It was definitely an open ended question. Although DiffArch kindly provided me with a script below, I am wondering what component you would use to check the cells around (i) - I am thinking some sort of dispatch to which doesn’t check cells within a certain range? I will play around with this during the weekend. Again, much appreciated
Hi, thanks for the script. Very kind of you - I am trying to deconstruct it now so I really know what is going on. Although it may be simple for you, it is a great learning tool for me :)… I am trying to relate this to object oriented programming which is why I am trying to extract the actual numerical values of the grid into an array of numbers. I will attempt to go into the Python script to see if I can manipulate it at all to get all values of the grid to be one or over (so x would be 1 ---- 0 would be 2 ---- 1 would be 3 etc…). I will also see if I can cluster the mines together in certain areas to create a gradient. I’ll let you know of my success (or lack of). Thanks again
Inside the Grid class, the values of the two-dimensional grid are stored in a one-dimensional list.
The Python component outputs a tree with each row of values in a branch.
Mines were previously -1 and just printed as Xs and are now 1 and all other values get initialized as 2s.
This should be feasible by entering the right indices of cells. Remember, they are stored in a one-dimensional array so indices range from 0 to rows x columns - 1!