/* function : SetCell () this function sets the value of a cell, then registers a SET action on the action course. if this function fails for any reasons, it registers instead a BAD_OPERATION action and sets the _BAD_OPERATION state flag. return value : - if succeeded : true. - if failed : false. */ bool sudokuBoard::SetCell (Cell * target , sudokuValue NewVal) { target ->v = NewVal ; bool status = this ->pushAction ( actionRecord ( actionRecord::SET , *target , true ) ); // if a failure happened, try to signal it. if ( !status ) { state |= ! sudokuState::_BAD_OPERATION ; // try to signal a bad operation. try { if( ! this->pushAction ( actionRecord(actionRecord::BAD_OPERATION , Cell() , false ) ) ) throw int(); } catch( int x ) { // if couldn't signal the bad operation, then terminate the program. UNREFERENCED_VAR(x); std::cerr << "Fatal error, pushAction failure.\nGenerated from function :\t"__FUNCTION__<<std::endl; std::cerr << "\tTerminating . . ."<<std::endl; std::terminate(); } return false; } else return true; }
/* function : leap_O_faith () called when there's no absolute choice to be made. this function chooses the cell with minimum number of possible values and assigns it a random value. it then pushes a LEAP_OF_FAITH action record on top of the action tracker. if this function fails, it sets the state flag _BAD_OPERATION. return value : Succeeded -> true. Failed -> false. */ bool sudokuBoard::leap_O_faith() { Cell *minPossib = &Data[0][0]; // find the minnimum possibilities cell that is free. for(Index i=0 ; i<9 ; i++) { for(Index j=0 ; j<9 ; j++) { if( Data[i][j] == sudokuValue::UNSET ) if( Data[i][j].countPossibilities() < minPossib->countPossibilities() ) minPossib = &Data[i][j]; } } // re-validate the chosen cell to check for errors. expectFor( *minPossib ); // if the possibilities have changed, then the current state of the board is invalid. if(minPossib->countPossibilities() == 0) { // set the bad operation flag and push a bad operation action. this->state |= sudokuState::_BAD_OPERATION; pushAction ( actionRecord( actionRecord::BAD_OPERATION , Cell() , false ) ); return false; } // else if the possibilities are correct : else { for(int i=1 ; i<10 ; i++) // cycle through the possibilities of the cell { if(minPossib->possible[i]) // find the first possible value. { Data[minPossib->row][minPossib->col].v = i; // return an action indicating the leap of faith. pushAction ( actionRecord( actionRecord::LEAP_OF_FAITH , Data[minPossib->row][minPossib->col] , true) ); return true; } } } // if couldn't find a guess, then report failure. return false; }
/************************************************************** * class actionCoarse. * Methods : ***************************************************************/ actionCourse::actionCourse() : state(0) { Tracker.push(actionRecord(actionRecord::NO_ACTION , Cell() , false)); }
/* function : Correct_LeapOfFaith () pre-condition : the top of the action tracker is a wrong leap of faith action. this function corrects the error made at the last leap of faith, by choosing a value that is valid and not specified in the faultyValues vector. if this function fails, it sets the error stat _BAD_OPERATION and registers a BAD_OPERATION actionRecord on top of the action course. return value : - if succeeded and changed the value . . . . : true - if the value wasn't changed due to any circumstance : false */ bool sudokuBoard::Correct_LeapOfFaith() { actionRecord last = lastAction(); // check for a faulty LEAP_OF_FAITH action if( last != actionRecord::LEAP_OF_FAITH ) { pushAction( actionRecord ( actionRecord::BAD_OPERATION , Cell() , false) ); return false; } // check if the current leap is actually faulty, // by checking if it has any faulty values. if( last.faultyValues.size() == 0 ) { pushAction( actionRecord ( actionRecord::BAD_OPERATION , Cell() , false) ); return false; } // cycle through the possibilities for( Index i = 0 ; i<10 ; i++ ) { // if the number contained in (i) is a valid in the subject cell: if( last.subject->possible[i] ) { // validate the cell to avoid any possible errors in expectations : expectFor( *last.subject ); // check if that number exists in the faulty values: bool IsFaulty = false; for( Index j = 0 ; j < last.faultyValues.size() ; j++) { if( i == static_cast<int>(last.faultyValues[j]) ) { IsFaulty = true; break; } } // if the value is a faulty one, then look for another : if (IsFaulty) continue; // else, make this value the new choice of this leap : else { // set the new value : last.subject->v = i; // re-validate the cell : expectFor( *last.subject ); // report success : return true; } } } // if execution reaches this point, then a value hasn't been changed. // report failure. return false; }
UI::UI() { widget.setupUi(this); widget.gridLayout->setContentsMargins(2,2,2,2); widget.gridLayout->setVerticalSpacing(0); // connect up all the menus connect(widget.actionAbout,SIGNAL(triggered()),this,SLOT(actionAbout())); connect(widget.actionConnectToServer,SIGNAL(triggered()),this,SLOT(actionConnect())); connect(widget.actionDisconnectFromServer,SIGNAL(triggered()),this,SLOT(actionDisconnect())); connect(widget.actionSubrx,SIGNAL(triggered()),this,SLOT(actionSubRx())); connect(widget.actionBandscope,SIGNAL(triggered()),this,SLOT(actionBandscope())); connect(widget.actionRecord,SIGNAL(triggered()),this,SLOT(actionRecord())); connect(&connection,SIGNAL(isConnected()),this,SLOT(connected())); connect(&connection,SIGNAL(disconnected(QString)),this,SLOT(disconnected(QString))); connect(&connection,SIGNAL(audioBuffer(char*,char*)),this,SLOT(audioBuffer(char*,char*))); connect(&connection,SIGNAL(spectrumBuffer(char*,char*)),this,SLOT(spectrumBuffer(char*,char*))); connect(widget.actionConfig,SIGNAL(triggered()),this,SLOT(actionConfigure())); connect(widget.actionMuteMainRx,SIGNAL(triggered()),this,SLOT(actionMuteMainRx())); connect(widget.actionMuteSubRx,SIGNAL(triggered()),this,SLOT(actionMuteSubRx())); connect(widget.actionGain_10,SIGNAL(triggered()),this,SLOT(actionGain_10())); connect(widget.actionGain_20,SIGNAL(triggered()),this,SLOT(actionGain_20())); connect(widget.actionGain_30,SIGNAL(triggered()),this,SLOT(actionGain_30())); connect(widget.actionGain_40,SIGNAL(triggered()),this,SLOT(actionGain_40())); connect(widget.actionGain_50,SIGNAL(triggered()),this,SLOT(actionGain_50())); connect(widget.actionGain_60,SIGNAL(triggered()),this,SLOT(actionGain_60())); connect(widget.actionGain_70,SIGNAL(triggered()),this,SLOT(actionGain_70())); connect(widget.actionGain_80,SIGNAL(triggered()),this,SLOT(actionGain_80())); connect(widget.actionGain_90,SIGNAL(triggered()),this,SLOT(actionGain_90())); connect(widget.actionGain_100,SIGNAL(triggered()),this,SLOT(actionGain_100())); connect(widget.actionKeypad, SIGNAL(triggered()),this,SLOT(actionKeypad())); connect(&keypad,SIGNAL(setKeypadFrequency(long long)),this,SLOT(setKeypadFrequency(long long))); connect(widget.action160, SIGNAL(triggered()),this,SLOT(action160())); connect(widget.action80, SIGNAL(triggered()),this,SLOT(action80())); connect(widget.action60, SIGNAL(triggered()),this,SLOT(action60())); connect(widget.action40, SIGNAL(triggered()),this,SLOT(action40())); connect(widget.action30, SIGNAL(triggered()),this,SLOT(action30())); connect(widget.action20, SIGNAL(triggered()),this,SLOT(action20())); connect(widget.action17, SIGNAL(triggered()),this,SLOT(action17())); connect(widget.action15, SIGNAL(triggered()),this,SLOT(action15())); connect(widget.action12, SIGNAL(triggered()),this,SLOT(action12())); connect(widget.action10, SIGNAL(triggered()),this,SLOT(action10())); connect(widget.action6, SIGNAL(triggered()),this,SLOT(action6())); connect(widget.actionGen, SIGNAL(triggered()),this,SLOT(actionGen())); connect(widget.actionWWV, SIGNAL(triggered()),this,SLOT(actionWWV())); connect(widget.actionCWL,SIGNAL(triggered()),this,SLOT(actionCWL())); connect(widget.actionCWU,SIGNAL(triggered()),this,SLOT(actionCWU())); connect(widget.actionLSB,SIGNAL(triggered()),this,SLOT(actionLSB())); connect(widget.actionUSB,SIGNAL(triggered()),this,SLOT(actionUSB())); connect(widget.actionDSB,SIGNAL(triggered()),this,SLOT(actionDSB())); connect(widget.actionAM,SIGNAL(triggered()),this,SLOT(actionAM())); connect(widget.actionSAM,SIGNAL(triggered()),this,SLOT(actionSAM())); connect(widget.actionFMN,SIGNAL(triggered()),this,SLOT(actionFMN())); connect(widget.actionDIGL,SIGNAL(triggered()),this,SLOT(actionDIGL())); connect(widget.actionDIGU,SIGNAL(triggered()),this,SLOT(actionDIGU())); connect(widget.actionFilter_0,SIGNAL(triggered()),this,SLOT(actionFilter0())); connect(widget.actionFilter_1,SIGNAL(triggered()),this,SLOT(actionFilter1())); connect(widget.actionFilter_2,SIGNAL(triggered()),this,SLOT(actionFilter2())); connect(widget.actionFilter_3,SIGNAL(triggered()),this,SLOT(actionFilter3())); connect(widget.actionFilter_4,SIGNAL(triggered()),this,SLOT(actionFilter4())); connect(widget.actionFilter_5,SIGNAL(triggered()),this,SLOT(actionFilter5())); connect(widget.actionFilter_6,SIGNAL(triggered()),this,SLOT(actionFilter6())); connect(widget.actionFilter_7,SIGNAL(triggered()),this,SLOT(actionFilter7())); connect(widget.actionFilter_8,SIGNAL(triggered()),this,SLOT(actionFilter8())); connect(widget.actionFilter_9,SIGNAL(triggered()),this,SLOT(actionFilter9())); connect(widget.actionANF,SIGNAL(triggered()),this,SLOT(actionANF())); connect(widget.actionNR,SIGNAL(triggered()),this,SLOT(actionNR())); connect(widget.actionNB,SIGNAL(triggered()),this,SLOT(actionNB())); connect(widget.actionSDROM,SIGNAL(triggered()),this,SLOT(actionSDROM())); connect(widget.actionPolyphase,SIGNAL(triggered()),this,SLOT(actionPolyphase())); connect(widget.actionLong,SIGNAL(triggered()),this,SLOT(actionLong())); connect(widget.actionSlow,SIGNAL(triggered()),this,SLOT(actionSlow())); connect(widget.actionMedium,SIGNAL(triggered()),this,SLOT(actionMedium())); connect(widget.actionFast,SIGNAL(triggered()),this,SLOT(actionFast())); connect(widget.actionPreamp,SIGNAL(triggered()),this,SLOT(actionPreamp())); connect(widget.actionBookmarkThisFrequency,SIGNAL(triggered()),this,SLOT(actionBookmark())); connect(widget.actionEditBookmarks,SIGNAL(triggered()),this,SLOT(editBookmarks())); // connect up band and frequency changes connect(&band,SIGNAL(bandChanged(int,int)),this,SLOT(bandChanged(int,int))); // connect(&band,SIGNAL(frequencyChanged(long long)),this,SLOT(frequencyChanged(long long))); // connect up mode changes connect(&mode,SIGNAL(modeChanged(int,int)),this,SLOT(modeChanged(int,int))); // connect up filter changes connect(&filters,SIGNAL(filtersChanged(FiltersBase*,FiltersBase*)),this,SLOT(filtersChanged(FiltersBase*,FiltersBase*))); connect(&filters,SIGNAL(filterChanged(int,int)),this,SLOT(filterChanged(int,int))); // connect up spectrum frame connect(widget.spectrumFrame, SIGNAL(frequencyMoved(int,int)), this, SLOT(frequencyMoved(int,int))); connect(widget.spectrumFrame, SIGNAL(frequencyChanged(long long)), this, SLOT(frequencyChanged(long long))); connect(widget.spectrumFrame, SIGNAL(spectrumHighChanged(int)), this,SLOT(spectrumHighChanged(int))); connect(widget.spectrumFrame, SIGNAL(spectrumLowChanged(int)), this,SLOT(spectrumLowChanged(int))); connect(widget.spectrumFrame, SIGNAL(waterfallHighChanged(int)), this,SLOT(waterfallHighChanged(int))); connect(widget.spectrumFrame, SIGNAL(waterfallLowChanged(int)), this,SLOT(waterfallLowChanged(int))); // connect up waterfall frame connect(widget.waterfallFrame, SIGNAL(frequencyMoved(int,int)), this, SLOT(frequencyMoved(int,int))); // connect up configuration changes connect(&configure,SIGNAL(spectrumHighChanged(int)),this,SLOT(spectrumHighChanged(int))); connect(&configure,SIGNAL(spectrumLowChanged(int)),this,SLOT(spectrumLowChanged(int))); connect(&configure,SIGNAL(fpsChanged(int)),this,SLOT(fpsChanged(int))); connect(&configure,SIGNAL(waterfallHighChanged(int)),this,SLOT(waterfallHighChanged(int))); connect(&configure,SIGNAL(waterfallLowChanged(int)),this,SLOT(waterfallLowChanged(int))); connect(&configure,SIGNAL(waterfallAutomaticChanged(bool)),this,SLOT(waterfallAutomaticChanged(bool))); configure.initAudioDevices(&audio); connect(&configure,SIGNAL(audioDeviceChanged(QAudioDeviceInfo,int,int,QAudioFormat::Endian)),this,SLOT(audioDeviceChanged(QAudioDeviceInfo,int,int,QAudioFormat::Endian))); connect(&configure,SIGNAL(hostChanged(QString)),this,SLOT(hostChanged(QString))); connect(&configure,SIGNAL(receiverChanged(int)),this,SLOT(receiverChanged(int))); connect(&configure,SIGNAL(nrValuesChanged(int,int,double,double)),this,SLOT(nrValuesChanged(int,int,double,double))); connect(&configure,SIGNAL(anfValuesChanged(int,int,double,double)),this,SLOT(anfValuesChanged(int,int,double,double))); connect(&configure,SIGNAL(nbThresholdChanged(double)),this,SLOT(nbThresholdChanged(double))); connect(&configure,SIGNAL(sdromThresholdChanged(double)),this,SLOT(sdromThresholdChanged(double))); connect(&bookmarks,SIGNAL(bookmarkSelected(QAction*)),this,SLOT(selectBookmark(QAction*))); connect(&bookmarkDialog,SIGNAL(accepted()),this,SLOT(addBookmark())); connect(&configure,SIGNAL(addXVTR(QString,long long,long long,long long,long long,int,int)),this,SLOT(addXVTR(QString,long long,long long,long long,long long,int,int))); connect(&configure,SIGNAL(deleteXVTR(int)),this,SLOT(deleteXVTR(int))); connect(&xvtr,SIGNAL(xvtrSelected(QAction*)),this,SLOT(selectXVTR(QAction*))); bandscope=NULL; fps=15; gain=100; subRx=FALSE; subRxGain=100; agc=AGC_SLOW; cwPitch=600; audio_device=0; audio_sample_rate=configure.getSampleRate(); audio_channels=configure.getChannels(); audio_byte_order=configure.getByteOrder(); audio.initialize_audio(AUDIO_BUFFER_SIZE); // load any saved settings loadSettings(); switch(agc) { case AGC_SLOW: widget.actionSlow->setChecked(TRUE); break; case AGC_MEDIUM: widget.actionMedium->setChecked(TRUE); break; case AGC_FAST: widget.actionFast->setChecked(TRUE); break; case AGC_LONG: widget.actionLong->setChecked(TRUE); break; } fps=configure.getFps(); configure.updateXvtrList(&xvtr); xvtr.buildMenu(widget.menuXVTR); widget.spectrumFrame->setHost(configure.getHost()); widget.spectrumFrame->setReceiver(configure.getReceiver()); widget.actionSubrx->setDisabled(TRUE); widget.actionMuteSubRx->setDisabled(TRUE); band.initBand(band.getBand()); }