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.
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 would create an array (2 dimensional) to represent the state of the population, internally, and then figuring out the neighbors is quite easy. Then you need a routine that scans the arry, and sets the corresponding textboxes on the UI, based on the contents of the array.
Dim arrLife(4,4) as Integer ' 5 elements by 5 elements
then T11 represents to contents of arrLife(2,1)
then you can figure out the realtionship between the Textbox number N and the row and column in the array:
for TN, the Row (0...4) = Int(N/5) and the Column = N mod 5
so for T18, Row = 3, and Column = 3
and sure enough (remembering that the rows and columns in the array are numbered 0..4), T18 is arrLife(3,3))
why only a B? If you needed a more complete explanation, then all you need do is to ask.
AW
0
Featured Post
With monday.comâ€™s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.