Skip to content

Commit

Permalink
Make Tiled3D::StandardRunner resettable, improve unit test for it
Browse files Browse the repository at this point in the history
  • Loading branch information
heyx3 committed Jun 24, 2022
1 parent 97b307b commit c4bf1b9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
15 changes: 14 additions & 1 deletion WFC++/Tiled3D/StandardRunner.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <span>
#include <tuple>
#include "Grid.h"

namespace WFC::Tiled3D
Expand Down Expand Up @@ -92,13 +93,25 @@ namespace WFC::Tiled3D
//Returns whether the algorithm is finished.
bool TickN(int n);

void Reset()
{
Grid.ClearCells(Region3i(Grid.Cells.GetDimensions()));
report.Clear();
nextCells.Clear();
unsolvableCells.Clear();
}
//TODO: Another overload that takes new 'constants'.


StandardRunner(const List<Tile>& inputTiles, const Vector3i& gridSize,
const Dictionary<Vector3i, std::tuple<TileIdx, Transform3D>>* constants = nullptr,
PRNG rand = PRNG(std::random_device()()))
: Grid(inputTiles, gridSize), Rand(rand),
History(gridSize, { })
{

if (constants != nullptr)
for (const auto& [cellPos, tileData] : *constants)
Set(cellPos, std::get<0>(tileData), std::get<1>(tileData));
}


Expand Down
23 changes: 14 additions & 9 deletions WFCtests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,24 +790,26 @@ SUITE(WFC_Tiled3D)

TEST(StandardRunner)
{
//Use two permutations of a single tile,
// which are compatible along Z but not X or Y,
// ensuring that each Z-level uses all one permutation.
TransformSet usedTransforms;
usedTransforms.Add(Transform3D{ });
usedTransforms.Add(Transform3D{ false, Rotations3D::AxisZ_90 });
StandardRunner state(OneTileArmy(usedTransforms), {4, 5, 6});

//StandardRunner uses <random> to generate numbers.
//Run the test many times to cover a broad range of possible outcomes.
const int N_TESTS =
#ifdef _DEBUG
100000
20000
#else
400000
200000
#endif
;
for (int i = 0; i < N_TESTS; ++i)
{
//Use two permutations of a single tile,
// which are compatible along Z but not X or Y,
// ensuring that each Z-level uses all one permutation.
TransformSet usedTransforms;
usedTransforms.Add(Transform3D{ });
usedTransforms.Add(Transform3D{ false, Rotations3D::AxisZ_90 });
StandardRunner state(OneTileArmy(usedTransforms), {4, 5, 6});
state.Reset();

//Tick once, and check that one cell is set.
bool isFinished = state.Tick();
Expand Down Expand Up @@ -855,12 +857,15 @@ SUITE(WFC_Tiled3D)
setCellPos == originalCellPos.MoreY() ||
setCellPos == originalCellPos.LessZ() ||
setCellPos == originalCellPos.MoreZ());

//TODO: Set a cell that makes the grid unsolvable, then watch it clear.
}
}
}


int main(int, const char* [])
{
std::cout << "Running..." << std::endl;
return UnitTest::RunAllTests();
}

0 comments on commit c4bf1b9

Please sign in to comment.