int left, right, top, bottom = 0; is initializing only the last variable. Better: int left = 0 , right = 0, top = 0, bottom = 0; or int left, right, top, bottom; left = right = top = bottom = 0; Same flavour: char* a, b, c, d;...

c,multidimensional-array,conways-game-of-life

I think you have two problems with your code: As @ogga said in comments you are not checking for upper bounds in getlivecellcounts. You checked for lower bounds in when you check i and j are more than 0 but you need to do this for upper bound too (just...

java,algorithm,loops,if-statement,conways-game-of-life

Where you do: if (grid[row][col] == true) { if (neighbors == 2 || neighbors == 3 ) { grid2[row][col] = true; } else { grid2[row][col] = false; } if (grid[row][col] == false) { if (neighbors > 2) { grid2[row][col] = false; } if (neighbors == 3) { grid2[row][col] = true;...

Here's one obvious way of doing this. You simply create a new instance of Cell and store its state (as :dead or :alive). dead? and alive? methods then simply check the state. class Cell ALIVE = :alive DEAD = :dead def self.new_dead_cell new(DEAD) end def self.new_live_cell new(ALIVE) end def initialize...

I suppose optimizing Conway's Game of Life is a science in and of itself, and I am sure this is covered pretty well in the link provided by NPE, but if I may suggest something, SetPixel is an awful waste of time. So, two optimizations: Only do SetPixel for those...

java,conways-game-of-life,agent-based-modeling,mason-abm

Note: this is a tentative answer as I have no way of verifying it at the moment. First, let's look at the documentation of ValueGridPortrayal2D. It says: Like other FieldPortrayal2Ds, this class uses an underlying SimplePortrayal2D to draw each separate element in the grid. A default SimplePortrayal2D is provided which...

ruby,arrays,parsing,conways-game-of-life

If you want to connect the edges to each other (which by the way creates a "torus" shape, or if you prefer is the "asteroids" world model where you can never leave the screen) then the simplest adjustment is to work in modular arithmetic: Change: if @start_grid[(row+r)][(col+c)] == 1 To:...

javascript,canvas,conways-game-of-life

Yes, cells in Game of Life may only be 'alive' or 'dead'. If they have never been alive, they are dead.

For the logic that loops through the board and checks adjacent cells, it is turning cells on/off while continuing to check others. It is likely you are reading adjacent cells as live or dead not because they were in the previous time step (which matters), but because you've changed their...

python,python-2.7,conways-game-of-life

A sequence with a length of n has a maximum element index of n - 1. Nonetheless you're trying to access element n - 1 + 1, which doesn't exist.

arrays,bash,conways-game-of-life

There's an easy way to encode a 2-dimensional array of size M×N into a 1-dimensional array of size M*N, for example: A[p,q] ↔ B[p+q*M] For our task: we'll fix M and N from the beginning, set all the array terms to . and then read the file to set the...

python,pygame,conways-game-of-life

I suspect this is the problem: cells[x][y] = update(cells,x,y) You've only got one grid, which you're updating while you're still computing from it. Generation n+1 should only take account of information from generation n - whereas currently you've got a mixture of information from n and n+1. You'll end up...

Well, you can use loops and just explicitly exclude the location itself (i.e. when the x and y offset are both 0): private int getNeighbours(LifeBoard board, int row, int col) { int neighbours = 0; for (int xOffset = -1; xOffset < 2; xOffset++) { for (int yOffset = -1;...

python,conways-game-of-life,indexoutofrangeexception

I would write a helper function that you could call that would either return a value or zero (pseudocode): def getValue(x, y) if x < 0 or y < 0 or x > xbound or y > ybound: return 0 return a[x][y] Then you can call getValue a bunch of...

algorithm,conways-game-of-life

The two player version of Conway’s Game of Life is extremely interesting, and so far I have developed and submitted one solid algorithm to HackerRank (attaining me a score of 41.656). The program I wrote attempts to set up diagonals across the board to act as obstacles and prevent opponents...

javascript,multidimensional-array,conways-game-of-life

Your wrap function is incomplete. It handles the case when x is less than 0, but when x is not less than 0, it always returns min. At that point, there are two cases: x is less than or equal to max, or x is greater than max, and you'd...

Here's a solution that works - using an enum for each cell and getting the i/j and x/y stuff right (I think). It certainly generates the correct first iteration: static class GameOfLife { final int w; final int h; State[][] frame; enum State { Dead, Alive; } public GameOfLife(int w,...

arrays,bash,conways-game-of-life

ok. Here we go. Because i found this question interesting to be implemented in bash i just wrote an implementation of conway's game of life. The main part to answer your question is probably: how to access neighbours for a position in a matrix if it is linearized?. So you...