10 using namespace __gnu_cxx;
13 Bot::Bot(const string& name, PlayerType type){
17 _playerTypeNames[robber] = "robber";
18 _playerTypeNames[cop_foot] = "cop-foot";
19 _playerTypeNames[cop_car] = "cop-car";
21 _playerTypes["robber"] = robber;
22 _playerTypes["cop-foot"] = cop_foot;
23 _playerTypes["cop-car"] = cop_car;
25 priority_queue<vector<string>, vector<vector<string> >, VectComp> pq;
35 v.push_back("hej hå");
38 v.push_back("hejsan");
45 cerr << "Size: " << pq.top().size() << " " << pq.top()[0] << endl;
47 cerr << "Size: " << pq.top().size() << " " << pq.top()[0] << endl;
49 cerr << "Size: " << pq.top().size() << " " << pq.top()[0] << endl;
51 cerr << "Size: " << pq.top().size() << " " << pq.top()[0] << endl;
53 cerr << "Size: " << pq.top().size() << " " << pq.top()[0] << endl;
55 cerr << "Size: " << pq.top().size() << " " << pq.top()[0] << endl;
63 cout << "reg: " << _name << " " << _playerTypeNames[_type] << endl;
70 _name = value<string>(input);
71 cerr << "Got name: " << _name << endl;
75 _players[value<string>(input)];
77 _players[value<string>(input)];
79 _players[value<string>(input)];
81 _players[value<string>(input)];
83 _players[value<string>(input)];
85 cerr << "Got players, building graph." << endl;
92 if (input == "game-over")
95 _type = _players[_name].type;
96 _location = _players[_name].location;
98 cerr << "New turn" << endl;
100 cerr << "Done with turn." << endl;
109 ( nod: loc node-tag coordinate coordinate eol )*
112 ( edg: loc loc edge-type eol )*
115 void Bot::buildGraph(){
118 if (input != "nod\\")
121 cerr << "Getting intersections" << endl;
126 istringstream node(input);
129 Intersection& inter = _intersections[input];
135 cerr << "Number of intersections: " << _intersections.size() << endl;
138 if (input != "edg\\")
141 cerr << "Getting streets" << endl;
148 istringstream street(input);
156 //cerr << "Street between: " << from << " and " << to << " of type: " << type << endl;
158 _intersections[from].connections[to] = both;
159 Intersection& inter = _intersections[to];
160 if (inter.connections.find(from) == inter.connections.end())
161 inter.connections[from] = foot;
163 _intersections[from].connections[to] = car;
165 cerr << "Number of streets: " << streets << endl;
168 void Bot::updateWorld(){
171 _world = value<int>(input);
172 //cerr << "World: " << _world << endl;
175 _robbed = value<int>(input);
176 //cerr << "Robbed: " << _robbed << endl;
183 istringstream bank(input);
186 bank >> _banks[input];
188 //cerr << "Number of banks: " << _banks.size() << endl;
195 istringstream evidence(input);
199 _smell = value<int>(input);
206 istringstream player(input);
209 //cerr << "Player: " << input << endl;
210 Player& pl = _players[input];
211 player >> pl.location;
213 pl.type = _playerTypes[input];
215 //cerr << "Number of players: " << _players.size() << endl;
218 void Bot::move(std::string location){
219 cerr << "Moving to: " << location << endl;
220 cout << "mov: " << location << " " << _playerTypeNames[_type] << endl;
224 T value(std::string input){
225 istringstream istr(input);
232 std::string Bot::turn(){
233 cerr << "Using stupid stand still Bot::turn" << endl;
245 bool operator()(const SPInfo* v1, const SPInfo* v2){
246 return v1->cost > v2->cost;
250 std::list<std::string> Bot::shortestPath(const std::string& from, const std::string& to, PlayerType type){
252 priority_queue<SPInfo*, vector<SPInfo* >, SPInfoComp > pq;
253 hash_map<string,SPInfo> nodes;
255 SPInfo* node = &nodes[from];
257 node->settled = false;
265 //cerr << "Vector with size: " << w.size() << endl;
266 //cerr << "Looking at: " << w.back() << endl;
267 //copy(w.begin(), w.end(), ostream_iterator<string>(cerr, " : "));
268 if (node->name == to){
270 front_insert_iterator<list<string> > ii(l);
277 node->settled = true;
279 Intersection& inter = _intersections[node->name];
280 for (hash_map<string,StreetType>::const_iterator street = inter.connections.begin();
281 street != inter.connections.end(); ++street){
282 hash_map<string,SPInfo>::iterator newNode = nodes.find(street->first);
283 bool hascar = type == cop_car;
284 if ( (hascar && (street->second == car || street->second == both)) ||
285 (!hascar && (street->second == foot || street->second == both))){
287 if (newNode == nodes.end()){
288 n = &nodes[street->first];
289 n->name = street->first;
293 }else if (newNode->second.settled)
296 n = &newNode->second;
298 if (n->cost > node->cost + 1){
299 n->cost = node->cost + 1;
309 return list<string>();