]> ruin.nu Git - icfp05.git/blobdiff - robber/robber.cpp
priority queue instead of a vector which is later sorted
[icfp05.git] / robber / robber.cpp
index 0e0a265a1e26daaf0fd6da99f0d2126922a9ed88..f586f6ae3267a4e95664d54c4c8ec2e9c36d8d38 100644 (file)
@@ -1,6 +1,7 @@
 #include "robber.h"
 #include <iostream>
 #include <iterator>
+#include <queue>
 #include <cmath>
 
 using namespace std;
@@ -36,8 +37,8 @@ string Robber::turn(){
                double goodness = 0;
                Intersection& conInter = _intersections[street->first];
 
-               list<string> closestFootCop = shortestPath(street->first, cop_foot, FindPlayer(_players, cop_foot, 6));
-               list<string> closestCarCop = shortestPath(street->first, cop_car, FindPlayer(_players, cop_car, 5));
+               list<string> closestFootCop = shortestPath(street->first, cop_foot, FindPlayer(_players, cop_foot, 6), true);
+               list<string> closestCarCop = shortestPath(street->first, cop_car, FindPlayer(_players, cop_car, 5), true);
 
                unsigned int closestCop = 0;
                bool copInCar = false;
@@ -53,7 +54,7 @@ string Robber::turn(){
                        continue;
                }
 
-               vector<double> banks;
+               priority_queue<double> banks;
                for(hash_map<string,int>::const_iterator bank = _banks.begin();
                                bank != _banks.end(); ++bank){
                        //cerr << "Handling bank at: " << bank->first << endl;
@@ -63,13 +64,15 @@ string Robber::turn(){
                                        continue;
                                //list<string>::iterator i = l.begin();
                                //++i;
-                               banks.push_back(bank->second/(pow(l.size(),4.0)));
+                               banks.push(bank->second/(pow(l.size(),4.0)));
                        }
                }
-               sort(banks.begin(),banks.end(),greater<double>());
+               //sort(banks.begin(),banks.end(),greater<double>());
 
-               for (unsigned int i = 0; i < 2 && i < banks.size();++i)
-                       goodness += banks[i];
+               for (unsigned int i = 0; i < 2 && banks.size() > 0;++i){
+                       goodness += banks.top();
+                       banks.pop();
+               }
 
                cerr << "Goodness before cop: " << goodness << endl;
                if (closestCop > 2){