From d36583ad6ae53708f1ae11bb7e4f4939e6ac3b4d Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Sat, 5 Apr 2025 17:27:22 +0100 Subject: allow cloning blues --- src/all.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'src/all.c') diff --git a/src/all.c b/src/all.c index 17fa45b..4cca8ae 100644 --- a/src/all.c +++ b/src/all.c @@ -89,6 +89,16 @@ enum { N_COLORS, }; +static int isRed(int cell) { + return ( + cell == RED || + cell == RED_LEFT || + cell == RED_RIGHT || + cell == RED_UP || + cell == RED_DOWN + ); +} + static const Color colors[N_COLORS][4] = { { {255, 255, 255, 255}, @@ -372,7 +382,16 @@ static void update(Game *game, uint64_t now, Arena a) { } break; case YELLOW: - game->state.grid[x + y * GRIDWIDTH] = BLACK; + if ( + (x > 0 && lastState->grid[x - 1 + y * GRIDWIDTH] == BLUE_RIGHT) || + (x < GRIDWIDTH - 1 && lastState->grid[x + 1 + y * GRIDWIDTH] == BLUE_LEFT) || + (y > 0 && lastState->grid[x + (y - 1) * GRIDWIDTH] == BLUE_DOWN) || + (y < GRIDHEIGHT - 1 && lastState->grid[x + (y + 1) * GRIDWIDTH] == BLUE_UP) + ) { + game->state.grid[x + y * GRIDWIDTH] = RED; + } else { + game->state.grid[x + y * GRIDWIDTH] = BLACK; + } break; case BLUE: blues = 0; @@ -430,6 +449,13 @@ static void update(Game *game, uint64_t now, Arena a) { break; case BLUE_LEFT: if ( + (x > 0 && isRed(lastState->grid[x - 1 + y * GRIDWIDTH])) || + (x < GRIDWIDTH - 1 && isRed(lastState->grid[x + 1 + y * GRIDWIDTH])) || + (y > 0 && isRed(lastState->grid[x + (y - 1) * GRIDWIDTH])) || + (y < GRIDHEIGHT - 1 && isRed(lastState->grid[x + (y + 1) * GRIDWIDTH])) + ) { + game->state.grid[x + y * GRIDWIDTH] = BLUE; + } else if ( x > 0 && lastState->grid[x - 1 + y * GRIDWIDTH] == EMPTY ) { @@ -440,6 +466,13 @@ static void update(Game *game, uint64_t now, Arena a) { break; case BLUE_RIGHT: if ( + (x > 0 && isRed(lastState->grid[x - 1 + y * GRIDWIDTH])) || + (x < GRIDWIDTH - 1 && isRed(lastState->grid[x + 1 + y * GRIDWIDTH])) || + (y > 0 && isRed(lastState->grid[x + (y - 1) * GRIDWIDTH])) || + (y < GRIDHEIGHT - 1 && isRed(lastState->grid[x + (y + 1) * GRIDWIDTH])) + ) { + game->state.grid[x + y * GRIDWIDTH] = BLUE; + } else if ( x < GRIDWIDTH - 1 && lastState->grid[x + 1 + y * GRIDWIDTH] == EMPTY ) { @@ -450,6 +483,13 @@ static void update(Game *game, uint64_t now, Arena a) { break; case BLUE_UP: if ( + (x > 0 && isRed(lastState->grid[x - 1 + y * GRIDWIDTH])) || + (x < GRIDWIDTH - 1 && isRed(lastState->grid[x + 1 + y * GRIDWIDTH])) || + (y > 0 && isRed(lastState->grid[x + (y - 1) * GRIDWIDTH])) || + (y < GRIDHEIGHT - 1 && isRed(lastState->grid[x + (y + 1) * GRIDWIDTH])) + ) { + game->state.grid[x + y * GRIDWIDTH] = BLUE; + } else if ( y > 0 && lastState->grid[x + (y - 1) * GRIDWIDTH] == EMPTY ) { @@ -460,6 +500,13 @@ static void update(Game *game, uint64_t now, Arena a) { break; case BLUE_DOWN: if ( + (x > 0 && isRed(lastState->grid[x - 1 + y * GRIDWIDTH])) || + (x < GRIDWIDTH - 1 && isRed(lastState->grid[x + 1 + y * GRIDWIDTH])) || + (y > 0 && isRed(lastState->grid[x + (y - 1) * GRIDWIDTH])) || + (y < GRIDHEIGHT - 1 && isRed(lastState->grid[x + (y + 1) * GRIDWIDTH])) + ) { + game->state.grid[x + y * GRIDWIDTH] = BLUE; + } else if ( y < GRIDHEIGHT - 1 && lastState->grid[x + (y + 1) * GRIDWIDTH] == EMPTY ) { -- cgit v1.2.3