-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScenarioLoader.cc
72 lines (62 loc) · 1.78 KB
/
ScenarioLoader.cc
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
/* -*- Mode: C++; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* scenarioLoader.cpp
* hog
*
* Created by Renee Jansen on 5/2/2006
* Cleaned up by Marzo Sette Torres Junior <[email protected]>
*
*/
#include <fstream>
using std::ifstream;
using std::ofstream;
#include "ScenarioLoader.h"
#include <assert.h>
/**
* Loads the experiments from the scenario file.
*/
ScenarioLoader::ScenarioLoader(char const *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(char const *fname) const {
// strncpy(scenName, fname, 1024);
ofstream ofile(fname);
float ver = 1.0;
ofile << "version " << ver << std::endl;
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;
}
}