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:
A.M. Rowsell 2023-05-28 15:25:50 -04:00
commit 63e79c2527
Signed by: amr
GPG key ID: 0B6E2D8375CF79A9
3 changed files with 122 additions and 29 deletions

85
.gitignore vendored Normal file
View 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
View 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)

View file

@ -1,42 +1,44 @@
#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);
wprintf(L"%lc", 0x2551UL); // prints ║
for (int i = 0; i < gridX; i++) {
wprintf(L"%lc", ((arr[i][j] == 1) ? 0x0023 : 0x0020));
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[]) {
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;
int gridX = 0, gridY = 0, seed = 0, generation = 0;
for (int i = argc - 1; i > 0; i--) {
switch (i) {
case 1:
@ -58,7 +60,7 @@ int main(int argc, char *argv[]) {
}
// dynamically allocate the 2D array, could be quite large!
int* arr[gridX];
for(int i = 0; i < gridY; i++) {
for (int i = 0; i < gridX; i++) {
arr[i] = (int*)malloc(gridY * sizeof(int));
}
// seed the array