HOG2
ScenarioLoader.cpp
Go to the documentation of this file.
1 /*
2  * scenarioLoader.cpp
3  * hog
4  *
5  * Created by Renee Jansen on 5/2/2006
6  *
7  */
8 
9 #include <fstream>
10 using std::ifstream;
11 using std::ofstream;
12 #include <iomanip>
13 #include "ScenarioLoader.h"
14 #include <assert.h>
15 
20 {
21  strncpy(scenName, fname, 1024);
22  ifstream sfile(fname,std::ios::in);
23 
24  float ver;
25  string first;
26  sfile>>first;
27 
28  // Check if a version number is given
29  if (first != "version"){
30  ver = 0.0;
31  sfile.seekg(0,std::ios::beg);
32  }
33  else{
34  sfile>>ver;
35  }
36 
37  int sizeX = 0, sizeY = 0;
38  int bucket;
39  string map;
40  int xs, ys, xg, yg;
41  double dist;
42 
43  // Read in & store experiments
44  if (ver==0.0){
45  while(sfile>>bucket>>map>>xs>>ys>>xg>>yg>>dist) {
46  Experiment exp(xs,ys,xg,yg,bucket,dist,map);
47  experiments.push_back(exp);
48  }
49  }
50  else if (ver==1.0){
51  while(sfile>>bucket>>map>>sizeX>>sizeY>>xs>>ys>>xg>>yg>>dist){
52  Experiment exp(xs,ys,xg,yg,sizeX,sizeY,bucket,dist,map);
53  experiments.push_back(exp);
54  }
55  }
56  else{
57  printf("Invalid version number.\n");
58  //assert(0);
59  }
60 }
61 
62 void ScenarioLoader::Save(const char *fname)
63 {
64 // strncpy(scenName, fname, 1024);
65  ofstream ofile(fname);
66 
67  float ver = 1.0;
68  ofile<<"version "<<ver<<std::endl;
69  ofile << std::setprecision(8);
70  ofile << std::fixed;
71  for (unsigned int x = 0; x < experiments.size(); x++)
72  {
73  ofile<<experiments[x].bucket<<"\t"<<experiments[x].map<<"\t"<<experiments[x].scaleX<<"\t";
74  ofile<<experiments[x].scaleY<<"\t"<<experiments[x].startx<<"\t"<<experiments[x].starty<<"\t";
75  ofile<<experiments[x].goalx<<"\t"<<experiments[x].goaly<<"\t"<<experiments[x].distance<<std::endl;
76  }
77 }
78 
80 {
81  experiments.push_back(which);
82 }
83 
ScenarioLoader::Save
void Save(const char *)
Definition: ScenarioLoader.cpp:62
ScenarioLoader::AddExperiment
void AddExperiment(Experiment which)
Definition: ScenarioLoader.cpp:79
ScenarioLoader::ScenarioLoader
ScenarioLoader()
Definition: ScenarioLoader.h:57
Experiment
Definition: ScenarioLoader.h:24
ScenarioLoader::scenName
char scenName[1024]
Definition: ScenarioLoader.h:66
ScenarioLoader::experiments
std::vector< Experiment > experiments
Definition: ScenarioLoader.h:67
ScenarioLoader.h