nxcgol
An implementation of Conway's Game of Life for the Nintendo Switch
 
Loading...
Searching...
No Matches
main.c File Reference
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <switch.h>

Data Structures

struct  Color
 
struct  Config
 

Macros

#define CONFIG_FILE   "nxcgol.config.txt"
 config file
 
#define ROWS   46
 total rows
 
#define COLS   81
 t
 
#define HISTORY_SIZE   8
 retain x generations for comparison
 
#define CELL   0xDB
 solid block cp437
 
#define UP   0x18
 up arrow cp437
 
#define DOWN   0x19
 down arrow cp437
 
#define ERROR_RED   CONSOLE_ESC(31m)
 
#define CONTROLS_BLUE   CONSOLE_ESC(38;2;135;206;235m)
 
#define RESET   CONSOLE_ESC(0m)
 
#define CONSOLE_ESC_NSTR(fmt)   "\033[" fmt
 console escape helper, does not stringify.
 

Functions

bool parse_rgb (const char *value, Color *color)
 parse r,g,b string into Color
 
void parse_config_file (Config *config)
 parse configuration file
 
int sim_speed_calc (int percent)
 calculate simulation speed based on percentage at 100(%) the usleep time will be 1ms at 1(%) the usleep time will be 100ms
 
void color_to_ansi (Color *c)
 convert r,g,c from Color to ansi escape sequence
 
int active_rows ()
 if show_stats is true we decrement 1 from rows to make room for stats we do this when iterating through the rows
 
int count_neighbors (int x, int y)
 get the neighbors of this cell
 
void randomize_matrix ()
 generate cells for new colony
 
void restart_simulation ()
 reset history, generation_index and increment restart_index, generate new colony.
 
int main (int argc, char **argv)
 

Variables

Config config
 default configuration
 
bool matrix [COLS][ROWS]
 
bool matrix_next [COLS][ROWS]
 
bool history [HISTORY_SIZE][COLS][ROWS]
 
int history_index = 0
 generations in history, for comparison to check for oscillation
 
int generation_index = 0
 generation number
 
int restart_index = 0
 colony number
 
int stagnant_index = 0
 number of generations colony has been stagnant
 

Macro Definition Documentation

◆ CELL

#define CELL   0xDB

solid block cp437

◆ COLS

#define COLS   81

t

◆ CONFIG_FILE

#define CONFIG_FILE   "nxcgol.config.txt"

config file

◆ CONSOLE_ESC_NSTR

#define CONSOLE_ESC_NSTR (   fmt)    "\033[" fmt

console escape helper, does not stringify.

◆ CONTROLS_BLUE

#define CONTROLS_BLUE   CONSOLE_ESC(38;2;135;206;235m)

◆ DOWN

#define DOWN   0x19

down arrow cp437

◆ ERROR_RED

#define ERROR_RED   CONSOLE_ESC(31m)

◆ HISTORY_SIZE

#define HISTORY_SIZE   8

retain x generations for comparison

◆ RESET

#define RESET   CONSOLE_ESC(0m)

◆ ROWS

#define ROWS   46

total rows

◆ UP

#define UP   0x18

up arrow cp437