Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,46 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

include(FetchContent)
option(TRACY_ENABLE "" ON)
include_directories(
${PROJECT_SOURCE_DIR}/tracy
)

# Define sources for the library
set(LIB_SOURCES
src/functions.hpp
src/instance.hpp
src/filters.cpp
src/items.cpp
src/rng.cpp
src/search.cpp
src/seed.cpp
src/util.cpp
src/functions.cpp
tracy/tracy/Tracy.hpp
)

FetchContent_Declare (
tracy
GIT_REPOSITORY https://github.com/wolfpld/tracy.git
GIT_TAG master
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(tracy)

# Define sources for the executable
set(EXECUTABLE_SOURCES
src/main.cpp
tracy/TracyClient.cpp
)

# Set optimization flags based on the compiler
if(MSVC)
set(OPTIMIZATION_FLAGS "/Ox") # Full optimization for MSVC
else()
set(OPTIMIZATION_FLAGS "-O3 -g -std=c++20 -Wall -Wextra -Wpedantic -Wno-c++17-extensions -gdwarf-3 -ldl") # Full optimization for GCC/Clang, plus debugging info
set(OPTIMIZATION_FLAGS "-O3 -g -std=c++20 -Wall -Wextra -Wpedantic -Wno-c++17-extensions -gdwarf-3 -march=native -lpthread -ldl") # Full optimization for GCC/Clang, plus debugging info
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPTIMIZATION_FLAGS}")
Expand Down Expand Up @@ -61,4 +79,4 @@ generate_export_header(${PROJECT_NAME}
)

add_executable(immol ${EXECUTABLE_SOURCES})
target_link_libraries(immol ${PROJECT_NAME})
target_link_libraries(immol ${PROJECT_NAME} TracyClient)
243 changes: 243 additions & 0 deletions src/filters.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
#include "filters.hpp"
#include <vector>
#include <numeric>

void Filter::parseJSON(std::string input) {
//Populate Lists with variables from the Json
return;
}


long searchWithFilter(Instance inst, Filter &filter) {
int searchSize = filter.searchList.size();
int modSize = filter.instanceModList.size();
int amountFoundList[MAX_SEARCH_LIST_SIZE] = {0};

for (int ante = 1; ante <= filter.maxAnte; ante++) {
for(int m = 1; m <= modSize; m++) {
if(m >= filter.instanceModList[m-1].startAnte && m <= filter.instanceModList[m-1].endAnte) {
inst.unlock(filter.instanceModList[m].modifier);
}
}
for (int i = 0; i < searchSize; i++) {
if (ante > filter.searchList[i].maxAnte) { continue; }
amountFoundList[i] += searchWithObject(inst, filter.searchList[i], ante);
}
}

//Check if you have found all the items in a list
int correct_amounts = 0;
for (int i = 0; i < searchSize; i++) {
if (amountFoundList[i] >= filter.searchList[i].amount) {
correct_amounts++;
}
}
if (correct_amounts == searchSize) {
return 1;
}

return 0;

}

inline long searchWithObject(Instance inst, SearchObject &searchObject, int ante){
switch (searchObject.searchType) {
case SearchableType::Joker:
return searchForJoker(inst, searchObject, ante);
case SearchableType::Tarot:
return searchForTarot(inst, searchObject, ante);
case SearchableType::Planet:
return searchForPlanet(inst, searchObject, ante);
case SearchableType::Spectral:
return searchForSpectral(inst, searchObject, ante);
case SearchableType::Card:
return searchForCard(inst, searchObject, ante);
case SearchableType::Tag:
return searchForTag(inst, searchObject, ante);
case SearchableType::Voucher:
return searchForVoucher(inst, searchObject, ante);
default:
return 0;
}
}

long searchForJoker(Instance inst, SearchObject &searchObject, int ante) {
int amount_found = 0;
int max_packs = 4;
if (ante > 1) max_packs = 6;

//I created nextJokerOnly to save on mem
//for now we'll just use storedepth given

for(int s = 1; s <= searchObject.storeDepth; s++) {
if (inst.nextJokerOnly(ItemSource::Shop, ante) == searchObject.item) {
amount_found++;
}
}

for (int p = 1; p <= max_packs; p++) {
if (inst.nextJokerOnly(ItemSource::Buffoon_Pack, ante) == searchObject.item) {
amount_found++;
}
}

return amount_found;
}

long searchForTarot(Instance inst, SearchObject &searchObject, int ante) {
int amount_found = 0;
int max_packs = 4;
if (ante > 1) max_packs = 6;
int max_store_items = 10;
if (ante > 1) max_store_items = 50;

//Check packs
for (int p = 1; p <= max_packs; p++) {
Pack pack = packInfo(inst.nextPack(ante));
if (pack.type == Item::Arcana_Pack ||
pack.type == Item::Jumbo_Arcana_Pack ||
pack.type == Item::Mega_Arcana_Pack) {
auto packContents = inst.nextArcanaPack(pack.size, 1);
for (int x = 0; x < pack.size; x++) {
if (packContents[x] == searchObject.item) {
amount_found++;
}
}
}
continue;
}

//Check shop
for (int s = 1; s <= max_store_items; s++) {
ShopItem shop_item = inst.nextShopItem(ante);
if (shop_item.item == searchObject.item) {
amount_found++;
}
}

return amount_found;
}

long searchForPlanet(Instance inst, SearchObject &searchObject, int ante) {
int amount_found = 0;
int max_packs = 4;
if (ante > 1) max_packs = 6;
int max_store_items = 10;
if (ante > 1) max_store_items = 50;

//Check packs
for (int p = 1; p <= max_packs; p++) {
Pack pack = packInfo(inst.nextPack(ante));
if (pack.type == Item::Celestial_Pack ||
pack.type == Item::Jumbo_Celestial_Pack ||
pack.type == Item::Mega_Celestial_Pack) {
auto packContents = inst.nextArcanaPack(pack.size, 1);
for (int x = 0; x < pack.size; x++) {
if (packContents[x] == searchObject.item) {
amount_found++;
}
}
}
continue;
}

//Check shop
for (int s = 1; s <= max_store_items; s++) {
ShopItem shop_item = inst.nextShopItem(ante);
if (shop_item.item == searchObject.item) {
amount_found++;
}
}

return amount_found;
}

long searchForSpectral(Instance inst, SearchObject &searchObject, int ante) {
int amount_found = 0;
int max_packs = 4;
if (ante > 1) max_packs = 6;
// int max_store_items = 10;
// if (ante > 1) max_store_items = 50;

//Check packs
for (int p = 1; p <= max_packs; p++) {
Pack pack = packInfo(inst.nextPack(ante));
if (pack.type == Item::Spectral_Pack ||
pack.type == Item::Jumbo_Spectral_Pack ||
pack.type == Item::Mega_Spectral_Pack) {
auto packContents = inst.nextArcanaPack(pack.size, 1);
for (int x = 0; x < pack.size; x++) {
if (packContents[x] == searchObject.item) {
amount_found++;
}
}
}
continue;
}

//Check shop TODO: Setup instance
/*for (int s = 1; s <= max_store_items; s++) {
ShopItem shop_item = inst.nextShopItem(ante);
if (shop_item.item == &searchObject.item) {
amount_found++;
}
}*/

return amount_found;
}

long searchForCard(Instance inst, SearchObject &searchObject, int ante) {
int amount_found = 0;
int max_packs = 4;
if (ante > 1) max_packs = 6;
// int max_store_items = 10;
// if (ante > 1) max_store_items = 50;

//Check packs
for (int p = 1; p <= max_packs; p++) {
Pack pack = packInfo(inst.nextPack(ante));
if (pack.type == Item::Standard_Pack ||
pack.type == Item::Jumbo_Standard_Pack ||
pack.type == Item::Mega_Standard_Pack) {
auto packContents = inst.nextArcanaPack(pack.size, 1);
for (int x = 0; x < pack.size; x++) {
if (packContents[x] == searchObject.item) {
amount_found++;
}
}
}
continue;
}

//Check shop TODO: Setup instance
/*for (int s = 1; s <= max_store_items; s++) {
ShopItem shop_item = inst.nextShopItem(ante);
if (shop_item.item == &searchObject.item) {
amount_found++;
}
}*/

return amount_found;
}


long searchForTag(Instance inst, SearchObject &searchObject, int ante) {
int amount_found = 0;

for(int i = 1; i <=2; i++) {
if(inst.nextTag(ante) == searchObject.item) {
amount_found++;
}
}

return amount_found;
}

//TODO: Setup instance prior to calling this
// May want to seperate ante 1 loop for examples like perkeo_observatory
long searchForVoucher(Instance inst, SearchObject &searchObject, int ante) {
if(inst.nextVoucher(ante) == searchObject.item) {
return 1;
}
return 0;
}
80 changes: 80 additions & 0 deletions src/filters.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#ifndef FILTERS_HPP
#define FILTERS_HPP

#include "functions.hpp"
#include <string>
#include <vector>

//Defining searchable types here
enum class SearchableType {
//Objects
Joker,
Voucher,
Tag,
Tarot,
Planet,
Spectral,
Card,
Booster_Pack,
//Modifiers
Suit,
Rank,
Enhancement,
Seal,
Edition,
//Other
Deck,
Hand,
Blind

};

struct SearchObject {
Item item;
SearchableType searchType;
int8_t storeDepth;
int8_t maxAnte;
int8_t amount;
};

struct InstanceModifier {
Item modifier;
int8_t startAnte;
int8_t endAnte;
};

//Possible optimizations for bigger searchList
//Generating all the items before searching
class Filter {
public:
bool orderedSearch = true;
bool preGenItems = false;
int maxAnte = 1;

std::vector<SearchObject> searchList;
std::vector<InstanceModifier> instanceModList;

void parseJSON(std::string input);
long generateObjects(Instance inst);
};

#define MAX_SEARCH_LIST_SIZE 10

long searchWithFilter(Instance inst, Filter &filter);
long searchWithObject(Instance inst, SearchObject &searchObject, int ante);

//Appear in shop & packs
//TODO: Possibly combine some of these functions (They use similar code)
long searchForJoker(Instance inst, SearchObject &searchObject, int ante);
long searchForTarot(Instance inst, SearchObject &searchObject, int ante);
long searchForPlanet(Instance inst, SearchObject &searchObject, int ante);

//Appear in packs (mostly)
long searchForSpectral(Instance inst, SearchObject &searchObject, int ante);
long searchForCard(Instance inst, SearchObject &searchObject, int ante);

//Appears on ante
long searchForTag(Instance inst, SearchObject &searchObject, int ante);
long searchForVoucher(Instance inst, SearchObject &searchObject, int ante);

#endif
Loading