2022-04-20 03:05:34 +02:00
|
|
|
#ifndef FAST_WFC_WFC_HPP_
|
|
|
|
#define FAST_WFC_WFC_HPP_
|
|
|
|
|
|
|
|
#include <optional>
|
|
|
|
#include <random>
|
|
|
|
|
|
|
|
#include "array_2d.h"
|
2022-04-20 03:24:50 +02:00
|
|
|
#include "propagator.h"
|
2022-04-20 03:05:34 +02:00
|
|
|
#include "wave.h"
|
|
|
|
|
2022-04-20 03:24:50 +02:00
|
|
|
// Class containing the generic WFC algorithm.
|
2022-04-20 03:05:34 +02:00
|
|
|
class WFC {
|
|
|
|
private:
|
2022-04-20 03:24:50 +02:00
|
|
|
// The random number generator.
|
2022-04-20 03:05:34 +02:00
|
|
|
std::minstd_rand gen;
|
|
|
|
|
2022-04-20 03:24:50 +02:00
|
|
|
// The distribution of the patterns as given in input.
|
2022-04-21 16:31:03 +02:00
|
|
|
const Vector<double> patterns_frequencies;
|
2022-04-20 03:05:34 +02:00
|
|
|
|
|
|
|
Wave wave;
|
|
|
|
|
2022-04-20 03:24:50 +02:00
|
|
|
// The number of distinct patterns.
|
2022-04-20 03:05:34 +02:00
|
|
|
const size_t nb_patterns;
|
|
|
|
|
2022-04-20 03:24:50 +02:00
|
|
|
// The propagator, used to propagate the information in the wave.
|
2022-04-20 03:05:34 +02:00
|
|
|
Propagator propagator;
|
|
|
|
|
2022-04-20 03:24:50 +02:00
|
|
|
// Transform the wave to a valid output (a 2d array of patterns that aren't in
|
|
|
|
// contradiction). This function should be used only when all cell of the wave
|
|
|
|
// are defined.
|
2022-04-21 16:43:04 +02:00
|
|
|
Array2D<uint32_t> wave_to_output() const;
|
2022-04-20 03:05:34 +02:00
|
|
|
|
|
|
|
public:
|
2022-04-20 03:24:50 +02:00
|
|
|
// Basic constructor initializing the algorithm.
|
2022-04-21 16:31:03 +02:00
|
|
|
WFC(bool periodic_output, int seed, Vector<double> patterns_frequencies,
|
2022-04-21 16:43:04 +02:00
|
|
|
Propagator::PropagatorState propagator, uint32_t wave_height,
|
|
|
|
uint32_t wave_width);
|
2022-04-20 03:05:34 +02:00
|
|
|
|
2022-04-20 03:24:50 +02:00
|
|
|
// Run the algorithm, and return a result if it succeeded.
|
2022-04-21 16:43:04 +02:00
|
|
|
Array2D<uint32_t> run();
|
2022-04-20 03:05:34 +02:00
|
|
|
|
2022-04-20 03:24:50 +02:00
|
|
|
// Return value of observe.
|
2022-04-20 03:05:34 +02:00
|
|
|
enum ObserveStatus {
|
|
|
|
success, // WFC has finished and has succeeded.
|
|
|
|
failure, // WFC has finished and failed.
|
|
|
|
to_continue // WFC isn't finished.
|
|
|
|
};
|
|
|
|
|
2022-04-20 03:24:50 +02:00
|
|
|
// Define the value of the cell with lowest entropy.
|
|
|
|
ObserveStatus observe();
|
2022-04-20 03:05:34 +02:00
|
|
|
|
2022-04-20 03:24:50 +02:00
|
|
|
// Propagate the information of the wave.
|
|
|
|
void propagate() { propagator.propagate(wave); }
|
2022-04-20 03:05:34 +02:00
|
|
|
|
2022-04-20 03:24:50 +02:00
|
|
|
// Remove pattern from cell (i,j).
|
2022-04-21 16:43:04 +02:00
|
|
|
void remove_wave_pattern(uint32_t i, uint32_t j, uint32_t pattern) {
|
2022-04-20 03:05:34 +02:00
|
|
|
if (wave.get(i, j, pattern)) {
|
|
|
|
wave.set(i, j, pattern, false);
|
|
|
|
propagator.add_to_propagator(i, j, pattern);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // FAST_WFC_WFC_HPP_
|