Is there any particular way to use a something like a getline function to for each of on a 2D array?
For an example:
--o--
-o---
---o-
o----
Basically I want to be able to read in a line and search if it has any "o" in it.
integralfx this getline example is for userinput. Mine isn't userinput.
Okay so I figured it out :D
I have another question if you're up for a challenge lol.
RULE 1: Any 'o' with fewer than 2 'o' next to it turns into '-'.
How do I implement this RULE1 for every 'o' in my 2D array.
This is kind of what I have so far
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
for (int i = 0; i < MAX_BOARD; i++)
{
for (int j = 0; j < MAX_BOARD; j++)
{
if(currentLife[i][j].getState == true)
{
if (currentLife[i][j].getState == true && )
{
}
}
}
}
| |
BTW:
"Next to 'o' " can mean right next to it on its sides, on the top and bottom of it and diagonally adjacent to it.
true == 'o'
false == '-'
This is where i'm stuck at haha
Last edited on
you have to test to see if you are on an edge OR you can cheat and allocate the matrix to have padding on the sides.
If you allocate padding (unused space) on the sides and set those to an invalid value, you can just look at
array[r][c] //center, is it the value?
array[r-1][c] //left
array[r+1][c] //right
array[r][c-1] //below
array[r][c+1] //above
and if you need the diagonals...
array[r-1][c-1]
... etc