Merge pull request #169 from cellos51/implement_joker_testing

Implement joker testing
This commit is contained in:
MeirGavish
2025-10-13 21:27:42 +03:00
committed by GitHub
3 changed files with 39 additions and 4 deletions
+2
View File
@@ -17,9 +17,11 @@ bool list_remove_by_idx(List *list, int index);
void* list_get(List *list, int index);
int list_get_size(List *list);
bool list_remove_by_value(List *list, void *value);
bool list_exists(List *list, void *value);
bool int_list_append(List *list, intptr_t value);
intptr_t int_list_get(List *list, int index);
bool int_list_remove_by_value(List *list, intptr_t value);
bool int_list_exists(List *list, intptr_t value);
#endif
+17 -4
View File
@@ -2436,10 +2436,23 @@ static void game_shop_create_items()
for (int i = 0; i < MAX_SHOP_JOKERS; i++)
{
// TODO: weight the random choice by joker rarity
int joker_idx = random() % list_get_size(jokers_available_to_shop);
intptr_t joker_id = int_list_get(jokers_available_to_shop, joker_idx);
list_remove_by_idx(jokers_available_to_shop, joker_idx);
int joker_idx = 0;
intptr_t joker_id = 0;
#ifdef TEST_JOKER_ID // Allow defining an ID for a joker to always appear in shop and be tested
if (int_list_exists(jokers_available_to_shop, TEST_JOKER_ID))
{
joker_id = TEST_JOKER_ID;
int_list_remove_by_value(jokers_available_to_shop, joker_id);
}
else
#endif
{
joker_idx = random() % list_get_size(jokers_available_to_shop);
joker_id = int_list_get(jokers_available_to_shop, joker_idx);
// TODO: weight the random choice by joker rarity
list_remove_by_idx(jokers_available_to_shop, joker_idx);
}
JokerObject *joker_object = joker_object_new(joker_new(joker_id));
+20
View File
@@ -99,3 +99,23 @@ int list_get_size(List *list)
}
return list->size;
}
bool list_exists(List *list, void *value)
{
if (list == NULL) return false;
for (int i = 0; i < list->size; i++)
{
if (list->_array[i] == value)
{
return true;
}
}
return false;
}
bool int_list_exists(List *list, intptr_t value)
{
return list_exists(list, (void*)value);
}