| MOSKing (13) | |||
I have an 2D array that contains set values. I want to create two functions to randomize the values and avoid overlapping them. How would I go about it?
Please help and thank you. | |||
|
|
|||
| drognisep (31) | |
| Are you reassigning the values, or simply moving them around? | |
|
|
|
| MOSKing (13) | |
| Just moving them around. | |
|
|
|
| drognisep (31) | |||||
If you're just moving them around, you could just as easily create a buffer array that matches the dimensions of Gird (Grid?).
If you want to randomly move things, then you would have to limit your random numbers to the amount of directions your elements can move
I'll leave the code for actually moving them to you, but you have the tools to start! :) | |||||
|
|
|||||
| MOSKing (13) | |
| Thank You very much. I'm trying to program the game Wumpus World. 2D Array and Functions, lots of fun. :( | |
|
|
|
| drognisep (31) | |
| Lol, well if you need more help let me know. | |
|
|
|
| Cubbi (1568) | |||
|
C++ has the handy functions random_shuffle() and shuffle(), which can help you randomize that array: Also, note that -1 is not a particularly good value to assign a char, here's an example using '\0' instead:
online demo: http://ideone.com/T4vV8Y | |||
|
Last edited on
|
|||