1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
// Copyright (c) 2013-2020 Vittorio Romeo
// License: Academic Free License ("AFL") v. 3.0
// AFL License page: https://opensource.org/licenses/AFL-3.0
#include "SSVOpenHexagon/Global/Assets.hpp"
#include "SSVOpenHexagon/Global/Config.hpp"
#include "SSVOpenHexagon/Global/Version.hpp"
#include "SSVOpenHexagon/Core/HexagonGame.hpp"
#include "TestUtils.hpp"
#include <random>
#include <stdexcept>
#include <array>
int main()
try
{
constexpr std::array packs{
// "ohvrvanilla_vittorio_romeo_cube_1", //
// "ohvrvanilla_vittorio_romeo_cube_1", //
"ohvrvanilla_vittorio_romeo_cube_1", //
"ohvrvanilla_vittorio_romeo_experimental_1" //
};
constexpr std::array levels{
// "ohvrvanilla_vittorio_romeo_cube_1_pointless", //
// "ohvrvanilla_vittorio_romeo_cube_1_seconddimension", //
"ohvrvanilla_vittorio_romeo_cube_1_apeirogon", //
"ohvrvanilla_vittorio_romeo_experimental_1_autotest0" //
};
hg::Config::loadConfig({});
hg::HGAssets assets{nullptr /* steamManager */, true /* headless */};
hg::ProfileData fakeProfile{hg::GAME_VERSION, "testProfile", {}, {}};
assets.addLocalProfile(std::move(fakeProfile));
assets.pSetCurrent("testProfile");
const auto doTest = [&](int i, bool differentHG, ssvs::GameWindow* gw)
{
hg::HexagonGame hg{
nullptr /* steamManager */, //
nullptr /* discordManager */, //
assets, //
nullptr /* audio */, //
gw, //
nullptr /* client */ //
};
if(getRndBool())
{
hg.executeRandomInputs = true;
}
else
{
hg.alwaysSpinRight = true;
}
hg::replay_file rf;
hg.onReplayCreated = [&](const hg::replay_file& newRf) { rf = newRf; };
hg.newGame(packs[i % packs.size()], levels[i % levels.size()],
true /* firstPlay */, 1.f /* diffMult */,
/* mExecuteLastReplay */ false);
hg.setMustStart(true);
const double score =
hg.executeGameUntilDeath(
1 /* maxProcessingSeconds */, 1.f /* timescale */)
.value()
.playedTimeSeconds;
std::optional<hg::HexagonGame::GameExecutionResult> score2;
if(differentHG)
{
hg::HexagonGame hg2{
nullptr /* steamManager */, //
nullptr /* discordManager */, //
assets, //
nullptr /* audio */, //
nullptr /* window */, //
nullptr /* client */ //
};
score2 = hg2.runReplayUntilDeathAndGetScore(
rf, 1 /* maxProcessingSeconds */, 1.f /* timescale */);
}
else
{
score2 = hg.runReplayUntilDeathAndGetScore(
rf, 1 /* maxProcessingSeconds */, 1.f /* timescale */);
}
TEST_ASSERT(score2.has_value());
const double replayPlayedTimeSeconds = score2.value().playedTimeSeconds;
std::cerr << score << " == " << replayPlayedTimeSeconds << std::endl;
TEST_ASSERT_EQ(score, replayPlayedTimeSeconds);
};
for(int i = 0; i < 25; ++i)
{
doTest(i, false, nullptr);
doTest(i, true, nullptr);
}
#ifndef SSVOH_HEADLESS_TESTS
ssvs::GameWindow gw;
for(int i = 0; i < 25; ++i)
{
doTest(i, false, &gw);
doTest(i, true, &gw);
}
#endif
return 0;
}
catch(const std::runtime_error& e)
{
std::cerr << "EXCEPTION: " << e.what() << std::endl;
}
catch(...)
{
std::cerr << "EXCEPTION: unknown" << std::endl;
}
|