Compare commits

...

2 Commits

Author SHA1 Message Date
Aryadev Chavali
3b02b934d8 some cleanup and changes 2026-03-20 03:14:02 +00:00
Aryadev Chavali
d338fabddc base: set mutation chance to simulation size
This results in the expected value of the number of mutations at any
one iteration to be 1, which is good.
2026-03-20 03:13:09 +00:00
3 changed files with 6 additions and 14 deletions

View File

@@ -36,7 +36,7 @@ typedef double f64;
// Simulation constants // Simulation constants
#define SIZEOF_PROGRAM_POW_2 6 #define SIZEOF_PROGRAM_POW_2 6
#define SIZEOF_PROGRAM (1 << SIZEOF_PROGRAM_POW_2) #define SIZEOF_PROGRAM (1 << SIZEOF_PROGRAM_POW_2)
#define NUM_PROGRAMS_POW_2 10 #define NUM_PROGRAMS_POW_2 12
#define NUM_PROGRAMS (1 << NUM_PROGRAMS_POW_2) #define NUM_PROGRAMS (1 << NUM_PROGRAMS_POW_2)
#define SIMULATION_SIZE (NUM_PROGRAMS * SIZEOF_PROGRAM) #define SIMULATION_SIZE (NUM_PROGRAMS * SIZEOF_PROGRAM)
@@ -47,10 +47,9 @@ typedef double f64;
#define CELL_WIDTH (WIDTH / (f64)CELL_ROW_SIZE) #define CELL_WIDTH (WIDTH / (f64)CELL_ROW_SIZE)
#define CELL_HEIGHT (HEIGHT / (f64)CELL_ROW_SIZE) #define CELL_HEIGHT (HEIGHT / (f64)CELL_ROW_SIZE)
#define MUTATION_CHANCE 5000 #define MUTATION_CHANCE (SIMULATION_SIZE)
#define MUTATION_OFFSET 1
#define DRAW_PROGRAM_OUTLINE 1 #define DRAW_PROGRAM_OUTLINE 0
#endif #endif

View File

@@ -105,10 +105,6 @@ void program_execute(struct ProgramConcat *prg)
switch (opcode) switch (opcode)
{ {
case '<': case '<':
// NOTE: We're doing a safe subtraction here, but maybe we should
// terminate execution if subtraction will overflow?
// ctx.head0 = SAFE_SUB(ctx.head0, 1);
ctx.head0 -= 1; ctx.head0 -= 1;
ctx.head0 %= sizeof(prg->tape); ctx.head0 %= sizeof(prg->tape);
++ctx.ip; ++ctx.ip;
@@ -118,10 +114,6 @@ void program_execute(struct ProgramConcat *prg)
++ctx.ip; ++ctx.ip;
break; break;
case '{': case '{':
// NOTE: We're doing a safe subtraction here, but maybe we should
// terminate execution if subtraction will overflow?
// ctx.head1 = SAFE_SUB(ctx.head1, 1);
ctx.head1 -= 1; ctx.head1 -= 1;
ctx.head1 %= sizeof(prg->tape); ctx.head1 %= sizeof(prg->tape);
++ctx.ip; ++ctx.ip;

View File

@@ -45,6 +45,7 @@ void simulation_iterate(simulation_t *sim)
{ {
a_b_concat = calloc(1, sizeof(*a_b_concat)); a_b_concat = calloc(1, sizeof(*a_b_concat));
} }
// Ensure a_b_concat is completely zeroed
memset(a_b_concat, 0, sizeof(*a_b_concat)); memset(a_b_concat, 0, sizeof(*a_b_concat));
// Reaction: Concat, execute, split. // Reaction: Concat, execute, split.
@@ -155,7 +156,7 @@ void simulation_pick_rng_neighbour(u64 *a, u64 *b)
*b = neighbours[rand() % size]; *b = neighbours[rand() % size];
} }
static char *VALID_OPS = "<>{}-+.,[]"; static const char *VALID_OPS = "<>{}-+.,[]";
static const Color possible_colors[] = { static const Color possible_colors[] = {
['<'] = {230, 25, 75, 255}, ['>'] = {60, 180, 75, 255}, ['<'] = {230, 25, 75, 255}, ['>'] = {60, 180, 75, 255},
['{'] = {255, 225, 25, 255}, ['}'] = {0, 130, 200, 255}, ['{'] = {255, 225, 25, 255}, ['}'] = {0, 130, 200, 255},
@@ -167,7 +168,7 @@ static const Color possible_colors[] = {
Color simulation_cell_color(const bf_token cell) Color simulation_cell_color(const bf_token cell)
{ {
return possible_colors[strchr(VALID_OPS, cell) ? cell : '\0']; return possible_colors[(!!strchr(VALID_OPS, (u8)cell)) * cell];
} }
/* Copyright (C) 2026 Aryadev Chavali /* Copyright (C) 2026 Aryadev Chavali