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;
106 ( nod: loc node-tag coordinate coordinate eol )*
109 ( edg: loc loc edge-type eol )*
112 void Bot::buildGraph(){
115 if (input != "nod\\")
118 cerr << "Getting intersections" << endl;
123 istringstream node(input);
126 Intersection& inter = _intersections[input];
130 else if (input == "hq")
132 else if (input == "robber-start")
133 inter.type = robber_start;
135 inter.type = ordinary;
140 cerr << "Number of intersections: " << _intersections.size() << endl;
143 if (input != "edg\\")
146 cerr << "Getting streets" << endl;
153 istringstream street(input);
161 //cerr << "Street between: " << from << " and " << to << " of type: " << type << endl;
163 _intersections[from].connections[to] = both;
164 Intersection& inter = _intersections[to];
165 if (inter.connections.find(from) == inter.connections.end())
166 inter.connections[from] = foot;
168 _intersections[from].connections[to] = car;
170 cerr << "Number of streets: " << streets << endl;
173 void Bot::updateWorld(){
176 _world = value<int>(input);
177 //cerr << "World: " << _world << endl;
180 _robbed = value<int>(input);
181 //cerr << "Robbed: " << _robbed << endl;
188 istringstream bank(input);
191 bank >> _banks[input];
193 //cerr << "Number of banks: " << _banks.size() << endl;
200 istringstream evidence(input);
204 _smell = value<int>(input);
211 istringstream player(input);
214 //cerr << "Player: " << input << endl;
215 Player& pl = _players[input];
216 player >> pl.location;
218 pl.type = _playerTypes[input];
220 //cerr << "Number of players: " << _players.size() << endl;
223 void Bot::move(std::string location){
224 cerr << "Moving to: " << location << endl;
225 cout << "mov: " << location << " " << _playerTypeNames[_type] << endl;
229 T value(std::string input){
230 istringstream istr(input);
237 std::string Bot::turn(){
238 cerr << "Using stupid stand still Bot::turn" << endl;
243 bool operator()(const SPInfo* v1, const SPInfo* v2){
244 return v1->cost > v2->cost;
248 std::list<std::string> Bot::shortestPath(const std::string& from, PlayerType type, const SPGoal& goal){
250 //cerr << "New shortest path from: " << from << endl;
252 priority_queue<SPInfo*, vector<SPInfo* >, SPInfoComp > pq;
253 hash_map<string,SPInfo> nodes;
255 SPInfo* node = &nodes[from];
257 node->settled = false;
266 //cerr << "Vector with size: " << w.size() << endl;
267 //cerr << "Looking at: " << node->name << endl;
268 //copy(w.begin(), w.end(), ostream_iterator<string>(cerr, " : "));
275 front_insert_iterator<list<string> > ii(l);
282 node->settled = true;
284 Intersection& inter = _intersections[node->name];
285 for (hash_map<string,StreetType>::const_iterator street = inter.connections.begin();
286 street != inter.connections.end(); ++street){
287 hash_map<string,SPInfo>::iterator newNode = nodes.find(street->first);
288 bool hascar = type == cop_car;
289 if ( (hascar && (street->second == car || street->second == both)) ||
290 (!hascar && (street->second == foot || street->second == both))){
291 //cerr << "Adding street: " << street->first << endl;
293 if (newNode == nodes.end()){
294 n = &nodes[street->first];
295 n->name = street->first;
299 }else if (newNode->second.settled)
302 n = &newNode->second;
304 if (n->cost > node->cost + 1){
305 n->cost = node->cost + 1;
315 return list<string>();