Example #1
0
void verify(){
  int guess[100];
  int key = 0;
  int pin = 0;
  int i = 0;
  while(i<counter){
    key = keyboard();
    key = convert(key);
    pin = switchh();
    pin = translate(pin);
     if(key != 0){
       guess[i] = key;
     }
     if(pin != 0){
       guess[i] = pin;
     }
    i++;
  }
  int j = 0;
  while(j<counter){
    if(newGame[j] == guess[j]){
      j++;
      printf("correct\n");
    }else{
      printf("wrong\n");
      startOver();
      repeatColors();
      verify();
   }
  }
  printf("go again\n");
   repeatColors();
   verify();
}
vector<double>* OutputFile::getRoverM(ParamQt*param)
{
  vector<double>*v=new vector<double>();
  startOver();
  while (getIt(param))
    {
      v->push_back(param->getRM());
    }
  startOver();
  return v;

  /*int L=getL();
  int b=getB();
  vector<double>*v=new vector<double>();
  //for (unsigned int i=0;i<rhos.size();i++) v->push_back(rhos[i]/thetas[i]*L*deltas[i]/(deltas[i]*b+L-b)*0.75*(1.0-exp(-4.0*thetas[i]/L)));
  for (unsigned int i=0;i<rhos.size();i++) v->push_back(rhos[i]/thetas[i]*L*deltas[i]/(deltas[i]*b+L-b)*3.0*thetas[i]/(3.0*L+4.0*thetas[i]));
  return v;*/
}
OutputFile::OutputFile(string &qstrs,bool makeVectors)
  : mDoc (qstrs.c_str())
{
  if (mDoc.LoadFile())
  {
    outputinitialised=false;
    startOver();
  }
  else
  {
    cerr << "Error in reading qstrs.c_str()" << endl;
  }
}
Example #4
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    t = new QTimer(this);
    time = -1;
    ui->setupUi(this);
    connect(ui->pushButtonStart, SIGNAL(clicked()),
            this, SLOT(startExperiment()));
    connect(ui->okPushButton, SIGNAL(clicked()),
            this, SLOT(proceedToRusults()));
    connect(ui->ok2PushButton, SIGNAL(clicked()),
            this, SLOT(startOver()));
}
long ApostolicoGiancarlo<AlphaType, ShiftRule>::findNext(bool bCircular)
{
  AlphaType const* pStrWalk;
  AlphaType const* pTxtWalk;
  long nShift;
  long* pNWalk;
  long* pMIter;

  if (bCircular && (pTextCmp >= pTextEnd))
  {
    startOver();
  }

  pStrWalk = pSubStrEnd;
  pTxtWalk = pTextCmp;
  pNWalk = pNValues + nSubStr - 1;
  pMIter = pMWalk;

  while (pTextCmp < pTextEnd)
  {
    /*
     * If M(h) is undefined or M(h) = Ni = 0, then compare T(h) and P(i) as 
     * follows:
     */
#ifdef __STREE_DEBUG__
    cerr << "in ApostolicoGiancarlo::findNext(): *pMWalk = " << *pMWalk 
         << " *pNWalk = " << *pNWalk << " *pStrWalk = " << *pStrWalk 
         << " *pTxtWalk = " << *pTxtWalk << "." << endl;
#endif // __STREE_DEBUG__
    if ((*pMIter <= 0) || ((*pMIter == *pNWalk) && (*pNWalk == 0)))
    {
      /*
       * If T(h) = P(i)
       */
      if (*pStrWalk == *pTxtWalk) 
      {
        /*
         * and i = 1, then report an occurent of P ending at 
         * position j of T, set M(j) = n, and shift as in the Boyer-Moore 
         * algorithm (ending this phase).
         */
        if (pStrWalk == pSubStr)
        {
          nShift = nTextPos;
          tShiftRule.shiftMatch(nTextPos);
          pTextCmp += nTextPos - nShift;
          *pMWalk = nSubStr;
          pMWalk += nTextPos - nShift;
#ifdef __STREE_DEBUG__
          cerr << "in ApostolicoGiancarlo::findNext(): case 1a match found." 
               << endl;
#endif // __STREE_DEBUG__
          return nShift;
        }
        /* 
         * and i > 1, then set h to h-1 and i to i-1 and repeat the phase
         * algorithm.
         */
        else if (pStrWalk > pSubStr)
        {
          --pStrWalk;
          --pTxtWalk;
          --pMIter;
          --pNWalk;
#ifdef __STREE_DEBUG__
          cerr << "in ApostolicoGiancarlo::findNext(): case 1b." << endl;
#endif // __STREE_DEBUG__
        }
      }
      /*
       * If T(h) != P(i), then set M(j) = j-h and shift P according to the 
       * Boyer-Moore rules based on a mismatch occuring in position i of P
       * (this ends the phase).
       */
      else
      {
        *pMWalk = pMWalk - pMIter;

        nShift = tShiftRule.shift(pStrWalk - pSubStr, *pTxtWalk);
        nTextPos += nShift;
        pTextCmp += nShift;

        pMWalk += nShift;
        pMIter = pMWalk;
        pNWalk = pNValues + nSubStr - 1;
        pTxtWalk = pTextCmp;
        pStrWalk = pSubStrEnd;
#ifdef __STREE_DEBUG__
        cerr << "in ApostolicoGiancarlo::findNext(): case 1c." << endl;
#endif // __STREE_DEBUG__
      }
    }
    /*
     * If M(h) < Ni, then P matches its counterparts in T from position n down
     * to position i-M(h)+1 of P. By the definition of M(h), P might match more
     * of T to the left, so set i to i-M(h), set h to h-M(h), and repeat the
     * phase algorithm.
     */
    else if (*pMIter < *pNWalk)
    {
      nShift = *pMIter;
      pStrWalk -= nShift;
      pTxtWalk -= nShift;
      pMIter -= nShift;
      pNWalk -= nShift;
#ifdef __STREE_DEBUG__
      cerr << "in ApostolicoGiancarlo::findNext(): case 2." << endl;
#endif // __STREE_DEBUG__
    }
    /*
     * If M(h) >= Ni and Ni = i > 0, then declare that an occurence of P has 
     * been found in T ending in position j. M(j) must be set to a value less
     * than or equal to n. Set M(j) to j-h, and shift according to the 
     * Boyer-Moore rules based on finding an occurence of P ending at j (this 
     * ends the phase).
     */
    else if ((*pMIter >= *pNWalk) && (*pNWalk == (pNWalk - pNValues + 1)))
    {
      nShift = nTextPos;
      tShiftRule.shiftMatch(nTextPos);
      pTextCmp += nTextPos - nShift;
      *pMWalk = pMWalk - pMIter;
      pMWalk += nTextPos - nShift;
#ifdef __STREE_DEBUG__
      cerr << "in ApostolicoGiancarlo::findNext(): case 3 match found." << endl;
#endif // __STREE_DEBUG__
      return nShift;
    }
    /*
     * If M(h) > Ni and Ni < i, then P matches T from the right end of P down to
     * character i-Ni+1 of P, but the next pair of characters mismatch [i.e., 
     * P(i-Ni) != T(h-Ni)]. Hence P matches T for j-h+Ni characters and 
     * mismatches at position i-Ni of P. M(j) must be set to a value less than 
     * or equal to j-h+Ni. set M(j) to j-h. Shift P by the Boyer-Moore rules
     * based on a mismatch at position i-Ni of P (this ends the phase).
     */
    else if ((*pMIter > *pNWalk) && (*pNWalk < (pNWalk - pNValues + 1)))
    {
      *pMWalk = pMWalk - pMIter;

      nShift = tShiftRule.shift(pStrWalk - *pNWalk - pSubStr, 
                                *(pTxtWalk - *pNWalk));
      nTextPos += nShift;
      pTextCmp += nShift;

      pMWalk += nShift;
      pMIter = pMWalk;
      pNWalk = pNValues + nSubStr - 1;
      pTxtWalk = pTextCmp;
      pStrWalk = pSubStrEnd;
#ifdef __STREE_DEBUG__
      cerr << "in ApostolicoGiancarlo::findNext(): case 4." << endl;
#endif // __STREE_DEBUG__
    }
    /*
     * if M(h) = Ni and 0 < Ni < i, then P and T must match for at least M(h)
     * characters to the left, but the left end of P has not yet been reached, 
     * so set i to t-M(h) and set h to h-M(h) and repeat the phase algorithm.
     */
    else if ((*pMIter == *pNWalk) && (*pNWalk < (pNWalk - pNValues + 1)) 
             && (*pNWalk > 0))
    {
      nShift = *pMIter;
      pStrWalk -= nShift;
      pTxtWalk -= nShift;
      pMIter -= nShift;
      pNWalk -= nShift;
#ifdef __STREE_DEBUG__
      cerr << "in ApostolicoGiancarlo::findNext(): case 5." << endl;
#endif // __STREE_DEBUG__
    }
  }

  return -1;
}