summaryrefslogtreecommitdiff
path: root/cuda-global/src/create_grid.cu
diff options
context:
space:
mode:
authorSimponic <loganhunt@simponic.xyz>2021-12-04 13:34:49 -0700
committerSimponic <loganhunt@simponic.xyz>2021-12-04 13:34:49 -0700
commitaa1d7c6e284cc0818325614391619f3ff13d3e94 (patch)
tree8a59a6b3e5aacb7f682756d3c7751f1d72e1d940 /cuda-global/src/create_grid.cu
downloadgol-aa1d7c6e284cc0818325614391619f3ff13d3e94.tar.gz
gol-aa1d7c6e284cc0818325614391619f3ff13d3e94.zip
Initial commit
Diffstat (limited to 'cuda-global/src/create_grid.cu')
-rw-r--r--cuda-global/src/create_grid.cu38
1 files changed, 38 insertions, 0 deletions
diff --git a/cuda-global/src/create_grid.cu b/cuda-global/src/create_grid.cu
new file mode 100644
index 0000000..fa208f2
--- /dev/null
+++ b/cuda-global/src/create_grid.cu
@@ -0,0 +1,38 @@
+#include "create_grid.cuh"
+
+void print_grid(struct GAME* game) {
+ printf("\n===GRID===\n");
+ for (int y = 0; y < game->height; y++) {
+ for (int x = 0; x < game->width; x++) {
+ printf("%i ", game->grid[y*(game->width+game->padding*2) + x]);
+ }
+ printf("\n");
+ }
+}
+
+void create_grid(int argc, char** argv) {
+ char* filename;
+ struct GAME game;
+ game.padding = 0;
+ if (argc == 5) {
+ game.width = atoi(argv[2]);
+ game.height = atoi(argv[3]);
+ filename = argv[4];
+ } else {
+ printf("Usage: ./gol create-grid <width> <height> <filename>\n");
+ exit(1);
+ }
+
+ int size = (game.width+game.padding*2) * (game.height+game.padding*2);
+ unsigned char* grid = (unsigned char*)malloc(sizeof(unsigned char) * size);
+ for (int y = 0; y < game.height; y++) {
+ printf("Row %i: ", y);
+ for (int x = 0; x < game.width; x++) {
+ char temp;
+ scanf("%i%c", (unsigned int*)&game.grid[y*(game.width+game.padding*2) + x],&temp);
+ }
+ }
+ game.grid = grid;
+ write_out(filename, &game);
+ print_grid(&game);
+}