Update formatting to consistently use tabs.

This commit is contained in:
Christoffer Lerno
2022-02-18 12:56:17 +01:00
parent bf5683b41c
commit 6b4e4f6114
10 changed files with 422 additions and 434 deletions

View File

@@ -11,10 +11,10 @@ extern fn void usleep(int time);
struct GameBoard
{
int h;
int w;
char* world;
char* temp;
int h;
int w;
char* world;
char* temp;
}
fn void GameBoard.show(GameBoard *board)
@@ -24,11 +24,11 @@ fn void GameBoard.show(GameBoard *board)
char* current = board.world;
for (int y = 0; y < board.h; y++)
{
for (int x = 0; x < board.w; x++)
{
printf(*current ? "\e[07m \e[m" : " ");
current++;
}
for (int x = 0; x < board.w; x++)
{
printf(*current ? "\e[07m \e[m" : " ");
current++;
}
printf("\e[E");
}
fflush(__stdoutp);
@@ -38,25 +38,25 @@ fn void GameBoard.evolve(GameBoard *board)
{
for (int y = 0; y < board.h; y++)
{
for (int x = 0; x < board.w; x++)
{
int n = 0;
for (int y1 = y - 1; y1 <= y + 1; y1++)
{
for (int x1 = x - 1; x1 <= x + 1; x1++)
{
int actualX = (x1 + board.w) % board.w;
int actualY = (y1 + board.h) % board.h;
if (board.world[actualX + actualY * board.w]) n++;
}
}
if (board.world[x + y * board.w]) n--;
board.temp[x + y * board.w] = (char)(n == 3 || (n == 2 && board.world[x + y * board.w]));
}
for (int x = 0; x < board.w; x++)
{
int n = 0;
for (int y1 = y - 1; y1 <= y + 1; y1++)
{
for (int x1 = x - 1; x1 <= x + 1; x1++)
{
int actualX = (x1 + board.w) % board.w;
int actualY = (y1 + board.h) % board.h;
if (board.world[actualX + actualY * board.w]) n++;
}
}
if (board.world[x + y * board.w]) n--;
board.temp[x + y * board.w] = (char)(n == 3 || (n == 2 && board.world[x + y * board.w]));
}
}
for (int i = 0; i < board.w * board.h; i++)
{
board.world[i] = board.temp[i];
board.world[i] = board.temp[i];
}
}
@@ -70,17 +70,17 @@ fn int main(int c, char** v)
if (w <= 0) w = 30;
if (h <= 0) h = 30;
GameBoard board;
board.w = w;
board.h = h;
board.world = malloc((ulong)(h * w));
board.temp = malloc((ulong)(h * w));
GameBoard board;
board.w = w;
board.h = h;
board.world = malloc((ulong)(h * w));
board.temp = malloc((ulong)(h * w));
for (int i = h * w - 1; i >= 0; i--)
{
board.world[i] = rand() % 10 == 0 ? 1 : 0;
}
for (int j = 0; j < 1000; j++)
for (int i = h * w - 1; i >= 0; i--)
{
board.world[i] = rand() % 10 == 0 ? 1 : 0;
}
for (int j = 0; j < 1000; j++)
{
board.show();
board.evolve();