reload
yazman yeterlibind x rcon reload
yazarsan daha kolay olur ben oyle kullaniyorum#include <stdio.h>
#include <stdlib.h>
#define WIDTH 30
#define HEIGHT 30
typedef int Grid[WIDTH][HEIGHT];
void print(Grid grid) {
for (int y=HEIGHT-1;y>=0;y--) {
for (int x=0;x<WIDTH;x++) {
if (grid[x][y]) {
printf(" #");
continue;
}
printf(" _");
}
printf("\n");
}
}
void update(Grid* grid) {
Grid copy;
memcpy(©, grid, sizeof(*grid));
for (int y=1;y<HEIGHT-1;y++) {
for (int x=1;x<WIDTH-1;x++) {
int count = 0;
count += copy[x-1][y+1];
count += copy[x][y+1];
count += copy[x+1][y+1];
count += copy[x-1][y-1];
count += copy[x][y-1];
count += copy[x+1][y-1];
count += copy[x-1][y];
count += copy[x+1][y];
if ((*grid)[x][y] == 1 && (count == 2 || count == 3)) {
continue;
}
if ((*grid)[x][y] == 0 && (count == 3)) {
(*grid)[x][y] = 1;
continue;
}
(*grid)[x][y] = 0;
}
}
}
void randomize(Grid* grid) {
for (int y=1;y<HEIGHT-1;y++) {
for (int x=1;x<WIDTH-1;x++) {
(*grid)[x][y] = rand() % 2;
}
}
}
int main(){
Grid grid = {0};
// glider
grid[3][1] = 1;
grid[3][2] = 1;
grid[3][3] = 1;
grid[2][3] = 1;
grid[1][2] = 1;
srand(14);
randomize(&grid);
for (int i=0;i<20;i++) {
print(grid);
printf("\n\n");
update(&grid);
}
return 0;
}
What do you guys think about my C program?#include <stdio.h>
#include <stdlib.h>
#define WIDTH 30
#define HEIGHT 30
typedef int Grid[WIDTH][HEIGHT];
void print(Grid grid) {
for (int y=HEIGHT-1;y>=0;y--) {
for (int x=0;x<WIDTH;x++) {
if (grid[x][y]) {
printf(" #");
continue;
}
printf(" _");
}
printf("\n");
}
}
void update(Grid* grid) {
Grid copy;
memcpy(©, grid, sizeof(*grid));
for (int y=1;y<HEIGHT-1;y++) {
for (int x=1;x<WIDTH-1;x++) {
int count = 0;
count += copy[x-1][y+1];
count += copy[x][y+1];
count += copy[x+1][y+1];
count += copy[x-1][y-1];
count += copy[x][y-1];
count += copy[x+1][y-1];
count += copy[x-1][y];
count += copy[x+1][y];
if ((*grid)[x][y] == 1 && (count == 2 || count == 3)) {
continue;
}
if ((*grid)[x][y] == 0 && (count == 3)) {
(*grid)[x][y] = 1;
continue;
}
(*grid)[x][y] = 0;
}
}
}
void randomize(Grid* grid) {
for (int y=1;y<HEIGHT-1;y++) {
for (int x=1;x<WIDTH-1;x++) {
(*grid)[x][y] = rand() % 2;
}
}
}
int main(){
Grid grid = {0};
// glider
grid[3][1] = 1;
grid[3][2] = 1;
grid[3][3] = 1;
grid[2][3] = 1;
grid[1][2] = 1;
srand(14);
randomize(&grid);
for (int i=0;i<20;i++) {
print(grid);
printf("\n\n");
update(&grid);
}
return 0;
}
What do you guys think about my C program?