我正在写一个基于John Conway的生命游戏的程序.我得到它编译,甚至在经过几天不间断的工作后运行.但是,打印出来的结果是错误的......
这是我的代码(不包括主要方法)
//clears the grid
public static void clearGrid ( boolean[][] grid )
{
for(int row = 0; row < 18; row++){
for(int col = 0; col < 18; col++){
grid[row][col]= false;
}
}
//set all index in array to false
}
//generate the next generation
public static void genNextGrid ( boolean[][] grid )
{
int n; //number of neighbors
boolean[][] TempGrid = grid;// a temporary array
for(int row = 0; row < 18; row++)
{
for(int col = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用pygame在conthon中制作conway的生活游戏.我无法弄清楚为什么,但它产生的模式是关闭的.我已经查看了一百万次代码,我看不出什么是错的.
这是一代人的截图

这是游戏的完整代码.
import pygame, sys
from pygame.locals import *
from random import randint
import numpy
#inititalize
pygame.init()
clock = pygame.time.Clock()
#constants
FPS = 10
BLACK = (0,0,0)
RED = (255,0,0)
GREY = (30,30,30)
SCREENX = 640
SCREENY = 480
CELLSIZE = 10
HEIGHT = SCREENY/CELLSIZE
WIDTH = SCREENX/CELLSIZE
#set up window
window = pygame.display.set_mode((SCREENX, SCREENY))
pygame.display.set_caption('Game of Life')
window.fill(BLACK)
#generate random seed
cells = numpy.zeros((WIDTH,HEIGHT), dtype=numpy.int)
for x in range(0,WIDTH):
for y in range(0,HEIGHT):
#0 is a dead cell, …Run Code Online (Sandbox Code Playgroud) 我正在实施John Conway生命游戏,但我遇到了一个奇怪的问题.如果代码给我带来麻烦,这是一个简短的版本:
let lifeMap = [
[true, false, false],
[false, false, false],
[false, false, false]
];
let oldLifeMap = lifeMap.slice();
for (let row = 0; row < lifeMap.length; row++) {
for (let val = 0; val < lifeMap[row].length; val++) {
let bool = lifeMap[row][val];
let newBool = false; // here is where I would determine if cell is alive/dead
lifeMap[row][val] = newBool;
if (row === 0 && val === 0) console.log("at (0,0)", oldLifeMap[0][0]);
}
}
Run Code Online (Sandbox Code Playgroud)
为了响应此代码,JavaScript打印at (0,0) false.我需要它一直 …
javascript arrays copy multidimensional-array conways-game-of-life
我正在尝试创建一个生命游戏模拟器.我之前使用StrGrid工作但是速度较慢而且我被告知要使用DrawGrid.
我的程序通过两个数组工作,strArray包含下一代单元格的所有值,而currentArray包含当前一代单元格的所有值(两者都是数组[1 ... 127]的类型数组[1 ... 127].字符串;,我知道使用布尔数组会更好,但这是一个较旧的程序).在计时器上,算法计算每个单元周围的活细胞数,并在strArray,T(指定活细胞)或F(指定死细胞)中给出一个值.然后将该模式写入currentArray,以便在下次需要计算活细胞时使用.然后,如果相关单元格与currentArray中的"F"匹配,我想将每个单元格的颜色更改为白色,如果匹配"T",则将其更改为黑色.我还希望能够为单击黑色的单元格着色,并将数据表中的值更改为"T".
但是,我对drawgrids不熟悉,似乎无法找到任何对我有意义的相关信息.当我使用字符串网格时,您可以使用stringgrid.cells [stringgrid.col,stringgrid.row]访问每个单元格的内容:='whatever'; 但是我找不到类似DrawGrid的方法.
总结一下,我需要帮助:
我希望你能帮助我.谢谢!
我是C/C++编程语言的新手.我想进行简单的康威生命游戏使用C programming language.
我的代码看起来像这样:
#include "stdafx.h"
// Define some constants
const int DIM = 10;
int board[DIM][DIM];
int checkNeighbours(int x, int y) {
int left, right, top, bottom = 0;
int sum;
// Check neighbour cells
if (board[x - 1][y]) { left = 1; }
if (board[x + 1][y]) { right = 1; }
if (board[x][y - 1]) { top = 1; }
if (board[x][y + 1]) { bottom = 1; }
sum …Run Code Online (Sandbox Code Playgroud) 我在javascript中写了一篇"生命游戏" .我在一个名为的函数中完成了所有逻辑doGeneration().我可以从控制台反复调用它,一切都按计划进行,但是,如果我把它放在while循环中,执行会阻止UI,我只看到最终结果(最终).
while (existence) {
doGeneration();
}
Run Code Online (Sandbox Code Playgroud)
如果我添加一个setTimeout(),即使是15的生成限制,浏览器实际上也会崩溃(Canary,Chrome).
while (existence) {
setTimeout(function() {
doGeneration();
},100);
}
Run Code Online (Sandbox Code Playgroud)
如何在doGeneration()不阻止DOM/UI的情况下每隔一秒左右调用一次?
谁能告诉我康威生命游戏中的空间填充模式的种子是什么?我计划在我的游戏中为用户添加一些有趣的模式。
非常感谢,
我以为我会在康威的生命游戏中崭露头角,但我正在努力奋斗......这真是一个惊喜!有人可能暗示算法问题吗?只是一点点轻推?这不是功课.
#include <stdio.h>
#include <stdlib.h>
#define HEIGHT 10
#define WIDTH 10
int *gb[HEIGHT];
int *gb2[HEIGHT];
void copy() {
int i, j;
for (i = j = 0; i < HEIGHT; i++) {
for (; j < WIDTH; j++) {
gb2[i][j] = gb[i][j];
}
}
}
void init() {
int i, j;
for (i = 0; i < HEIGHT; i++) {
gb [i] = malloc(sizeof(int)*WIDTH);
gb2[i] = malloc(sizeof(int)*WIDTH);
}
for (i = j = 0; i < HEIGHT; i++) {
for …Run Code Online (Sandbox Code Playgroud)