-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
121 lines (100 loc) · 3.26 KB
/
main.cpp
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
#include <string>
#include <iostream>
#include <unistd.h>
#include "utils.hh"
#include "map.hh"
#include "renderer.hh"
#include "spin_lattice.hh"
int main(int argc, char* argv[]) {
// Parsing arguments
int N = 0; // number of images to be generated
int L = 0; // lattice size (LxL)
for (int i = 1; i < argc; i++)
{
std::string arg = argv[i];
if (arg == "--num-generated-images" || arg == "-N")
{
if (i + 1 < argc)
{
N = std::stoi(argv[i + 1]);
i++; // Skip the next argument
}
else
{
std::cerr << "Error: --num-generated-images option requires an argument." << std::endl;
return 1;
}
}
else if (arg == "--lattice-size" || arg == "-L")
{
if (i + 1 < argc)
{
L = std::stoi(argv[i + 1]);
i++; // Skip the next argument
}
else
{
std::cerr << "Error: --lattice-size option requires an argument." << std::endl;
return 1;
}
}
else
{
std::cerr << "Error: Unknown argument '" << arg << "'" << std::endl;
return 1;
}
}
if(N==0)
{
std::cerr << "Error: option --num-generated-images is required" << std::endl;
exit(1);
}
if(L==0)
{
std::cerr << "Error: option --lattice-size is required" << std::endl;
exit(1);
}
// Print program name and version
splash_screen();
for(int n = 1; n <= N; n++)
{
// Declare a spin lattice object
SpinLattice lattice(L);
// Annealing procedure
std::cout << std::endl << "Starting annealing procedure for map #" << n << std::endl;
lattice.anneal(100000);
// Remove noisy pixel by "freezing" the lattice
std::cout << std::endl << "Freezing the lattice: " << std::endl;
lattice.freeze();
// declare a map object starting from the sea/terrain pattern
// generated by the Ising Lattice
std::cout << std::endl << "Generating heightmap from spin lattice:" << std::endl;
Map map(lattice);
// generating amenities on map using the heightmap
// Generate a set of rivers
std::cout << std::endl << "Generating rivers . . ." << std::endl;
for (size_t i = 0; i < 20; i++)
{
map.generate_river();
}
std::cout << "Generating mountains . . ." << std::endl;
for (size_t i = 0; i < 150; i++)
{
map.generate_mountain();
}
std::cout << "Generating trees . . ." << std::endl;
for (size_t i = 0; i < 700; i++)
{
map.generate_tree();
}
// Render the map
std::cout << "Rendering the map . . ." << std::endl;
Renderer renderer = Renderer();
std::string filename = "map"+std::to_string(n)+".bmp";
renderer.render(&map, filename);
char buffer[200];
getcwd(buffer, sizeof(buffer));
std::cout << "Map saved into " << buffer << "/" << filename << std::endl;
}
return 0;
}