Skip to content

Commit 6cfac73

Browse files
committed
Example of filter class to be populated from JSON, using searchable types and objects
1 parent 139e850 commit 6cfac73

2 files changed

Lines changed: 136 additions & 0 deletions

File tree

src/filters.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include "filters.hpp"
2+
#include "functions.hpp"
3+
#include <vector>
4+
#include <numeric>
5+
6+
void Filter::parseJSON(std::string input) {
7+
//Populate Lists with variables from the Json
8+
return;
9+
}
10+
11+
12+
long searchWithFilter(Instance inst, Filter &filter) {
13+
std::vector<int> amountFoundList;
14+
amountFoundList.resize(filter.searchList.size());
15+
std:fill(amountFoundList.begin(), amountFoundList.end(), 0);
16+
17+
for (int ante = 1; ante <= filter.maxAnte; ante++) {
18+
for (int i = 0; i < filter.searchList.size(); i++) {
19+
if (ante > filter.searchList[i].maxAnte) { continue; }
20+
amountFoundList[i] += searchWithObject(inst, filter.searchList[i], ante);
21+
}
22+
}
23+
24+
//Check if you have found all the items in a list
25+
int correct_amounts = 0;
26+
for (int i = 0; i < filter.searchList.size(); i++) {
27+
if (amountFoundList[i] >= filter.searchList[i].amount) {
28+
correct_amounts++;
29+
}
30+
}
31+
if (correct_amounts == filter.searchList.size()) {
32+
return 1;
33+
}
34+
return 0;
35+
36+
}
37+
38+
long searchWithObject(Instance inst, SearchObject searchObject, int ante){
39+
switch (searchObject.searchType) {
40+
case SearchableType::Joker:
41+
return searchForJoker(inst, searchObject, ante);
42+
default:
43+
return 0;
44+
}
45+
}
46+
47+
long searchForJoker(Instance inst, SearchObject searchObject, int ante) {
48+
int amount_found = 0;
49+
int max_packs = 4;
50+
if (ante > 1) max_packs = 6;
51+
int max_store_items = 10;
52+
if (ante > 1) max_store_items = 50;
53+
54+
//Check packs
55+
for (int p = 1; p <= max_packs; p++) {
56+
Pack pack = packInfo(inst.nextPack(ante));
57+
if (pack.type == Item::Buffoon_Pack ||
58+
pack.type == Item::Jumbo_Buffoon_Pack ||
59+
pack.type == Item::Mega_Buffoon_Pack) {
60+
auto packContents = inst.nextArcanaPack(pack.size, 1);
61+
for (int x = 0; x < pack.size; x++) {
62+
if (packContents[x] == searchObject.item) {
63+
amount_found++;
64+
}
65+
}
66+
}
67+
continue;
68+
}
69+
70+
//Check shop
71+
for (int s = 1; s <= max_store_items; s++) {
72+
ShopItem shop_item = inst.nextShopItem(ante);
73+
if (shop_item.item == searchObject.item) {
74+
amount_found++;
75+
}
76+
}
77+
78+
return amount_found;
79+
}

src/filters.hpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#ifndef FILTERS_HPP
2+
#define FILTERS_HPP
3+
4+
#include "instance.hpp"
5+
#include <string>
6+
#include <vector>
7+
8+
//Defining searchable types here
9+
enum class SearchableType {
10+
//Objects
11+
Joker,
12+
Voucher,
13+
Tag,
14+
Tarot,
15+
Planet,
16+
Spectral,
17+
Card,
18+
Booster_Pack,
19+
//Modifiers
20+
Suit,
21+
Rank,
22+
Enhancement,
23+
Seal,
24+
Edition,
25+
//Other
26+
Deck,
27+
Hand,
28+
Blind
29+
30+
};
31+
32+
struct SearchObject {
33+
Item item;
34+
SearchableType searchType;
35+
int maxAnte;
36+
int amount;
37+
};
38+
39+
//Possible optimizations for bigger searchList
40+
//Generating all the items before searching
41+
class Filter {
42+
public:
43+
bool orderedSearch = true;
44+
bool preGenItems = false;
45+
int maxAnte = 1;
46+
47+
std::vector<SearchObject> searchList;
48+
49+
void parseJSON(std::string input);
50+
long generateObjects(Instance inst);
51+
};
52+
53+
long searchWithFilter(Instance inst, Filter &filter);
54+
long searchWithObject(Instance inst, SearchObject searchObject, int ante);
55+
long searchForJoker(Instance inst, SearchObject searchObject, int ante);
56+
57+
#endif

0 commit comments

Comments
 (0)