-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgarden.h
192 lines (169 loc) · 4.09 KB
/
garden.h
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#ifndef GARDEN_FOR_ALGERNON
#define GARDEN_FOR_ALGERNON 0
#include <iostream>
#include <fstream>
#include <string>
#include "graphalterations.h"
#define garden_debug true
class Garden
{
private:
std::fstream seed_source;
std::ofstream seed_storage;
int seeds_processed;
AlterationLib alter_lib;
std::string current_seed;
public:
Garden();
bool OpenSeedPack(std::string path);
bool OpenSeedStorage(std::string path);
bool LoadNextSeed();
bool PlantSeed(std::string folder);
//bool PlantSprout(std::string folder);
int GetSeedsProcessed();
};
Garden::Garden()
{
current_seed = "";
seeds_processed = 0;
}
bool Garden::OpenSeedPack(std::string path)
{
seed_source.open(path.c_str());
if(!seed_source)
{
if(garden_debug)
{
std::cout << "-ERROR-\nFILE: garden.h\nFUNCTION: bool Garden::OpenSeedPack(std::string path)\nMESSAGE: file not found or corrupt\n";
}
return false;
}
seed_source >> current_seed;
if(!seed_source)
{
if(garden_debug)
{
std::cout << "-ERROR-\nFILE: garden.h\nFUNCTION: bool Garden::OpenSeedPack(std::string path)\nMESSAGE: file empty or corrupt\n";
}
return false;
}
return true;
}
bool Garden::OpenSeedStorage(std::string path)
{
seed_storage.open(path.c_str());
if(!seed_source)
{
if(garden_debug)
{
std::cout << "-ERROR-\nFILE: garden.h\nFUNCTION: bool Garden::OpenSeedStorage(std::string path)\nMESSAGE: file could not be created\n";
}
return false;
}
return true;
}
bool Garden::LoadNextSeed()
{
seed_source >> current_seed;
if(!seed_source)
{
if(garden_debug)
{
std::cout << "-ERROR-\nFILE: garden.h\nFUNCTION: bool Garden::LoadNextSeed()\nMESSAGE: no more seeds\n";
}
return false;
}
return true;
}
bool Garden::PlantSeed(std::string folder)
{
bool do_alter = true;
long long unsigned int args[4];
int alteration_count = alter_lib.GetListSize(); //get size of alteration library
int alteration_index = 0; //current alteration to use
std::fstream file;
std::string seed_profile = folder;
std::string file_name;
std::string new_seed = current_seed; //change default value to "" ?
std::string tmpStr;
seed_profile += current_seed + ".txt"; //a profile that indicates if seed was processed
file.open(seed_profile.c_str(),std::ios::in);
if(file)
{
if(garden_debug)
{
std::cout << "-ERROR-\nFILE: garden.h\nFUNCTION: bool Garden::PlantSeed(str::string folder)\nMESSAGE: sprout exists\n";
}
return false;
}
file.close();
file.clear();
folder += current_seed + "\\"; //folder for sprouts
tmpStr = "mkdir \"" + folder + "\"";
system(tmpStr.c_str());
while(alteration_index < alteration_count)
{
file_name = folder + alter_lib.GetAlterationName(alteration_index) + ".txt";
file.open(file_name.c_str(),std::ios::out);
args[0] = 1;
args[1] = 1;
args[2] = 1;
args[3] = 1;
while(do_alter)
{
if(garden_debug)
{
std::cout << alter_lib.GetAlterationName(alteration_index)
<<" with " << args[0] << " " << args[1] << " " << args[2] << " " << args[3] << '\n'
<<'\t'<<"seed: " << current_seed << '\n';
}
new_seed = alter_lib.DoAlteration(alteration_index,current_seed,args[0],args[1],args[2],args[3]);
if(garden_debug)
{
std::cout << "result: " << new_seed << '\n';
}
if(new_seed == current_seed) //alteration ineffective
{
if(args[0]!= 1)
{
args[0]=1;
args[1]++;
}
else if(args[1]!=1)
{
args[1]=1;
args[2]++;
}
else if(args[2]!=1)
{
args[2]=1;
args[3]++;
}
else
{
do_alter = false;
}
}
else
{
file << args[0] << " " << args[1] << " " << args[2] << " " << args[3] << " " <<new_seed << std::endl;
args[0]++;
}
}
alteration_index++;
file.close();
do_alter = true;
}
file.open(seed_profile.c_str(), std::ios::out);
file.close();
return true;
}
int Garden::GetSeedsProcessed()
{
return seeds_processed;
}
#endif
/*
NOTES TO SELF:
-maybe create error message handling class or struct
*/