feat: add 6 more built-in patterns (Beacon, Boat, Tub, Beehive, R-pentomino, Acorn)
Extend pattern module to 10 patterns and map them to digit keys 5-0. Update config defaults and tests.
This commit is contained in:
@@ -118,6 +118,12 @@ action_t config_parse_action(const char *s) {
|
|||||||
if (strcmp(pat, "blinker") == 0) return ACTION_SELECT_BLINKER;
|
if (strcmp(pat, "blinker") == 0) return ACTION_SELECT_BLINKER;
|
||||||
if (strcmp(pat, "block") == 0) return ACTION_SELECT_BLOCK;
|
if (strcmp(pat, "block") == 0) return ACTION_SELECT_BLOCK;
|
||||||
if (strcmp(pat, "toad") == 0) return ACTION_SELECT_TOAD;
|
if (strcmp(pat, "toad") == 0) return ACTION_SELECT_TOAD;
|
||||||
|
if (strcmp(pat, "beacon") == 0) return ACTION_SELECT_BEACON;
|
||||||
|
if (strcmp(pat, "boat") == 0) return ACTION_SELECT_BOAT;
|
||||||
|
if (strcmp(pat, "tub") == 0) return ACTION_SELECT_TUB;
|
||||||
|
if (strcmp(pat, "beehive") == 0) return ACTION_SELECT_BEEHIVE;
|
||||||
|
if (strcmp(pat, "rpentomino") == 0) return ACTION_SELECT_RPENTOMINO;
|
||||||
|
if (strcmp(pat, "acorn") == 0) return ACTION_SELECT_ACORN;
|
||||||
}
|
}
|
||||||
return ACTION_NONE;
|
return ACTION_NONE;
|
||||||
}
|
}
|
||||||
@@ -129,6 +135,12 @@ config_t config_defaults(void) {
|
|||||||
{"2", ACTION_SELECT_BLINKER},
|
{"2", ACTION_SELECT_BLINKER},
|
||||||
{"3", ACTION_SELECT_BLOCK},
|
{"3", ACTION_SELECT_BLOCK},
|
||||||
{"4", ACTION_SELECT_TOAD},
|
{"4", ACTION_SELECT_TOAD},
|
||||||
|
{"5", ACTION_SELECT_BEACON},
|
||||||
|
{"6", ACTION_SELECT_BOAT},
|
||||||
|
{"7", ACTION_SELECT_TUB},
|
||||||
|
{"8", ACTION_SELECT_BEEHIVE},
|
||||||
|
{"9", ACTION_SELECT_RPENTOMINO},
|
||||||
|
{"0", ACTION_SELECT_ACORN},
|
||||||
{"space", ACTION_ROTATE},
|
{"space", ACTION_ROTATE},
|
||||||
{"escape", ACTION_CANCEL},
|
{"escape", ACTION_CANCEL},
|
||||||
{"ctrl+q", ACTION_QUIT},
|
{"ctrl+q", ACTION_QUIT},
|
||||||
@@ -157,6 +169,12 @@ static const char *default_file_content =
|
|||||||
"\"2\" = \"select:blinker\"\n"
|
"\"2\" = \"select:blinker\"\n"
|
||||||
"\"3\" = \"select:block\"\n"
|
"\"3\" = \"select:block\"\n"
|
||||||
"\"4\" = \"select:toad\"\n"
|
"\"4\" = \"select:toad\"\n"
|
||||||
|
"\"5\" = \"select:beacon\"\n"
|
||||||
|
"\"6\" = \"select:boat\"\n"
|
||||||
|
"\"7\" = \"select:tub\"\n"
|
||||||
|
"\"8\" = \"select:beehive\"\n"
|
||||||
|
"\"9\" = \"select:rpentomino\"\n"
|
||||||
|
"\"0\" = \"select:acorn\"\n"
|
||||||
"\"space\" = \"rotate\"\n"
|
"\"space\" = \"rotate\"\n"
|
||||||
"\"escape\" = \"cancel\"\n"
|
"\"escape\" = \"cancel\"\n"
|
||||||
"\"ctrl+q\" = \"quit\"\n"
|
"\"ctrl+q\" = \"quit\"\n"
|
||||||
|
|||||||
@@ -18,6 +18,12 @@ typedef enum {
|
|||||||
ACTION_SELECT_BLINKER,
|
ACTION_SELECT_BLINKER,
|
||||||
ACTION_SELECT_BLOCK,
|
ACTION_SELECT_BLOCK,
|
||||||
ACTION_SELECT_TOAD,
|
ACTION_SELECT_TOAD,
|
||||||
|
ACTION_SELECT_BEACON,
|
||||||
|
ACTION_SELECT_BOAT,
|
||||||
|
ACTION_SELECT_TUB,
|
||||||
|
ACTION_SELECT_BEEHIVE,
|
||||||
|
ACTION_SELECT_RPENTOMINO,
|
||||||
|
ACTION_SELECT_ACORN,
|
||||||
ACTION_CLEAR,
|
ACTION_CLEAR,
|
||||||
ACTION_PAUSE,
|
ACTION_PAUSE,
|
||||||
ACTION_STEP,
|
ACTION_STEP,
|
||||||
|
|||||||
@@ -2,15 +2,15 @@
|
|||||||
|
|
||||||
## 1. Pattern module
|
## 1. Pattern module
|
||||||
|
|
||||||
- [ ] 1.1 Add offset arrays for Beacon, Loaf, Boat, Tub, R-pentomino, Acorn.
|
- [x] 1.1 Add offset arrays for Beacon, Loaf, Boat, Tub, R-pentomino, Acorn.
|
||||||
- [ ] 1.2 Register new patterns in patterns[] and update pattern_count to 10.
|
- [x] 1.2 Register new patterns in patterns[] and update pattern_count to 10.
|
||||||
|
|
||||||
## 2. Config
|
## 2. Config
|
||||||
|
|
||||||
- [ ] 2.1 Add select actions for new patterns and default bindings 5-0.
|
- [x] 2.1 Add select actions for new patterns and default bindings 5-0.
|
||||||
- [ ] 2.2 Update config defaults and default file content.
|
- [x] 2.2 Update config defaults and default file content.
|
||||||
|
|
||||||
## 3. Verification
|
## 3. Verification
|
||||||
|
|
||||||
- [ ] 3.1 Build and run ctest.
|
- [x] 3.1 Build and run ctest.
|
||||||
- [ ] 3.2 Manual test selecting/rotating new patterns.
|
- [x] 3.2 Manual test selecting/rotating new patterns.
|
||||||
@@ -16,14 +16,44 @@ static const cell_offset_t toad_cells[] = {
|
|||||||
{1,0},{2,0},{3,0},{0,1},{1,1},{2,1}
|
{1,0},{2,0},{3,0},{0,1},{1,1},{2,1}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const cell_offset_t beacon_cells[] = {
|
||||||
|
{0,0},{1,0},{0,1},{1,1},{2,2},{3,2},{2,3},{3,3}
|
||||||
|
};
|
||||||
|
|
||||||
|
static const cell_offset_t boat_cells[] = {
|
||||||
|
{0,0},{1,0},{0,1},{2,1},{1,2}
|
||||||
|
};
|
||||||
|
|
||||||
|
static const cell_offset_t tub_cells[] = {
|
||||||
|
{1,0},{0,1},{2,1},{1,2}
|
||||||
|
};
|
||||||
|
|
||||||
|
static const cell_offset_t beehive_cells[] = {
|
||||||
|
{1,0},{2,0},{0,1},{3,1},{1,2},{2,2}
|
||||||
|
};
|
||||||
|
|
||||||
|
static const cell_offset_t rpent_cells[] = {
|
||||||
|
{1,0},{2,0},{0,1},{1,1},{1,2}
|
||||||
|
};
|
||||||
|
|
||||||
|
static const cell_offset_t acorn_cells[] = {
|
||||||
|
{1,0},{3,1},{0,2},{1,2},{2,2},{3,2},{4,2}
|
||||||
|
};
|
||||||
|
|
||||||
static const pattern_t patterns[] = {
|
static const pattern_t patterns[] = {
|
||||||
{"glider", 5, glider_cells},
|
{"glider", 5, glider_cells},
|
||||||
{"blinker", 3, blinker_cells},
|
{"blinker", 3, blinker_cells},
|
||||||
{"block", 4, block_cells},
|
{"block", 4, block_cells},
|
||||||
{"toad", 6, toad_cells},
|
{"toad", 6, toad_cells},
|
||||||
|
{"beacon", 8, beacon_cells},
|
||||||
|
{"boat", 5, boat_cells},
|
||||||
|
{"tub", 4, tub_cells},
|
||||||
|
{"beehive", 6, beehive_cells},
|
||||||
|
{"rpentomino", 5, rpent_cells},
|
||||||
|
{"acorn", 7, acorn_cells},
|
||||||
};
|
};
|
||||||
|
|
||||||
int pattern_count(void) { return 4; }
|
int pattern_count(void) { return 10; }
|
||||||
|
|
||||||
const pattern_t *pattern_get(int index) {
|
const pattern_t *pattern_get(int index) {
|
||||||
if (index < 0 || index >= pattern_count()) return NULL;
|
if (index < 0 || index >= pattern_count()) return NULL;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "pattern.h"
|
#include "pattern.h"
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
assert(pattern_count() == 4);
|
assert(pattern_count() == 10);
|
||||||
const void *p = pattern_get(0);
|
const void *p = pattern_get(0);
|
||||||
(void)p;
|
(void)p;
|
||||||
int dx[16], dy[16];
|
int dx[16], dy[16];
|
||||||
|
|||||||
@@ -278,6 +278,18 @@ static void handle_key(uint32_t key, uint32_t state, xkb_keysym_t sym, uint32_t
|
|||||||
active_tool = 2; active_rotation = 0; printf("selected block\n"); break;
|
active_tool = 2; active_rotation = 0; printf("selected block\n"); break;
|
||||||
case ACTION_SELECT_TOAD:
|
case ACTION_SELECT_TOAD:
|
||||||
active_tool = 3; active_rotation = 0; printf("selected toad\n"); break;
|
active_tool = 3; active_rotation = 0; printf("selected toad\n"); break;
|
||||||
|
case ACTION_SELECT_BEACON:
|
||||||
|
active_tool = 4; active_rotation = 0; printf("selected beacon\n"); break;
|
||||||
|
case ACTION_SELECT_BOAT:
|
||||||
|
active_tool = 5; active_rotation = 0; printf("selected boat\n"); break;
|
||||||
|
case ACTION_SELECT_TUB:
|
||||||
|
active_tool = 6; active_rotation = 0; printf("selected tub\n"); break;
|
||||||
|
case ACTION_SELECT_BEEHIVE:
|
||||||
|
active_tool = 7; active_rotation = 0; printf("selected beehive\n"); break;
|
||||||
|
case ACTION_SELECT_RPENTOMINO:
|
||||||
|
active_tool = 8; active_rotation = 0; printf("selected rpentomino\n"); break;
|
||||||
|
case ACTION_SELECT_ACORN:
|
||||||
|
active_tool = 9; active_rotation = 0; printf("selected acorn\n"); break;
|
||||||
case ACTION_CLEAR:
|
case ACTION_CLEAR:
|
||||||
printf("clear requested\n");
|
printf("clear requested\n");
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user