Beispiel #1
0
void LBattery::updateBattery(bool force){
  // Get current state of charge
  //QStringList result = LUtils::getCmdOutput("/usr/sbin/apm", QStringList() << "-al");
  int charge = LOS::batteryCharge(); //result.at(1).toInt();
//qDebug() << "1: " << result.at(0).toInt() << " 2: " << result.at(1).toInt();
  int icon = -1;
  if (charge > 90) { icon = 4; }
  else if (charge > 70) { icon = 3; }
  else if (charge > 50) { icon = 2; }
  else if (charge > 30) { icon = 1; }
  else if (charge > 0 ) { icon = 0; }
  if(LOS::batteryIsCharging()){ icon = icon+10; }
  //icon = icon + result.at(0).toInt() * 10;
  if (icon != iconOld || force) {
    switch (icon) {
      case 0:
        label->setPixmap( LXDG::findIcon("battery-caution", "").pixmap(label->size()) );
        break;
      case 1:
        label->setPixmap( LXDG::findIcon("battery-040", "").pixmap(label->size()) );
        break;
      case 2:
        label->setPixmap( LXDG::findIcon("battery-060", "").pixmap(label->size()) );
        break;
      case 3:
        label->setPixmap( LXDG::findIcon("battery-080", "").pixmap(label->size()) );
        break;
      case 4:
        label->setPixmap( LXDG::findIcon("battery-100", "").pixmap(label->size()) );
        break;
      case 10:
        label->setPixmap( LXDG::findIcon("battery-charging-caution", "").pixmap(label->size()) );
        break;
      case 11:
        label->setPixmap( LXDG::findIcon("battery-charging-040", "").pixmap(label->size()) );
        break;
      case 12:
        label->setPixmap( LXDG::findIcon("battery-charging-060", "").pixmap(label->size()) );
        break;
      case 13:
        label->setPixmap( LXDG::findIcon("battery-charging-080", "").pixmap(label->size()) );
        break;
      case 14:
        label->setPixmap( LXDG::findIcon("battery-charging", "").pixmap(label->size()) );
        break;
      default:
        label->setPixmap( LXDG::findIcon("battery-missing", "").pixmap(label->size()) );
        break;
    }
    iconOld = icon;
  }
  //Now update the display
  QString tt;
  //Make sure the tooltip can be properly translated as necessary (Ken Moore 5/9/14)
  if(icon > 9 && icon < 15){ tt = QString(tr("%1 % (Charging)")).arg(QString::number(charge)); }
  else{ tt = QString( tr("%1 % (%2 Remaining)") ).arg(QString::number(charge), getRemainingTime() ); }
  label->setToolTip(tt);
}
/*
 * If seconds == 0, reset the timeout to the last one set
 * If seconds  < 0, set the timeout to -seconds if there's less than
 *                  -seconds remaining.
 * If seconds  > 0, set the timeout to seconds.
 */
void RequestInjectionData::resetTimer(int seconds /* = 0 */) {
  if (seconds == 0) {
    seconds = getTimeout();
  } else if (seconds < 0) {
    if (!getTimeout()) return;
    seconds = -seconds;
    if (seconds < getRemainingTime()) return;
  }
  setTimeout(seconds);
  clearFlag(TimedOutFlag);
}
Beispiel #3
0
/*
 * If seconds == 0, reset the timeout to the last one set
 * If seconds  < 0, set the timeout to -seconds if there's less than
 *                  -seconds remaining.
 * If seconds  > 0, set the timeout to seconds.
 */
void RequestInjectionData::resetTimer(int seconds /* = 0 */) {
  auto data = &ThreadInfo::s_threadInfo->m_reqInjectionData;
  if (seconds == 0) {
    seconds = data->getTimeout();
  } else if (seconds < 0) {
    if (!data->getTimeout()) return;
    seconds = -seconds;
    if (seconds < data->getRemainingTime()) return;
  }
  data->setTimeout(seconds);
  data->clearTimedOutFlag();
}
deque<int> TimedAlphaBetaPlayer::getPitWithMaximumGain(MancalaBoard* board)
{
    deque<int> movesGlobal;
    int depthCovered = 0;
    unsigned long long depthCoveredTime = k_timeLimitPerMove;
    unsigned long long lastDepthCoveredTime = k_timeLimitPerMove;
    
    int maxGainPitIndexLocal = -1;
    deque<int> movesLocal;
    
    m_startTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
    
    for (int depth = 1; depth < m_maxDepth && getRemainingTime() > m_timeTolerance; depth++)
    {
        board->setCutOffDepth(depth);
        board->m_alpha = INT_MIN;
        board->m_beta = INT_MAX;
        board->m_expectedValue = INT_MIN;
        
        movesGlobal = movesLocal;
        depthCovered = depth - 1;
        lastDepthCoveredTime = depthCoveredTime;
        depthCoveredTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count() - m_startTime;
        
        for(int pitIndex = 0; pitIndex < board->getNumPitsPerPlayer() && getRemainingTime() > m_timeTolerance; pitIndex++)
        {
            if (!board->isPitValid(pitIndex))
                continue;
            
            MancalaBoard* clonedBoard = board->clone();
            clonedBoard->play(pitIndex);
            clonedBoard->setGameIndex(pitIndex);
            clonedBoard->setPreviousPlayer( board->getCurrentPlayer() );
            clonedBoard->m_alpha = board->m_alpha;
            clonedBoard->m_beta = board->m_beta;
            
            initIsGrouped(clonedBoard);
            
            clonedBoard->setGameDepth(board->getGameDepth() + 1);
            
            initExpectedValue(clonedBoard);
            
            int gain = getExpectedValue(clonedBoard);
            
            if (gain > board->m_expectedValue)
            {
                board->m_expectedValue = gain;
                if (getMinOrMaxPlayer(board->getCurrentPlayer()) == MAX)
                {
                    if (board->m_expectedValue >= board->m_beta)
                    {
                        movesLocal = clonedBoard->m_bonusMoves;
                        movesLocal.push_front(maxGainPitIndexLocal);
                        
                        delete clonedBoard;
                        clonedBoard = NULL;
                        
                        break;
                    }
                    board->m_alpha = std::max(board->m_alpha, board->m_expectedValue);
                }
                else
                {
                    if (board->m_expectedValue <= board->m_alpha)
                    {
                        movesLocal = clonedBoard->m_bonusMoves;
                        movesLocal.push_front(maxGainPitIndexLocal);
                        
                        delete clonedBoard;
                        clonedBoard = NULL;
                        
                        break;
                    }
                    board->m_beta = std::min(board->m_beta, board->m_expectedValue);
                }
                
                maxGainPitIndexLocal = pitIndex;
                movesLocal = clonedBoard->m_bonusMoves;
                movesLocal.push_front(maxGainPitIndexLocal);
            }
            
            delete clonedBoard;
            clonedBoard = NULL;
        }
    }
    return movesGlobal;
}
int TimedAlphaBetaPlayer::getExpectedValue(MancalaBoard* board)
{
    if ((board->getGameDepth() == board->getCutOffDepth() &&
         board->getPreviousPlayer() != board->getCurrentPlayer()) ||
        board->isGameOver()) {
        return board->m_expectedValue;
    }
    
    for(int pitIndex = 0; pitIndex < board->getNumPitsPerPlayer() && getRemainingTime() > m_timeTolerance; pitIndex++)
    {
        if (!board->isPitValid(pitIndex))
            continue;
        
        MancalaBoard* clonedBoard = board->clone();
        clonedBoard->play(pitIndex);
        clonedBoard->setGameIndex(pitIndex);
        clonedBoard->setPreviousPlayer( board->getCurrentPlayer() );
        clonedBoard->m_alpha = board->m_alpha;
        clonedBoard->m_beta = board->m_beta;
        
        initIsGrouped(clonedBoard);
        
        initGameDepth(board, clonedBoard);
        
        initExpectedValue(clonedBoard);
        
        int clonedNodeExpectedValue = getExpectedValue(clonedBoard);
        
        if (getMinOrMaxPlayer(board->getCurrentPlayer()) == MAX)
        {
            if (clonedNodeExpectedValue > board->m_expectedValue)
            {
                board->m_expectedValue = clonedNodeExpectedValue;
                percolateBonusMovesUp(board, clonedBoard);
            }
            
            if (board->m_expectedValue >= board->m_beta)
            {
                delete clonedBoard;
                clonedBoard = NULL;
                
                return board->m_expectedValue;
            }
            board->m_alpha = std::max(board->m_alpha, board->m_expectedValue);
        }
        else
        {
            if (clonedNodeExpectedValue < board->m_expectedValue) {
                board->m_expectedValue = clonedNodeExpectedValue;
                percolateBonusMovesUp(board, clonedBoard);
            }
            
            if (board->m_expectedValue <= board->m_alpha)
            {
                delete clonedBoard;
                clonedBoard = NULL;
                return board->m_expectedValue;
            }
            board->m_beta = std::min(board->m_beta, board->m_expectedValue);
        }
        
        delete clonedBoard;
        clonedBoard = NULL;
    }
    
    return board->m_expectedValue;
}