Added gitignore, fixed print routine
Had mixed up Y with X in some for loops, this caused the printing to be messed up on anything but square grids. Now grid generation and printing is complete, have to start implementing the actual life algorithm next. Also added .gitignore with cmake and c defaults
This commit is contained in:
parent
9c67c06b7d
commit
63e79c2527
3 changed files with 122 additions and 29 deletions
85
.gitignore
vendored
Normal file
85
.gitignore
vendored
Normal file
|
@ -0,0 +1,85 @@
|
|||
# manual entries up here
|
||||
.gdb_history
|
||||
conway
|
||||
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/cmake
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=cmake
|
||||
|
||||
### CMake ###
|
||||
CMakeLists.txt.user
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
CMakeScripts
|
||||
Testing
|
||||
Makefile
|
||||
cmake_install.cmake
|
||||
install_manifest.txt
|
||||
compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
|
||||
### CMake Patch ###
|
||||
# External projects
|
||||
*-prefix/
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/cmake
|
||||
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/c
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=c
|
||||
|
||||
### C ###
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Linker output
|
||||
*.ilk
|
||||
*.map
|
||||
*.exp
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
*.la
|
||||
*.lo
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
|
||||
# Debug files
|
||||
*.dSYM/
|
||||
*.su
|
||||
*.idb
|
||||
*.pdb
|
||||
|
||||
# Kernel Module Compile Results
|
||||
*.mod*
|
||||
*.cmd
|
||||
.tmp_versions/
|
||||
modules.order
|
||||
Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/c
|
||||
|
6
CMakeLists.txt
Normal file
6
CMakeLists.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(conway)
|
||||
|
||||
add_executable(conway conway.c)
|
||||
target_compile_options(conway PUBLIC -ggdb -O0 -Wall)
|
60
conway.c
60
conway.c
|
@ -1,44 +1,46 @@
|
|||
#include <locale.h>
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <wchar.h>
|
||||
#include <locale.h>
|
||||
|
||||
void printGrid(int gridX, int gridY, int **arr) {
|
||||
void printGrid(int gridX, int gridY, int** arr)
|
||||
{
|
||||
// print the array for debugging
|
||||
wprintf(L"%lc", 0x2554);
|
||||
for(int j = 0; j < gridY; j++) {
|
||||
wprintf(L"%lc", 0x2550);
|
||||
wprintf(L"%lc", 0x2554UL); // prints ╔
|
||||
for (int j = 0; j < gridX; j++) {
|
||||
wprintf(L"%lc", 0x2550UL); // prints ═
|
||||
}
|
||||
wprintf(L"%lc", 0x2557);
|
||||
wprintf(L"%lc", 0x2557UL); // prints ╗
|
||||
wprintf(L"\n");
|
||||
for(int j = 0; j < gridY; j++) {
|
||||
wprintf(L"%lc", 0x2551);
|
||||
for(int i = 0; i < gridX; i++) {
|
||||
wprintf(L"%lc", ((arr[i][j] == 1) ? 0x0023 : 0x0020));
|
||||
for (int j = 0; j < gridY; j++) {
|
||||
wprintf(L"%lc", 0x2551UL); // prints ║
|
||||
for (int i = 0; i < gridX; i++) {
|
||||
wprintf(L"%lc", ((arr[i][j] == 1) ? 0x0023UL : 0x0020UL));
|
||||
}
|
||||
wprintf(L"%lc\n", 0x2551);
|
||||
wprintf(L"%lc\n", 0x2551UL); // prints ║
|
||||
}
|
||||
wprintf(L"%lc", 0x255A);
|
||||
for(int j = 0; j < gridY; j++) {
|
||||
wprintf(L"%lc", 0x2550);
|
||||
wprintf(L"%lc", 0x255AUL); // prints ╚
|
||||
for (int j = 0; j < gridX; j++) {
|
||||
wprintf(L"%lc", 0x2550UL);
|
||||
}
|
||||
wprintf(L"%lc", 0x255D);
|
||||
wprintf(L"%lc", 0x255DUL); // prints ╝
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if(argc < 3) {
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc < 3) {
|
||||
printf("Usage: conway <xsize> <ysize> [seed]\n");
|
||||
exit(255);
|
||||
}
|
||||
setlocale(LC_CTYPE, "");
|
||||
int gridX, gridY, seed = 0, generation = 0;
|
||||
for(int i = argc - 1; i > 0; i--) {
|
||||
switch(i) {
|
||||
int gridX = 0, gridY = 0, seed = 0, generation = 0;
|
||||
for (int i = argc - 1; i > 0; i--) {
|
||||
switch (i) {
|
||||
case 1:
|
||||
gridX = atoi(argv[i]);
|
||||
break;
|
||||
|
@ -50,20 +52,20 @@ int main(int argc, char *argv[]) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
if(seed == 0) {
|
||||
if (seed == 0) {
|
||||
time_t t;
|
||||
srand((unsigned) time(&t));
|
||||
srand((unsigned)time(&t));
|
||||
} else {
|
||||
srand(seed);
|
||||
}
|
||||
// dynamically allocate the 2D array, could be quite large!
|
||||
int *arr[gridX];
|
||||
for(int i = 0; i < gridY; i++) {
|
||||
arr[i] = (int *)malloc(gridY * sizeof(int));
|
||||
int* arr[gridX];
|
||||
for (int i = 0; i < gridX; i++) {
|
||||
arr[i] = (int*)malloc(gridY * sizeof(int));
|
||||
}
|
||||
// seed the array
|
||||
for(int i = 0; i < gridX; i++) {
|
||||
for(int j = 0; j < gridY; j++) {
|
||||
for (int i = 0; i < gridX; i++) {
|
||||
for (int j = 0; j < gridY; j++) {
|
||||
arr[i][j] = (rand() % 2 == 0) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue