add suggestions

This commit is contained in:
biglyderv 2025-03-26 21:19:01 -04:00
parent e6165f3af8
commit 34d2d97c82
Signed by: biglyderv
GPG key ID: 0E2EB0B4CD7397B5
6 changed files with 177 additions and 15 deletions

View file

@ -8,44 +8,63 @@
#define inv_file "inv.txt"
#define inv_base_file "inv_base.txt"
#define combo_file "combos.txt"
#define poll_file "polls.txt"
#define polls_lock_file "polls_lock.txt"
#define MAX_BUF_LENGTH 1024
#define MAX_COMBO_LENGTH 1024
void init_tables(hashmap *elements, hashmap *inv, int do_inv) {
load_elements(elements, "../elem_data/" combo_file, 0) ||
load_elements(elements, combo_file, 0) ||
void init_tables(hashmap *elements, hashmap *inv, hashmap *polls, int do_inv) {
load_elements(elements, "../elem_data/" combo_file, 0);
load_elements(elements, combo_file, 0) ||
load_elements(elements, "bin/" combo_file, 0);
load_elements(polls, "../elem_data/" poll_file, 2);
if (!do_inv)
return;
load_elements(elements, "../elem_data/" inv_base_file, 1) ||
load_elements(inv, inv_base_file, 1) ||
load_elements(inv, "bin/" inv_base_file, 1);
load_elements(inv, inv_file, 1);
}
int main(int argc, char *argv[]) {
char *name;
if (argc < 2) {
name = "guest";
} else {
name = argv[1];
}
hashmap *elements = hashmap_create();
hashmap *inv = hashmap_create();
hashmap *polls = hashmap_create();
char *command = calloc(MAX_BUF_LENGTH, sizeof(char));
char *command_re = calloc(MAX_BUF_LENGTH, sizeof(char));
char **sort_tmp = calloc(MAX_COMBO_LENGTH, sizeof(char **));
init_tables(elements, inv, 1);
int wasCombination = 0;
load_elements(inv, inv_file, 1);
init_tables(elements, inv, polls, 1);
printf("Welcome to Elemental on Command Line!\n");
printf("%s, welcome to Elemental on Command Line!\n", name);
while (1) {
// todo: separate into functions
printf("\n");
fgets(command, MAX_BUF_LENGTH - 1, stdin);
int slashRan = slash_command(command, inv);
if (slashRan)
if (wasCombination && suggest_command(command, command_re, polls, name)) {
wasCombination = 0;
continue;
}
wasCombination = 0;
if (slash_command(command, inv))
continue;
int combos = get_command(command, command_re, sort_tmp);
@ -68,13 +87,14 @@ int main(int argc, char *argv[]) {
hashmap_get(elements, command_re, strlen(command_re), &result);
if (result == 0) {
init_tables(elements, inv, 0);
init_tables(elements, inv, polls, 0);
hashmap_get(elements, command_re, strlen(command_re), &result);
}
if (result == 0) {
printf("You didn't make anything.\n");
wasCombination = 1;
printf("You didn't make anything; use /suggest to suggest an element.\n");
continue;
}