conways-game-of-life

another Game of Life question (infinite grid)?

倖福魔咒の 提交于 2019-12-20 11:49:23
问题 I have been playing around with Conway's Game of life and recently discovered some amazingly fast implementations such as Hashlife and Golly. (download Golly here - http://golly.sourceforge.net/) One thing that I cant get my head around is how do coders implement the infinite grid? We can't keep an infinite array of anything, if you run golly and get a few gliders to fly off past the edges, wait for a few mins and zoom right out, you will see the gliders still there out in space running away,

Optimizing Conway's 'Game of Life'

醉酒当歌 提交于 2019-12-17 08:16:33
问题 To experiment, I've (long ago) implemented Conway's Game of Life (and I'm aware of this related question!). My implementation worked by keeping 2 arrays of booleans, representing the 'last state', and the 'state being updated' (the 2 arrays being swapped at each iteration). While this is reasonably fast, I've often wondered about how to optimize this. One idea, for example, would be to precompute at iteration N the zones that could be modified at iteration (N+1) (so that if a cell does not

How to declare a two-dimensional array in Ruby

筅森魡賤 提交于 2019-12-14 00:22:33
问题 I want a twodimensional array in Ruby, that I can access for example like this: if @array[x][y] == "1" then @array[x][y] = "0" The problem is: I don't know the initial sizes of the array dimensions and i grow the array (with the << operator). How do I declare it as an instance variable, so I get no error like this? undefined method `[]' for nil:NilClass (NoMethodError) QUESTION UPDATED: @array = Array.new {Array.new} now works for me, so the comment from Matt below is correct! I just found

implement game of life with only 2 array

心已入冬 提交于 2019-12-13 09:48:07
问题 I want to memory-efficient this (the game of life code of shiffman in the nature of code book). how can change the below code to have only two arrays and constantly swap them, writing the next set of states into whichever one isn’t the current array? class GOL { int w = 8; int columns, rows; int[][] board; GOL() { // Initialize rows, columns and set-up arrays columns = width / w; rows = height / w; board = new int[columns][rows]; //next = new int[columns][rows]; // Call function to fill array

Java panel/frame graphic not working

末鹿安然 提交于 2019-12-13 05:13:37
问题 I am trying to make a game of life simulation using Java Graphics but when a run my code the left one third of the screen is grey.I want the whole screen to be white with black squares representing living squares. I am confused about all the java containers/panels and frames. Here's my code: public class ConwayGame { static JPanel panel; static JFrame frame; public static void main(String[] args) throws InterruptedException{ int [][] array = new int [40][40]; /* * Set the pattern for Conway's

Issue with Game of life code method? (User interface is complete but actual GOL methods aren't generating what they should)

六眼飞鱼酱① 提交于 2019-12-12 05:29:23
问题 I've been working on a Game of Life assignment and am nearing the stage of completion, but am struggling to figure out what I've messed up on such that the GOL rules (and Fredkin rules that the assignment requires us to implement as well) are not generating the proper result. As I have little experience working with graphics I decided to output everything in the interactions window (using Dr.Java). (It's used to set up menu options like the scale, coordinates (you manually enter), generations

Infinite Board: Conway's Game of Life - Python

ⅰ亾dé卋堺 提交于 2019-12-11 22:41:42
问题 I was assigned this project with instructions below: The game of Life is defined for an infinite-sized grid. In Chapter 2, we defined the Life Grid ADT to use a fixed-size grid in which the user specified the width and height of the grid. This was sufficient as an illustration of the use of a 2-D array for the implementation of the game of Life. But a full implementation should allow for an infinite-sized grid. Implement the Sparse Life Grid ADT using an approach similar to the one used to

Is there a way to get current column and row index pair of where rectangle is clicked on a uniform grid with for loop, etc.?

牧云@^-^@ 提交于 2019-12-11 15:15:17
问题 namespace ConwayGameofLife { public partial class GameController : Window { public int row; public int col; public SolidColorBrush brush; public Rectangle[,] rectangle; public GridCell cell; public string[,] cellPosition; public int cellColumn; public int cellRow; public GameController() { InitializeComponent(); brush = new SolidColorBrush(Colors.Gray); } private void GridSlider_Button(object sender, RoutedPropertyChangedEventArgs<double> e) { row = (int)gridSlider.Value; col = (int

Game of Life, method doesnt work

故事扮演 提交于 2019-12-11 09:57:07
问题 I'm not sure if I am turning mad but this is what my problem is: I programm Game of Life and have a "countalive" method which counts how many surrounding fields are alive. public int countalive(Board board, int yaxis, int xaxis) { //defekt int living = board.getfields()[yaxis - 1][xaxis - 1] + board.getfields()[yaxis - 1][xaxis] + board.getfields()[yaxis - 1][xaxis + 1] + board.getfields()[yaxis][xaxis - 1] + board.getfields()[yaxis][xaxis + 1] + board.getfields()[yaxis + 1][xaxis - 1] +

Why are the generations in my Game of Life (using Processing) out of order?

雨燕双飞 提交于 2019-12-11 06:47:01
问题 import processing.core.PApplet; import static java.lang.System.out; public class GoL2 extends PApplet { int rectSideLength = 25; // rectSideLength = length of each side of the rectangles drawn that represent cells int generation = 0; int windowWidth = 1920; int windowHeight = 950; int[][] currentGeneration = new int[windowWidth][windowHeight]; // currentGeneration = 2D array to gold cell values of current generation int[][] nextGeneration = new int[windowWidth][windowHeight]; //