Skip to content
Snippets Groups Projects
Commit 3115b9e8 authored by clemo's avatar clemo
Browse files

long int, comments


Signed-off-by: default avatarclemo <clemo@cbcode.at>
parent 8e280da7
No related branches found
No related tags found
No related merge requests found
Pipeline #4551 passed
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#include "./gol.h" #include "./gol.h"
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
const unsigned int ROUNDS = 10;
void print_colmn(unsigned int value) void print_colmn(unsigned int value)
{ {
printf("%d", value); printf("%d", value);
...@@ -22,15 +21,15 @@ int main(int argc, char **argv) ...@@ -22,15 +21,15 @@ int main(int argc, char **argv)
game->current[1] = 51; game->current[1] = 51;
game->current[2] = 1271; game->current[2] = 1271;
game->current[5] = 51; game->current[5] = 51;
unsigned int round = 0; unsigned long int round = 0;
while (1) while (1)
{ {
printf("round: %d \n", round++); printf("round: %ld \n", round++);
gol_each(game, &print_colmn, &print_row); gol_each(game, &print_colmn, &print_row);
gol_tick(game); gol_tick(game);
printf("\033[%dA", height + 1); printf("\033[%dA", height + 1);
printf("\033[%dD", width); printf("\033[%dD", width);
usleep(200000); // usleep(200000);
} }
gol_free(game); gol_free(game);
} }
...@@ -36,14 +36,9 @@ void gol_free(gol_t *g) ...@@ -36,14 +36,9 @@ void gol_free(gol_t *g)
free(g); free(g);
} }
int pMod(int x, int y)
{
return (x + y) % y;
}
int getCell(gol_t *g, int cell) int getCell(gol_t *g, int cell)
{ {
cell = pMod(cell, g->width * g->height); cell = cell % (g->width * g->height);
div_t d = div(cell, 8); div_t d = div(cell, 8);
return g->current[d.quot] & (1 << (d.rem)) ? 1 : 0; return g->current[d.quot] & (1 << (d.rem)) ? 1 : 0;
} }
......
...@@ -15,7 +15,18 @@ void print_row(unsigned int line) ...@@ -15,7 +15,18 @@ void print_row(unsigned int line)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
gol_t *game = gol_setup(5, 15); gol_t *game = gol_setup(5, 15);
//set walker
/*
# set walker
# split by 5 (width)
00000
001 #128
00
01010
0 #20
1100
0000 #3
*/
game->current[0] = 128; game->current[0] = 128;
game->current[1] = 20; game->current[1] = 20;
game->current[2] = 3; game->current[2] = 3;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment