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-20 03:05:34 +02:00
|
|
|
const std::vector<double> patterns_frequencies;
|
|
|
|
|
|
|
|
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.
|
|
|
|
Array2D<unsigned> 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-20 03:05:34 +02:00
|
|
|
WFC(bool periodic_output, int seed, std::vector<double> patterns_frequencies,
|
|
|
|
Propagator::PropagatorState propagator, unsigned wave_height,
|
2022-04-20 03:24:50 +02:00
|
|
|
unsigned 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 14:28:04 +02:00
|
|
|
Array2D<unsigned> 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).
|
|
|
|
void remove_wave_pattern(unsigned i, unsigned j, unsigned 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_
|