Skip to content

Commit f3a0137

Browse files
authored
Merge branch 'MathIsFun0:cpp-rewrite' into cpp-rewrite
2 parents 6cfac73 + 58bb7ab commit f3a0137

5 files changed

Lines changed: 49 additions & 27 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ set(EXECUTABLE_SOURCES
2727
if(MSVC)
2828
set(OPTIMIZATION_FLAGS "/Ox") # Full optimization for MSVC
2929
else()
30-
set(OPTIMIZATION_FLAGS "-O3 -g -std=c++17 -Wall -Wextra -Wpedantic -Wno-c++17-extensions") # Full optimization for GCC/Clang, plus debugging info
30+
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
3131
endif()
3232

3333
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OPTIMIZATION_FLAGS}")

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,8 @@ cmake --build build --config Release
5050
```
5151

5252
## Future Plans
53+
- SIMD
5354
- CLI
5455
- custom filters with JSON
5556
- add all unimplemented sources
56-
- compatibility with modded items?
57-
58-
## TODO Optimizations
59-
- Thanks to @Tacodiva for alerting me to some of these
60-
- searching: don't reinitialize instances, don't reconvert int to string, allocate heap memory beforehand, allocate seeds better [use recursive approach to precompute hashes]
61-
- pseudohash: cache multiples of pi, optimize first step without dividing by num?
57+
- compatibility with modded items?

build.sh

100644100755
File mode changed.

src/instance.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,22 @@ struct InstParams {
3535

3636
struct Instance {
3737
bool locked[(int)Item::ITEMS_END] = {false};
38-
Seed& seed;
38+
Seed &seed;
3939
double hashedSeed;
4040
Cache cache;
4141
InstParams params;
4242
LuaRandom rng;
43-
Instance(Seed& s) : seed(s) {
43+
Instance(Seed &s) : seed(s) {
4444
hashedSeed = s.pseudohash(0);
4545
params = InstParams();
4646
rng = LuaRandom(0);
4747
};
48-
void reset(Seed& s) { // This is slow, use next() unless necessary
48+
void reset(Seed &s) { // This is slow, use next() unless necessary
4949
seed = s;
5050
hashedSeed = s.pseudohash(0);
5151
params = InstParams();
52-
cache.nodes.clear();
52+
cache.nodes
53+
.clear(); // Somehow `clear` is faster than swapping with empty map
5354
cache.generatedFirstPack = false;
5455
};
5556
void next() {

src/main.cpp

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ long filter_negative_tag(Instance inst) {
157157
return score;
158158
}
159159

160+
long filter_lucky(Instance inst) {
161+
for (int i = 0; i < 7; i++) {
162+
if (inst.random(RandomType::Lucky_Money) >= 1.0/15) {
163+
return 0;
164+
}
165+
}
166+
return 1;
167+
}
168+
160169
long filter_suas_speedrun(Instance inst) {
161170
// First four cards in shop must include Mr. Bones, Merry Andy, and Luchador
162171
bool bones = false, andy = false, luchador = false;
@@ -190,9 +199,11 @@ long filter_suas_speedrun(Instance inst) {
190199

191200
long filter_blank(Instance inst) { return 0; }
192201

193-
// These won't be permanent filters, just ones I sub in and out while JSON filters aren't ready yet
202+
// These won't be permanent filters, just ones I sub in and out while JSON
203+
// filters aren't ready yet
194204
long filter_test(Instance inst) {
195-
// Four Fingers, Shortcut, and Smeared Joker in first two antes (https://discord.com/channels/1325151824638120007/1326284714125955183)
205+
// Four Fingers, Shortcut, and Smeared Joker in first two antes
206+
// (https://discord.com/channels/1325151824638120007/1326284714125955183)
196207
bool fingers = false;
197208
bool shortcut = false;
198209
bool smeared = false;
@@ -245,7 +256,7 @@ void benchmark() {
245256
std::cout << "------LONGER TESTING------\n";
246257
std::cout << "Total time: " << end - start << "ms\n";
247258
std::cout << "Seeds per second: " << std::fixed << std::setprecision(0)
248-
<< 1000000000 / ((end - start) / 1000.0) << "\n";
259+
<< 1000000000 / ((end - start) / 1000.0) << "\n";
249260
}
250261

251262
void benchmark_quick() {
@@ -260,10 +271,28 @@ void benchmark_quick() {
260271
long end = std::chrono::duration_cast<std::chrono::milliseconds>(
261272
std::chrono::system_clock::now().time_since_epoch())
262273
.count();
263-
std::cout << "----PERKEO OBSERVATORY----\n";
264-
std::cout << "Total time: " << end - start << "ms\n";
265-
std::cout << "Seeds per second: " << std::fixed << std::setprecision(0)
266-
<< 100000000 / ((end - start) / 1000.0) << "\n";
274+
std::cout << "----PERKEO OBSERVATORY----\n";
275+
std::cout << "Total time: " << end - start << "ms\n";
276+
std::cout << "Seeds per second: " << std::fixed << std::setprecision(0)
277+
<< 100000000 / ((end - start) / 1000.0) << "\n";
278+
}
279+
280+
void benchmark_quick_lucky() {
281+
long total = 0;
282+
long start = std::chrono::duration_cast<std::chrono::milliseconds>(
283+
std::chrono::system_clock::now().time_since_epoch())
284+
.count();
285+
Search search(filter_lucky, "IMMOLATE", 12, 100000000);
286+
search.highScore = 10; // No output
287+
search.printDelay = 100000000000;
288+
search.search();
289+
long end = std::chrono::duration_cast<std::chrono::milliseconds>(
290+
std::chrono::system_clock::now().time_since_epoch())
291+
.count();
292+
std::cout << "-------LUCKY CARDS-------\n";
293+
std::cout << "Total time: " << end - start << "ms\n";
294+
std::cout << "Seeds per second: " << std::fixed << std::setprecision(0)
295+
<< 100000000 / ((end - start) / 1000.0) << "\n";
267296
}
268297

269298
void benchmark_single() {
@@ -278,10 +307,10 @@ void benchmark_single() {
278307
long end = std::chrono::duration_cast<std::chrono::milliseconds>(
279308
std::chrono::system_clock::now().time_since_epoch())
280309
.count();
281-
std::cout << "----SINGLE THREADED PO----\n";
282-
std::cout << "Total time: " << end - start << "ms\n";
283-
std::cout << "Seeds per second: " << std::fixed << std::setprecision(0)
284-
<< 10000000 / ((end - start) / 1000.0) << "\n";
310+
std::cout << "----SINGLE THREADED PO----\n";
311+
std::cout << "Total time: " << end - start << "ms\n";
312+
std::cout << "Seeds per second: " << std::fixed << std::setprecision(0)
313+
<< 10000000 / ((end - start) / 1000.0) << "\n";
285314
}
286315

287316
void benchmark_blank() {
@@ -301,14 +330,10 @@ void benchmark_blank() {
301330
<< 100000000 / ((end - start) / 1000.0) << "\n";
302331
}
303332

304-
void run_filter(std::function<int(Instance)> f) {
305-
Search search(f, 12);
306-
search.search();
307-
}
308-
309333
int main() {
310334
benchmark_single();
311335
benchmark_quick();
336+
benchmark_quick_lucky();
312337
benchmark_blank();
313338
benchmark();
314339
return 1;

0 commit comments

Comments
 (0)