Skip to content
Permalink
Browse files

Game can be one with the right RNG seed

  • Loading branch information...
richelbilderbeek committed Aug 9, 2019
1 parent 804aa8a commit c3ed513b3d53c8438c7660b35f49a11233e7302b
@@ -110,7 +110,7 @@ void Helper::CreateGraph() const
}
else if (!chapter.GetOptions().GetOptions().empty())
{
for (const auto option: chapter.GetOptions().GetOptions())
for (const auto& option: chapter.GetOptions().GetOptions())
{
f << i << "->" << option.GetNextChapter() << " [ label = \"Choice\"];\n";
}
@@ -129,11 +129,11 @@ void Helper::CreateGraph() const
f << i << "-> GameWon;\n";
}
}
catch (std::logic_error& e)
catch (const std::logic_error& )
{
//f << i << ": FAIL" << std::endl;
}
catch (std::runtime_error& e)
catch (const std::runtime_error&)
{
//f << i << ": not present" << std::endl;
}
@@ -15,60 +15,50 @@
#include "helper.h"
#include "chapter.h"
#include "walkthrough.h"


// Boost.Test does not play well with -Weffc++
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_CASE(test_game)
BOOST_AUTO_TEST_CASE(test_game_helper)
{
const bool verbose{false};
if (verbose) { std::clog << __func__ << std::endl; }
Helper();
}

{
Helper();
}
BOOST_AUTO_TEST_CASE(test_game_create_chapter)
{
Chapter(1);
}

BOOST_AUTO_TEST_CASE(test_game_has_repeatable_rng)
{
const int seed{123456};
Dice::Get()->SetSeed(seed);

if (verbose) { std::clog << "Create a chapter" << std::endl; }
{
Chapter(1);
}
if (verbose) { std::clog << "Test if game runs identically twice with same RNG seed" << std::endl; }
{
const int seed{123456};
Dice::Get()->SetSeed(seed);
Character character1(
Dice::Get()->Throw(),
Dice::Get()->Throw() + Dice::Get()->Throw(),
Dice::Get()->Throw(),
Item::luck_potion
);

Character character1(
Dice::Get()->Throw(),
Dice::Get()->Throw() + Dice::Get()->Throw(),
Dice::Get()->Throw(),
Item::luck_potion
);
const Game game1(seed,character1);

const Game game1(seed,character1);
Dice::Get()->SetSeed(seed);

Dice::Get()->SetSeed(seed);
Character character2(
Dice::Get()->Throw(),
Dice::Get()->Throw() + Dice::Get()->Throw(),
Dice::Get()->Throw(),
Item::luck_potion
);

Character character2(
Dice::Get()->Throw(),
Dice::Get()->Throw() + Dice::Get()->Throw(),
Dice::Get()->Throw(),
Item::luck_potion
);
const Game game2(seed,character2);
BOOST_CHECK(character1.GetChapters() == character2.GetChapters());
}

const Game game2(seed,character2);
assert(character1.GetChapters() == character2.GetChapters());
}
if (verbose) { std::clog << "Can the game be won?" << std::endl; }
{
const int seed{0};
//Use a maxed-out character
const Character character(6,12,12,Item::luck_potion);
Walkthrough walkthrough(seed,character);
walkthrough.Start();
}
BOOST_AUTO_TEST_CASE(test_game_win)
{
const int seed{2};
//Use a maxed-out character
const Character character(6,12,12,Item::luck_potion);
Walkthrough walkthrough(seed,character);
walkthrough.Start();
}
#pragma GCC diagnostic pop
@@ -0,0 +1 @@
*.pro.user
@@ -4,10 +4,6 @@ include(../Files/Files.pri)

SOURCES += main.cpp

# C++17
CONFIG += c++17
QMAKE_CXXFLAGS += -std=c++17

# High warning levels
# Qt does not go well with -Weffc++
QMAKE_CXXFLAGS += -Wall -Wextra -Wshadow -Wnon-virtual-dtor -pedantic -Werror
@@ -1 +1,2 @@
*_plugin_import.cpp
*.pro.user
@@ -4,10 +4,6 @@ include(../Classes/CityOfThievesConsole.pri)
include(../Files/Files.pri)
include(../QtClasses/CityOfThievesDesktop.pri)

# C++17
CONFIG += c++17
QMAKE_CXXFLAGS += -std=c++17

# High warning levels
# Qt does not go well with -Weffc++
QMAKE_CXXFLAGS += -Wall -Wextra -Wshadow -Wnon-virtual-dtor -pedantic -Werror

0 comments on commit c3ed513

Please sign in to comment.
You can’t perform that action at this time.