conways-game-of-life

Conway's Game of Life not counting neighbors correctly

人走茶凉 提交于 2019-12-11 04:18:23
问题 I am doing the standard Conway's Game of Life program using Python. I am having an issue when trying to count neighbors as I iterate through the array. I created print statements that print the succession of the if statement, as well as the value of count for each statement. Here is my code: ( I have the questions inside the # throughout the code) import random numrows = 10 numcols = 10 def rnd(): rn = random.randint(0,1) return rn def initial(): grid = [] count = 0 for x in range(numrows):

How do I add a feature where I can get the generation in my game of life program?

和自甴很熟 提交于 2019-12-10 11:27:56
问题 I'm trying to make my program display (testing in console first) the count number at each step where the cell changes its form. So the count should start from 0 and increment each time the cell changes its form. I tried this, using count++ however it doesn't increment by 1 but instead gives me random numbers. Any help will be much appreciated. import java.awt.Color; import java.util.Timer; import java.util.TimerTask; import java.awt.Image; import java.awt.Graphics; import javax.swing

Please help with my basic java implementation of Conway's game of life

瘦欲@ 提交于 2019-12-08 02:45:10
问题 I have spent quite a while trying to write a program to implement Conway's game of life - Link with more info. . I am following some online guides and was given the majority of the functions. I wrote the "next" and "neighbours" methods shown below. Could anyone tell me if these are good implementations, and how they could be made better please ? The point of the exercise was to not modify or change any of the other methods and just write the next method ! :) import java.io.*; import java.util

Toad pattern in game of life

孤者浪人 提交于 2019-12-07 23:27:42
问题 I was trying to solve the Game of life problem for a test. Rules of that game are: Any live cell with fewer than two live neighbors dies, as if caused by under-population. Any live cell with two or three live neighbors’ lives on to the next generation. Any live cell with more than three live neighbors dies, as if by overcrowding. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction. I tested my work on various patterns like Block, Boat, Blinker and Toad

Please help with my basic java implementation of Conway's game of life

泪湿孤枕 提交于 2019-12-06 09:20:23
I have spent quite a while trying to write a program to implement Conway's game of life - Link with more info. . I am following some online guides and was given the majority of the functions. I wrote the "next" and "neighbours" methods shown below. Could anyone tell me if these are good implementations, and how they could be made better please ? The point of the exercise was to not modify or change any of the other methods and just write the next method ! :) import java.io.*; import java.util.Random; public class Life { private boolean[][] cells; public static void main( String[] args ) { Life

Toad pattern in game of life

情到浓时终转凉″ 提交于 2019-12-06 08:37:48
I was trying to solve the Game of life problem for a test. Rules of that game are: Any live cell with fewer than two live neighbors dies, as if caused by under-population. Any live cell with two or three live neighbors’ lives on to the next generation. Any live cell with more than three live neighbors dies, as if by overcrowding. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction. I tested my work on various patterns like Block, Boat, Blinker and Toad pattern shown below. But my code is not giving expected output for toad pattern as shown...although its

Brushes.White slows graphics demo down

て烟熏妆下的殇ゞ 提交于 2019-12-05 03:27:19
Below is a (very naive) implementation of Conway's Game of Life in WPF. It's just a demo... xaml: <Window x:Class="wpf_conway_life_2013_05_19.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="500" Width="500"> <Grid> <Canvas Name="canvas" Width="auto" Height="auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> </Canvas> </Grid> </Window> code behind: using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes;

How to declare a two-dimensional array in Ruby

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 04:13:50
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 out the reason why I received the error was because I iterated over the array like this: for i in 0..

Conway's Game of Life with Python

旧巷老猫 提交于 2019-12-03 14:52:44
问题 I took a liking to Conway's Game of Life and began to try and write it in python. At this moment I have yet to write any code for the borders of the program so I am just asking for help with what I have right now. I seem to have trouble when initialization a "blinker" formation. Instead of oscillating like it should, it seems to turn itself into a cube. #File: gameoflife.py #Description: This is a basic "life" simulation that follows three distinct rules: #1.Any live cell with fewer than two

What's an efficient implementation of Conway's Game of Life for low memory uses?

我是研究僧i 提交于 2019-12-03 06:02:30
问题 I'm looking for a fast and memory efficient approach for implementing Conway's Game of Life. Constraints: a 96x128 board, approximately 2kB RAM available and 52MHz processor (see the tech specs here: http://www.getinpulse.com/features). My current naive solution that represents each cell as a single bit in a matrix (96*128/8=1,536 bytes) works but is too slow. What tricks can be used to improve performance? Storing the coordinates of live cells (for example in this implementation http://dotat