Skip to content

Commit e58f7b6

Browse files
Added VS build for drop sim; additional combine-simulations improvements.
1 parent f780fad commit e58f7b6

6 files changed

Lines changed: 153 additions & 9 deletions

File tree

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ tbl/
33
.vscode/launch.json
44
a.out
55
dropsim
6+
dropsim.exe
7+
dropsim.pdb
68
*.txt
79
!atomic.txt
8-
!atomicbase.txt
10+
!atomicbase.txt
11+
*.user
12+
.vs
13+
obj

.npmignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,10 @@
2222
/json/base/precalctc/.gitkeep
2323
dropsim.cpp
2424
dropsim
25+
dropsim.pdb
26+
dropsim.exe
2527
a.out
2628
*.txt
29+
*.user
30+
.vs
31+
obj

combine-simulations.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@ fs.readdir(__dirname + '/simulations/', (err, files) => {
2828
picks: 0,
2929
avgpicks: 0,
3030
playermod: data.playermod,
31+
elapsed: data.elapsed,
32+
simrate: Math.round(data.runs * 1000000 / data.elapsed) / 1000,
3133
drops: {},
3234
};
3335

3436
let total = totals[tc];
3537

3638
total.runs += data.runs;
3739
total.picks += data.picks;
40+
total.elapsed = Math.max(total.elapsed, data.elapsed);
3841
total.avgpicks = total.picks / total.runs;
42+
total.simrate = Math.round(total.runs * 1000000 / total.elapsed) / 1000;
3943

4044
Object.keys(data.drops).forEach(key => {
4145
if (!total.drops[key]) {

dropsim.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
/**
2-
* Written for linux g++ and c++17 std lib.
3-
*
4-
* You probably can compile this with other compilers on other platforms, but I haven't tested it.
2+
* Cross-platform C++17 drop simulator.
3+
*
4+
* Compiles with:
5+
* - Linux: g++ dropsim.cpp -o dropsim -std=c++17 -pthread
6+
* - Windows: Visual Studio 2017+ (C++17 support required)
57
*/
68

9+
// Disable MSVC security warnings for fopen, strcspn, etc.
10+
#ifdef _MSC_VER
11+
#define _CRT_SECURE_NO_WARNINGS
12+
#endif
13+
714
#include <unordered_map>
815
#include <iostream>
916
#include <cstdio>
@@ -54,8 +61,8 @@ std::mt19937 gen(rd());
5461
// Helper function to split string by tab delimiter, keeping empty strings between tabs
5562
std::vector<std::string> splitByChar(const std::string& str, char delimiter) {
5663
std::vector<std::string> tokens;
57-
long start = 0;
58-
long end = str.find(delimiter);
64+
size_t start = 0;
65+
size_t end = str.find(delimiter);
5966

6067
while (end != std::string::npos) {
6168
tokens.push_back(str.substr(start, end - start));
@@ -170,7 +177,7 @@ void pick(std::string tcname, std::vector<std::string> &drops) {
170177
}
171178

172179
std::string realpath(std::string path) {
173-
return std::filesystem::canonical(std::filesystem::absolute(path));
180+
return std::filesystem::canonical(std::filesystem::absolute(path)).string();
174181
}
175182

176183
// Main takes first parameter as treasure class name
@@ -191,7 +198,7 @@ int main(int argc, char* argv[]) {
191198
path = realpath(path) + "/";
192199

193200
std::string tcname = argv[1];
194-
int dropcycles = 5000;
201+
int dropcycles = 25000;
195202

196203
if (argc >= 3) {
197204
playermod = atoi(argv[2]);
@@ -348,6 +355,8 @@ int main(int argc, char* argv[]) {
348355
long picks = 0;
349356
std::unordered_map<std::string, long> drops;
350357

358+
auto startTime = std::chrono::steady_clock::now();
359+
351360
while (true) {
352361
for (int j = 0; j < dropcycles; j++) {
353362
std::vector<std::string> rundrops;
@@ -361,6 +370,9 @@ int main(int argc, char* argv[]) {
361370
runs++;
362371
}
363372

373+
auto elapsed = std::chrono::steady_clock::now() - startTime;
374+
auto elapsedMilliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count();
375+
364376
// Write results to file as json with name: results-{timestamp}_{i}.json
365377
std::string filename = path + "simulations/" + tcname + " [" + std::to_string(playermod) + "][" + std::to_string(i) + "].json";
366378
std::ofstream out(filename);
@@ -371,12 +383,13 @@ int main(int argc, char* argv[]) {
371383
out << " \"picks\": " << picks << ",\n";
372384
out << " \"playermod\": " << playermod << ",\n";
373385
out << " \"avgpicks\": " << std::fixed << std::setprecision(6) << (double)picks / runs << ",\n";
386+
out << " \"elapsed\": " << elapsedMilliseconds << ",\n";
374387
out << " \"drops\": {\n";
375388
long count = 0;
376389
for (const auto& drop : drops) {
377390
std::string escapedDrop = drop.first;
378391
// Escape backslashes and double quotes in the drop name
379-
long pos = 0;
392+
size_t pos = 0;
380393
while ((pos = escapedDrop.find('\\', pos)) != std::string::npos) {
381394
escapedDrop.insert(pos, "\\");
382395
pos += 2; // Move past the escaped backslash

dropsim.sln

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.0.31903.59
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dropsim", "dropsim.vcxproj", "{A5B8C7D6-E9F1-4A2B-8C3D-4E5F6A7B8C9D}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|x64 = Debug|x64
10+
Release|x64 = Release|x64
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{A5B8C7D6-E9F1-4A2B-8C3D-4E5F6A7B8C9D}.Debug|x64.ActiveCfg = Debug|x64
14+
{A5B8C7D6-E9F1-4A2B-8C3D-4E5F6A7B8C9D}.Debug|x64.Build.0 = Debug|x64
15+
{A5B8C7D6-E9F1-4A2B-8C3D-4E5F6A7B8C9D}.Release|x64.ActiveCfg = Release|x64
16+
{A5B8C7D6-E9F1-4A2B-8C3D-4E5F6A7B8C9D}.Release|x64.Build.0 = Release|x64
17+
EndGlobalSection
18+
GlobalSection(SolutionProperties) = preSolution
19+
HideSolutionNode = FALSE
20+
EndGlobalSection
21+
EndGlobal

dropsim.vcxproj

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|x64">
5+
<Configuration>Debug</Configuration>
6+
<Platform>x64</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|x64">
9+
<Configuration>Release</Configuration>
10+
<Platform>x64</Platform>
11+
</ProjectConfiguration>
12+
</ItemGroup>
13+
<PropertyGroup Label="Globals">
14+
<VCProjectVersion>17.0</VCProjectVersion>
15+
<ProjectGuid>{A5B8C7D6-E9F1-4A2B-8C3D-4E5F6A7B8C9D}</ProjectGuid>
16+
<Keyword>Win32Proj</Keyword>
17+
<RootNamespace>dropsim</RootNamespace>
18+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
19+
</PropertyGroup>
20+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
21+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
22+
<ConfigurationType>Application</ConfigurationType>
23+
<UseDebugLibraries>true</UseDebugLibraries>
24+
<PlatformToolset>v143</PlatformToolset>
25+
<CharacterSet>Unicode</CharacterSet>
26+
</PropertyGroup>
27+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
28+
<ConfigurationType>Application</ConfigurationType>
29+
<UseDebugLibraries>false</UseDebugLibraries>
30+
<PlatformToolset>v143</PlatformToolset>
31+
<WholeProgramOptimization>true</WholeProgramOptimization>
32+
<CharacterSet>Unicode</CharacterSet>
33+
</PropertyGroup>
34+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
35+
<ImportGroup Label="ExtensionSettings">
36+
</ImportGroup>
37+
<ImportGroup Label="Shared">
38+
</ImportGroup>
39+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
40+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
41+
</ImportGroup>
42+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
43+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
44+
</ImportGroup>
45+
<PropertyGroup Label="UserMacros" />
46+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
47+
<LinkIncremental>true</LinkIncremental>
48+
<OutDir>$(ProjectDir)</OutDir>
49+
<IntDir>$(ProjectDir)obj\$(Configuration)\</IntDir>
50+
<TargetName>dropsim</TargetName>
51+
</PropertyGroup>
52+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
53+
<LinkIncremental>false</LinkIncremental>
54+
<OutDir>$(ProjectDir)</OutDir>
55+
<IntDir>$(ProjectDir)obj\$(Configuration)\</IntDir>
56+
<TargetName>dropsim</TargetName>
57+
</PropertyGroup>
58+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
59+
<ClCompile>
60+
<WarningLevel>Level3</WarningLevel>
61+
<SDLCheck>true</SDLCheck>
62+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
63+
<ConformanceMode>true</ConformanceMode>
64+
<LanguageStandard>stdcpp17</LanguageStandard>
65+
<MultiProcessorCompilation>true</MultiProcessorCompilation>
66+
</ClCompile>
67+
<Link>
68+
<SubSystem>Console</SubSystem>
69+
<GenerateDebugInformation>true</GenerateDebugInformation>
70+
</Link>
71+
</ItemDefinitionGroup>
72+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
73+
<ClCompile>
74+
<WarningLevel>Level3</WarningLevel>
75+
<FunctionLevelLinking>true</FunctionLevelLinking>
76+
<IntrinsicFunctions>true</IntrinsicFunctions>
77+
<SDLCheck>true</SDLCheck>
78+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
79+
<ConformanceMode>true</ConformanceMode>
80+
<LanguageStandard>stdcpp17</LanguageStandard>
81+
<MultiProcessorCompilation>true</MultiProcessorCompilation>
82+
</ClCompile>
83+
<Link>
84+
<SubSystem>Console</SubSystem>
85+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
86+
<OptimizeReferences>true</OptimizeReferences>
87+
<GenerateDebugInformation>true</GenerateDebugInformation>
88+
</Link>
89+
</ItemDefinitionGroup>
90+
<ItemGroup>
91+
<ClCompile Include="dropsim.cpp" />
92+
</ItemGroup>
93+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
94+
<ImportGroup Label="ExtensionTargets">
95+
</ImportGroup>
96+
</Project>

0 commit comments

Comments
 (0)