nothing8171
asked on
VB - Conway's Game of Life - logic for counting neighbors
Hello,
I don't have the code with me, but I am trying to figure out the code or pseudocode for determing how many neighbors I have in John Conway's - The Game of Life.
I have a grid that is 5 x 5, and an initialize button which places an "X" in random text boxes when clicked. The boxes are in text boxes within a control array. How the heck do I figure out how many neighbors each Text box has? This is driving me crazy?
......and yes, this is a homework assignment, but I am not asking for the program, just some help with the logic for counting the neightbors.
T0 T1 T2 T3 T4
T5 T6 T7 T8 T9
T10 T11 T12 T13 T14
T15 T16 T17 T18 T19
T20 T21 T22 T23 T24
You see, if I'm trying to get the neighbors for T11, it has no idea which Textbox number is around him.....it could be anything. This is where I'm confused.
I don't have the code with me, but I am trying to figure out the code or pseudocode for determing how many neighbors I have in John Conway's - The Game of Life.
I have a grid that is 5 x 5, and an initialize button which places an "X" in random text boxes when clicked. The boxes are in text boxes within a control array. How the heck do I figure out how many neighbors each Text box has? This is driving me crazy?
......and yes, this is a homework assignment, but I am not asking for the program, just some help with the logic for counting the neightbors.
T0 T1 T2 T3 T4
T5 T6 T7 T8 T9
T10 T11 T12 T13 T14
T15 T16 T17 T18 T19
T20 T21 T22 T23 T24
You see, if I'm trying to get the neighbors for T11, it has no idea which Textbox number is around him.....it could be anything. This is where I'm confused.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
similarly, from the array to the textboxes, is equally simple, as arrLife(R,c) ==> T(R*5 + C)
that is multiply the row index (0..4) by 5, and add the column indec (also 0..4) to get the N, for TN
thus, arrLife(3,3) --> T(3*5 +3) = T18
AW
that is multiply the row index (0..4) by 5, and add the column indec (also 0..4) to get the N, for TN
thus, arrLife(3,3) --> T(3*5 +3) = T18
AW
why only a B? If you needed a more complete explanation, then all you need do is to ask.
AW
AW
ASKER