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);
205 _evidence[world] = input;
209 _smell = value<int>(input);
216 istringstream player(input);
219 //cerr << "Player: " << input << endl;
220 Player& pl = _players[input];
221 player >> pl.location;
223 pl.type = _playerTypes[input];
225 //cerr << "Number of players: " << _players.size() << endl;
228 void Bot::move(std::string location){
229 cerr << "Moving to: " << location << endl;
230 cout << "mov: " << location << " " << _playerTypeNames[_type] << endl;
234 T value(std::string input){
235 istringstream istr(input);
242 std::string Bot::turn(){
243 cerr << "Using stupid stand still Bot::turn" << endl;
248 bool operator()(const SPInfo* v1, const SPInfo* v2){
249 return v1->cost > v2->cost;
253 std::list<std::string> Bot::shortestPath(const std::string& from, PlayerType type, const SPGoal& goal){
255 //cerr << "New shortest path from: " << from << endl;
257 priority_queue<SPInfo*, vector<SPInfo* >, SPInfoComp > pq;
258 hash_map<string,SPInfo> nodes;
260 SPInfo* node = &nodes[from];
262 node->settled = false;
271 //cerr << "Vector with size: " << w.size() << endl;
272 //cerr << "Looking at: " << node->name << endl;
273 //copy(w.begin(), w.end(), ostream_iterator<string>(cerr, " : "));
280 front_insert_iterator<list<string> > ii(l);
287 node->settled = true;
289 Intersection& inter = _intersections[node->name];
290 for (hash_map<string,StreetType>::const_iterator street = inter.connections.begin();
291 street != inter.connections.end(); ++street){
292 hash_map<string,SPInfo>::iterator newNode = nodes.find(street->first);
293 bool hascar = type == cop_car;
294 if ( (hascar && (street->second == car || street->second == both)) ||
295 (!hascar && (street->second == foot || street->second == both))){
296 //cerr << "Adding street: " << street->first << endl;
298 if (newNode == nodes.end()){
299 n = &nodes[street->first];
300 n->name = street->first;
304 }else if (newNode->second.settled)
307 n = &newNode->second;
309 if (n->cost > node->cost + 1){
310 n->cost = node->cost + 1;
320 return list<string>();