-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathScenarioLoader.cpp
More file actions
83 lines (73 loc) · 1.77 KB
/
ScenarioLoader.cpp
File metadata and controls
83 lines (73 loc) · 1.77 KB
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
/*
* scenarioLoader.cpp
* hog
*
* Created by Renee Jansen on 5/2/2006
*
*/
#include <fstream>
using std::ifstream;
using std::ofstream;
#include <iomanip>
#include "ScenarioLoader.h"
#include <assert.h>
/**
* Loads the experiments from the scenario file.
*/
ScenarioLoader::ScenarioLoader(const char* fname)
{
strncpy(scenName, fname, 1024);
ifstream sfile(fname,std::ios::in);
float ver;
string first;
sfile>>first;
// Check if a version number is given
if (first != "version"){
ver = 0.0;
sfile.seekg(0,std::ios::beg);
}
else{
sfile>>ver;
}
int sizeX = 0, sizeY = 0;
int bucket;
string map;
int xs, ys, xg, yg;
double dist;
// Read in & store experiments
if (ver==0.0){
while(sfile>>bucket>>map>>xs>>ys>>xg>>yg>>dist) {
Experiment exp(xs,ys,xg,yg,bucket,dist,map);
experiments.push_back(exp);
}
}
else if (ver==1.0){
while(sfile>>bucket>>map>>sizeX>>sizeY>>xs>>ys>>xg>>yg>>dist){
Experiment exp(xs,ys,xg,yg,sizeX,sizeY,bucket,dist,map);
experiments.push_back(exp);
}
}
else{
printf("Invalid version number.\n");
//assert(0);
}
}
void ScenarioLoader::Save(const char *fname)
{
// strncpy(scenName, fname, 1024);
ofstream ofile(fname);
float ver = 1.0;
ofile<<"version "<<ver<<std::endl;
ofile << std::setprecision(8);
ofile << std::fixed;
for (unsigned int x = 0; x < experiments.size(); x++)
{
ofile<<experiments[x].bucket<<"\t"<<experiments[x].map<<"\t"<<experiments[x].scaleX<<"\t";
ofile<<experiments[x].scaleY<<"\t"<<experiments[x].startx<<"\t"<<experiments[x].starty<<"\t";
ofile<<experiments[x].goalx<<"\t"<<experiments[x].goaly<<"\t"<<experiments[x].distance<<std::endl;
}
}
void ScenarioLoader::AddExperiment(Experiment which)
{
experiments.push_back(which);
}