/* * sets the depth and path history */ void completeBoard(Board *current, Board *newBoard, int mov, int f) { int i; newBoard->depth = current->depth + 1; newBoard->path = (int *)calloc(newBoard->depth, sizeof(int)); setNumbers(newBoard); for(i = 0; i < current->depth; i++) { newBoard->path[i] = current->path[i]; } newBoard->path[newBoard->depth - 1] = mov; switch(f) { case 0: newBoard->f = newBoard->depth + getH(newBoard); break; case 1: newBoard->f = newBoard->depth + getHout(newBoard); break; case 2: newBoard->f = newBoard->depth + getHmanhattan(newBoard); break; case 3: newBoard->f = newBoard->depth + getHgreat2(newBoard); break; case 4: newBoard->f = newBoard->depth + getHgreat3(newBoard); break; default: printf("error\n"); } }
int manager::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: { QString _r = autoCalc((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r; } break; case 1: { QString _r = calc((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r; } break; case 2: loadLayouts(); break; case 3: restoreLayouts(); break; case 4: { QString _r = getFunctions((*reinterpret_cast< QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r; } break; case 5: setABC(); break; case 6: setNumbers(); break; case 7: setAngleModeRadian(); break; case 8: setAngleModeDegree(); break; case 9: { QString _r = getAngleMode(); if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r; } break; case 10: setClipboard((*reinterpret_cast< QString(*)>(_a[1]))); break; default: ; } _id -= 11; } return _id; }
void Altimeter::loadSettings(QSettings &settings) { PanelItem::loadSettings(settings); QString unitname = settings.value("unit").toString(); DistanceUnit unit = Units::distanceUnitForName(unitname); setUnit(unit); setRange1(settings.value("range1", 500).toDouble()); setRange2(settings.value("range2", 5000).toDouble()); setThinBars(settings.value("thinbars", 10).toDouble()); setThickBars(settings.value("thickbars", 50).toDouble()); setNumbers(settings.value("numbers", 100).toDouble()); setNumbersScale(settings.value("numbersscale", 0.01).toDouble()); }
Variometer::Variometer(QObject *parent, ExtPlaneConnection *conn) : NeedleInstrument(parent), _client(this, typeName(), conn) { conn->registerClient(&_client); _client.subscribeDataRef("sim/flightmodel/position/vh_ind_fpm", 2.0); connect(&_client, SIGNAL(refChanged(QString,double)), this, SLOT(velocityChanged(QString,double))); setBars(500, 100); setNumbers(500); setNumberScale(0.01); setUnit(VELOCITY_FPM); setMaxValue(2000); setMinTextValue(-2000); isTotalEnergy = false; setIsTotalEnergy(false); }
Variometer::Variometer(ExtPlanePanel *panel, ExtPlaneConnection *conn) : NeedleInstrument(panel), _client(this, typeName(), conn), interpolator(0, 3) { conn->registerClient(&_client); _client.subscribeDataRef("sim/flightmodel/position/vh_ind", VARIOMETER_ACCURACY); connect(&_client, SIGNAL(refChanged(QString,double)), &interpolator, SLOT(valueChanged(QString,double))); connect(&interpolator, SIGNAL(interpolatedValueChanged(QString,double)), this, SLOT(velocityChanged(QString,double))); setBars(1, 0.5); setNumbers(1); setUnit(VELOCITY_MS); setMaxValue(5); isTotalEnergy = false; setIsTotalEnergy(false); setNeedle(new GABalancedNeedle(this)); }
Altimeter::Altimeter(QObject *parent, ExtPlaneConnection *conn) : PanelItem(parent), _client(this, typeName(), conn) { _value = 0; setThickBars(50); setThinBars(10); setRange1(500); setRange2(5000); setNumbers(50); setNumbersScale(0.01); _baroPressure = 1013.25; _bezel = QPixmap::fromImage(QImage(QString("../../images/bezel_square_.png")), Qt::AutoColor); units = DISTANCE_M; baroUnits = PRESSURE_HPA; connect(&_client, SIGNAL(refChanged(QString,double)), this, SLOT(refChanged(QString,double))); _client.subscribeDataRef("sim/flightmodel/misc/h_ind", 3); _client.subscribeDataRef("sim/cockpit2/gauges/actuators/barometer_setting_in_hg_pilot"); }
AirspeedIndicator::AirspeedIndicator(ExtPlanePanel *panel, ExtPlaneConnection *conn) : NeedleInstrument(panel), _client(this, typeName(), conn), interpolator(0, 5) { conn->registerClient(&_client); _client.subscribeDataRef("sim/cockpit2/gauges/indicators/airspeed_kts_pilot", 0.3); // _client.subscribeDataRef("simulated", 1); connect(&_client, SIGNAL(refChanged(QString,double)), &interpolator, SLOT(valueChanged(QString,double))); connect(&interpolator, SIGNAL(interpolatedValueChanged(QString,double)), this, SLOT(speedChanged(QString,double))); setBars(20, 10); setNumbers(50); setUnit(VELOCITY_KTS); setMaxValue(300); setVso(35); setVs(50); setVfe(110); setVno(150); setVne(200); yellowTriangle = vs; setNeedle(new GABalancedNeedle(this)); }
Altimeter::Altimeter(QObject *parent, ExtPlaneConnection *conn) : PanelItem(parent), _client(this, typeName(), conn) { _value = 0; setThickBars(50); setThinBars(10); setRange1(500); setRange2(5000); setNumbers(50); setNumbersScale(0.01); _baroPressure = 1013.25; units = DISTANCE_M; baroUnits = PRESSURE_HPA; connect(&_client, SIGNAL(refChanged(QString,double)), this, SLOT(refChanged(QString,double))); _client.subscribeDataRef("sim/flightmodel/misc/h_ind", 3); _client.subscribeDataRef("sim/cockpit2/gauges/actuators/barometer_setting_in_hg_pilot"); font.setPixelSize(20); // @todo configurable pressureFont.setPixelSize(15); }
int main(){ //set up moves Move moves[4] ={{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; //set up hash table HashTable *hashTable; HashTable *queueTable; int tableSize = pow(SIZE, 9) - SIZE + 1; int nos[SIZE * SIZE]; int g[SIZE * SIZE]; char *nums = (char *)calloc(SIZE * SIZE, sizeof(char)); //char nums[9] = {'7', '2', '4', '5', '6', '0', '8', '3', '1'}; nums = readData(); char *gl = (char *)calloc(SIZE * SIZE, sizeof(char)); //char gl[9] = {'2', '4', '1', '7', '8', '6', '5', '0', '3'}; gl = readData(); int i; //converts char* to int* for(i = 0; i < SIZE * SIZE; i++) nos[i] = (int)nums[i] - '0'; for(i = 0; i < SIZE * SIZE; i++) g[i] = (int)gl[i] - '0'; goal = (Board *)calloc(1, sizeof(Board)); insertTiles(goal, g); setNumbers(goal); start = (Board *)calloc(1, sizeof(Board)); insertTiles(start, nos); setNumbers(start); start->depth = 0; printf("\nSTART:\n"); printBoard(start); printf("\nGOAL:\n"); printBoard(goal); Queue *queue; Board *newBoard; int f; for (f = 0; f < 5; f++){ success = 0; hashTable = (HashTable *)createHashTable(tableSize); queueTable = (HashTable *)createHashTable(tableSize); solution = (Board *)calloc(1, sizeof(Board)); Board *board = (Board *)calloc(1, sizeof(Board)); board = start; switch(f){ case 0: board->f = getH(board); break; case 1: board->f = getHout(board); break; case 2: board->f = getHmanhattan(board); break; case 3: board->f = getHgreat2(board); break; case 4: board->f = getHgreat3(board); break; default: printf("error\n"); } //set up queue queue = (Queue *)createQueue(); int error; if((error = insert(queue, board)) == 1){ printf("failed to insert starting board\n"); exit(1); } Node *current; //Board *newBoard; int m; int fVal; int tries = 0; //iterate through queue until done while(!success){ current = queue->head; if((fVal = lookupBoard(hashTable, current->b)) == -1) { if((error = addBoard(hashTable, current->b)) == 1) { printf("failed to add board to hashtable\n"); exit(1); } //moves for(m = 0; m < 4; m++){ if(!success) { if((newBoard = makeBoardOnMove(current, moves[m], f)) != NULL){ if(newBoard->value == goal->value){ success = 1; solution = newBoard; } if((fVal = lookupBoard(queueTable, newBoard)) == -1){ tries++; if((error = insert(queue, newBoard)) == 1) { printf("failed to insert new board\n"); exit(1); } if((error = addBoard(queueTable, newBoard)) == 1) { printf("failed to add new Board to queuetable\n"); exit(1); } } else if(newBoard->f < fVal) { tries++; if((error = replace(queue, newBoard)) == 1) { printf("failed to replace with new board\n"); exit(1); } error = addBoard(queueTable, newBoard); } else { free(newBoard); } } } } } pop(queue); if(queue->head == NULL)printf("Empty Queue\n"); } //print out results printf("\nTRIES: %d\n", tries); printf("COST: %d\n", solution->depth); printf("EST. DIST. START TO GOAL: %d\n", start->f); printf("\nSOLUTION: "); printPath(solution); int ql = getQueueLength(queue); printf("QUEUE LEN: %d\n\n", ql); freeQueue(queue); free(queue); free(hashTable); free(queueTable); hashTable = NULL; queueTable = NULL; queue = NULL; } return 1; }