Exemplo n.º 1
0
void AI::objectCheck()
{
  cout<<"--Base AI variables--"<<endl;
  cout<<"turnNumber\t"<<turnNumber()<<endl;
  ///Player Number; either 0 or 1
  cout<<"playerID\t"<<playerID()<<endl;
  ///What number game this is for the server
  cout<<"gameNumber\t"<<gameNumber()<<endl;
  ///Player 0's time remaining
  cout<<"player0Time\t"<<player0Time()<<endl;
  ///Player 1's time remaining
  cout<<"player1Time\t"<<player1Time()<<endl;
  ///Player 0's name
  cout<<"player0Name\t"<<player0Name()<<endl;
  ///Player 1's name
  cout<<"player1Name\t"<<player1Name()<<endl;
  ///The cost of a pirate
  cout<<"pirateCost\t"<<pirateCost()<<endl;
  ///The cost of a ship
  cout<<"shipCost\t"<<shipCost()<<endl;
  cout<<"portCost\t"<<portCost()<<endl;
  cout<<"boardX\t"<<boardX()<<endl;
  cout<<"baordY\t"<<boardY()<<endl;
  cout<<"--Object counts--"<<endl;
  cout<<"Pirates : "<<pirates.size()<<endl;
  displayPirates();
  cout<<"Ports   : "<<ports.size()<<endl;
  displayPorts();
  cout<<"Ships   : "<<ships.size()<<endl;
  displayShips();
  cout<<"Tiles   : "<<tiles.size()<<endl;
  displayTiles();
  cout<<"Treasure: "<<treasures.size()<<endl;
//  displayTreasure();
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
    QCoreApplication app(argc,argv);

    // check input args
    QStringList inputArgs = app.arguments();
    if(inputArgs.size() != 2)   {
        badInput();
        return -1;
    }

    // open osmscout map
    osmscout::DatabaseParameter map_param;
    osmscout::Database map(map_param);
    if(!map.Open(inputArgs[1].toStdString()))   {
        qDebug() << "ERROR: Failed to open osmscout map";
        return -1;
    }
    osmscout::TypeConfig * typeConfig = map.GetTypeConfig();
    osmscout::TypeSet typeSet;
    setTypesForAdminRegions(typeConfig,typeSet);

//    GeoBoundingBox tempbbox;
//    tempbbox.minLon = -83.3203; tempbbox.maxLon = -82.9688;
//    tempbbox.minLat = 42.1875; tempbbox.maxLat = 42.3633;

////    tempbbox.minLon -= 1; tempbbox.maxLon += 1;
////    tempbbox.minLat -= 1; tempbbox.maxLat += 1;

    // create search database
    Kompex::SQLiteDatabase * database;
    Kompex::SQLiteStatement * stmt;

    QString db_file_path = app.applicationDirPath()+"/searchdb.sqlite";
    QFile db_file(db_file_path);
    if(db_file.exists())   {
        if(!db_file.remove())   {
            qDebug() << "ERROR: searchdb.sqlite exists and "
                        "could not be deleted";
            return -1;
        }
    }

    try   {
        database = new Kompex::SQLiteDatabase("searchdb.sqlite",
                                              SQLITE_OPEN_READWRITE |
                                              SQLITE_OPEN_CREATE,0);

        stmt = new Kompex::SQLiteStatement(database);

        stmt->SqlStatement("CREATE TABLE name_lookup("
                           "name_id INTEGER PRIMARY KEY NOT NULL,"
                           "name_lookup TEXT NOT NULL UNIQUE);");

        stmt->SqlStatement("CREATE TABLE admin_regions("
                           "id INTEGER PRIMARY KEY NOT NULL,"
                           "node_offsets BLOB,"
                           "way_offsets BLOB,"
                           "area_offsets BLOB"
                           ");");

        stmt->SqlStatement("CREATE TABLE streets("
                           "id INTEGER PRIMARY KEY NOT NULL,"
                           "node_offsets BLOB,"
                           "way_offsets BLOB,"
                           "area_offsets BLOB"
                           ");");

        stmt->SqlStatement("CREATE TABLE pois("
                           "id INTEGER PRIMARY KEY NOT NULL,"
                           "node_offsets BLOB,"
                           "way_offsets BLOB,"
                           "area_offsets BLOB"
                           ");");
    }
    catch(Kompex::SQLiteException &exception)   {
        qDebug() << "ERROR: SQLite exception creating database:"
                 << QString::fromStdString(exception.GetString());
        return -1;
    }


    // build a tile list for the dataset

//    // world bbox
//    GeoBoundingBox bbox_world;
//    bbox_world.minLon = -180.0; bbox_world.maxLon = 180.0;
//    bbox_world.minLat = -90.0;  bbox_world.maxLat = 90.0;

    // map data bbox
    GeoBoundingBox bbox_map;
    map.GetBoundingBox(bbox_map.minLat,bbox_map.minLon,
                       bbox_map.maxLat,bbox_map.maxLon);

    // generate tile list
    std::vector<Tile*> list_tiles;
    buildTileList(bbox_map,list_tiles);

#ifdef DEBUG_WITH_OSG
    return displayTiles(bbox_map,list_tiles);
#endif


    // [name_id] [name_key]
    int32_t name_id=1;
    boost::unordered_map<std::string,int32_t> table_names;

    // build database tables
    bool opOk=false;

    // admin_regions
    qDebug() << "INFO: Building admin_regions table...";
    setTypesForAdminRegions(typeConfig,typeSet);
    opOk = buildTable(stmt,name_id,table_names,"admin_regions",
                      list_tiles,map,typeSet,false,true,true);
    if(opOk)   {
        qDebug() << "INFO: Finished building admin_regions table";
    }
    else   {
        qDebug() << "ERROR: Failed to build admin_regions table";
        return -1;
    }

    // streets
    qDebug() << "INFO: Building streets table...";
    setTypesForStreets(typeConfig,typeSet);
    opOk = buildTable(stmt,name_id,table_names,"streets",
                      list_tiles,map,typeSet,false,false,false);
    if(opOk)   {
        qDebug() << "INFO: Finished building streets table";
    }
    else   {
        qDebug() << "ERROR: Failed to build streets table";
        return -1;
    }

    // pois
    qDebug() << "INFO: Building pois table...";
    setTypesForPOIs(typeConfig,typeSet);
    opOk = buildTable(stmt,name_id,table_names,"pois",
                      list_tiles,map,typeSet,false,false,false);
    if(opOk)   {
        qDebug() << "INFO: Finished building pois table";
    }
    else   {
        qDebug() << "ERROR: Failed to build pois table";
        return -1;
    }

    // build name_lookup table
    qDebug() << "INFO: Building name_lookup table...";
    opOk = buildNameLookupTable(stmt,table_names);
    if(opOk)   {
        qDebug() << "INFO: Finished building name_lookup table";
    }
    else   {
        qDebug() << "ERROR: Failed to build name_lookup table";
        return -1;
    }

    // vacuum to minimize db
    try   {
        stmt->SqlStatement("VACUUM;");
    }
    catch(Kompex::SQLiteException &exception)   {
        qDebug() << "ERROR: SQLite exception vacuuming:"
                 << QString::fromStdString(exception.GetString());
        return -1;
    }

    // clean up
    for(size_t i=0; i < list_tiles.size(); i++)   {
        delete list_tiles[i];
    }
    list_tiles.clear();
    delete stmt;
    delete database;

//    // ### debug
//    std::map<int64_t,std::string> table_count_names;
//    boost::unordered_map<std::string,qint64>::iterator it;
//    for(it = table_names.begin(); it != table_names.end(); ++it)   {
//        std::map<int64_t,int64_t>::iterator d_it;
//        d_it = g_table_nameid_count.find(it->second);

//        std::pair<int64_t,std::string> data;
//        data.first = d_it->second;
//        data.second = it->first;
//        table_count_names.insert(data);
//    }

//    std::map<int64_t,std::string>::iterator c_it;
//    for(c_it  = table_count_names.begin();
//        c_it != table_count_names.end(); ++c_it)   {
//        qDebug() << QString::fromStdString(c_it->second) << ":" << c_it->first;
//    }

//    // debug
//    boost::unordered_map<std::string,qint64>::iterator it;
//    for(it  = table_names.begin(); it != table_names.end(); ++it)
//    {
//        qDebug() << it->second << ": " << QString::fromStdString(it->first);
//    }
}