Action SMDPAgent::startEpisode(const State &state, std::ostream &output)
{
	initialize(output);
	Action action = nextAction(state, output);
	applyAction(action, output);
	return action;
}
Action SMDPAgent::step(double reward, const State &state, std::ostream &output)
{
	giveReward(reward, output);
	Action action = nextAction(state, output);
	applyAction(action, output);
	return action;
}
예제 #3
0
void G2oQGLViewer::draw()
{
  if (! graph)
    return;

  if (_drawActions == 0) {
    _drawActions = HyperGraphActionLibrary::instance()->actionByName("draw");
    assert(_drawActions);
  }
  
  if (_updateDisplay) {
    _updateDisplay = false;
    glNewList(_drawList, GL_COMPILE_AND_EXECUTE);
    applyAction(graph, _drawActions, _drawActionParameters);
    glEndList();
  } else {
    glCallList(_drawList); 
  }
}
예제 #4
0
void Environment3D::getSuccessors(SearchState3D *s,
                                  std::vector<SearchState3D *> &successors,
                                  std::vector<double> &costs)
{
    if(actionSet_.empty())
        generateActionSet();
    
    Transform3D sT = s->getValue();
    
    if(states_.get(sT) == nullptr)
        states_.insert(s);
    
//    Timer timer;
//    timer.start();
    
    for(auto action : actionSet_)
    {
        // Generate the successor transform by applying an action to the current state
        Transform3D T = sT;
        applyAction(action, T);
        
        SearchState3D *neighbor = states_.get(T);
        if(neighbor == nullptr)
        {
            // Has not seen this state yet
            neighbor = new SearchState3D();
            neighbor->setValue(T);
            states_.insert(neighbor);
        }
        
        successors.push_back(neighbor);
        costs.push_back(action.getCost());
    }
    
//    std::cout << "Successor generation took "
//    << GET_ELAPSED_MICRO(timer) << " microseconds" << std::endl;
}
예제 #5
0
void Player::makeMove() {
  vector<Vec2> squareDirs = creature->getConstSquare()->getTravelDir();
  const vector<Creature*>& creatures = creature->getLevel()->getAllCreatures();
  if (creature->isAffected(Creature::HALLU))
    ViewObject::setHallu(true);
  else
    ViewObject::setHallu(false);
  MEASURE(
      model->getView()->refreshView(creature),
      "level render time");
  if (Options::getValue(OptionId::HINTS) && displayTravelInfo && creature->getConstSquare()->getName() == "road") {
    model->getView()->presentText("", "Use ctrl + arrows to travel quickly on roads and corridors.");
    displayTravelInfo = false;
  }
  static bool greeting = false;
  if (Options::getValue(OptionId::HINTS) && displayGreeting) {
    CHECK(creature->getFirstName());
    model->getView()->presentText("", "Dear " + *creature->getFirstName() + ",\n \n \tIf you are reading this letter, then you have arrived in the valley of " + NameGenerator::worldNames.getNext() + ". There is a band of dwarves dwelling in caves under a mountain. Find them, talk to them, they will help you. Let your sword guide you.\n \n \nYours, " + NameGenerator::firstNames.getNext() + "\n \nPS.: Beware the goblins!");
    model->getView()->presentText("", "Every settlement that you find has a leader, and they may have quests for you."
        "\n \nYou can turn these messages off in the options (press F2).");
    displayGreeting = false;
    model->getView()->refreshView(creature);
  }
  for (const Creature* c : creature->getVisibleEnemies()) {
    if (c->isSpecialMonster() && !contains(specialCreatures, c)) {
      privateMessage(MessageBuffer::important(c->getDescription()));
      model->getView()->refreshView(creature);
      specialCreatures.push_back(c);
    }
  }
  if (travelling)
    travelAction();
  else if (target)
    targetAction();
  else {
    Action action = model->getView()->getAction();
  vector<Vec2> direction;
  bool travel = false;
  switch (action.getId()) {
    case ActionId::FIRE: fireAction(action.getDirection()); break;
    case ActionId::TRAVEL: travel = true;
    case ActionId::MOVE: direction.push_back(action.getDirection()); break;
    case ActionId::MOVE_TO: if (action.getDirection().dist8(creature->getPosition()) == 1) {
                              Vec2 dir = action.getDirection() - creature->getPosition();
                              if (const Creature* c = creature->getConstSquare(dir)->getCreature()) {
                                if (!creature->isEnemy(c)) {
                                  chatAction(dir);
                                  break;
                                }
                              }
                              direction.push_back(dir);
                            } else
                            if (action.getDirection() != creature->getPosition()) {
                              target = action.getDirection();
                              target = Vec2(min(creature->getLevel()->getBounds().getKX() - 1, max(0, target->x)),
                                  min(creature->getLevel()->getBounds().getKY() - 1, max(0, target->y)));
                              // Just in case
                              if (!target->inRectangle(creature->getLevel()->getBounds()))
                                target = Nothing();
                            }
                            else
                              pickUpAction(false);
                            break;
    case ActionId::SHOW_INVENTORY: displayInventory(); break;
    case ActionId::PICK_UP: pickUpAction(false); break;
    case ActionId::EXT_PICK_UP: pickUpAction(true); break;
    case ActionId::DROP: dropAction(false); break;
    case ActionId::EXT_DROP: dropAction(true); break;
    case ActionId::WAIT: creature->wait(); break;
    case ActionId::APPLY_ITEM: applyAction(); break; 
    case ActionId::THROW: throwAction(); break;
    case ActionId::THROW_DIR: throwAction(action.getDirection()); break;
    case ActionId::EQUIPMENT: equipmentAction(); break;
    case ActionId::HIDE: hideAction(); break;
    case ActionId::PAY_DEBT: payDebtAction(); break;
    case ActionId::CHAT: chatAction(); break;
    case ActionId::SHOW_HISTORY: messageBuffer.showHistory(); break;
    case ActionId::UNPOSSESS: if (creature->canPopController()) {
                                creature->popController();
                                return;
                              } break;
    case ActionId::CAST_SPELL: spellAction(); break;
    case ActionId::DRAW_LEVEL_MAP: model->getView()->drawLevelMap(creature); break;
    case ActionId::EXIT: model->exitAction(); break;
    case ActionId::IDLE: break;
  }
  if (creature->isAffected(Creature::SLEEP) && creature->canPopController()) {
    if (model->getView()->yesOrNoPrompt("You fell asleep. Do you want to leave your minion?"))
      creature->popController();
    return;
  }
  for (Vec2 dir : direction)
    if (travel) {
      vector<Vec2> squareDirs = creature->getConstSquare()->getTravelDir();
      if (findElement(squareDirs, dir)) {
        travelDir = dir;
        lastLocation = creature->getLevel()->getLocation(creature->getPosition());
        travelling = true;
        travelAction();
      }
    } else
    if (creature->canMove(dir)) {
      creature->move(dir);
      itemsMessage();
      break;
    } else {
      const Creature *c = creature->getConstSquare(dir)->getCreature();
      if (creature->canBumpInto(dir)) {
        creature->bumpInto(dir);
        break;
      } else 
      if (creature->canDestroy(dir)) {
        privateMessage("You bash the " + creature->getSquare(dir)->getName());
        creature->destroy(dir);
        break;
      }
    }
  }
  for (Vec2 pos : creature->getLevel()->getVisibleTiles(creature)) {
    ViewIndex index = creature->getLevel()->getSquare(pos)->getViewIndex(creature);
    (*levelMemory)[creature->getLevel()].clearSquare(pos);
    for (ViewLayer l : { ViewLayer::ITEM, ViewLayer::FLOOR_BACKGROUND, ViewLayer::FLOOR, ViewLayer::LARGE_ITEM})
      if (index.hasObject(l))
        remember(pos, index.getObject(l));
  }
}
예제 #6
0
void ComponentMovement::handleActionPerformAction( const ActionPerformAction *action ) {
	applyAction(action->action);
}
/* This function loads the xml-database and the journalfile */
bool OPimContactAccessBackend_XML::loadXml( XMLElement *root, bool isJournal )
{
    OPimRecord::ChangeAction action = OPimRecord::ACTION_ADD;
    QMap<int, QString> contactMap;
    QMap<QString, QString> customMap;
    QMap<QString, QString>::Iterator customIt;
    QAsciiDict<int> dict( 47 );
    initDict( dict );

    if(root != 0l ) { // start parsing
        /* Parse all XML-Elements and put the data into the
         * Contact-Class
         */
        XMLElement *element = root->firstChild();
        element = element ? element->firstChild() : 0;

        m_journalEnabled = false;
        
        /* Search Tag "Contacts" which is the parent of all Contacts */
        while( element && !isJournal ) {
            if( element->tagName() != QString::fromLatin1("Contacts") ) {
                element = element->nextChild();
            }
            else {
                element = element->firstChild();
                break;
            }
        }
        /* Parse all Contacts and ignore unknown tags */
        while( element ) {
            if( element->tagName() != QString::fromLatin1("Contact") ) {
                element = element->nextChild();
                continue;
            }
            /* Found alement with tagname "contact", now parse and store all
             * attributes contained
             */
            QString dummy;
            action = OPimRecord::ACTION_ADD;

            XMLElement::AttributeMap aMap = element->attributes();
            XMLElement::AttributeMap::Iterator it;
            contactMap.clear();
            customMap.clear();
            for( it = aMap.begin(); it != aMap.end(); ++it ) {
                int *find = dict[ it.key() ];
                /* Unknown attributes will be stored as "Custom" elements */
                if ( !find ) {
                    //contact.setCustomField(it.key(), it.data());
                    customMap.insert( it.key(),  it.data() );
                    continue;
                }

                /* Check if special conversion is needed and add attribute
                 * into Contact class
                 */
                switch( *find ) {
                    /*
                      case Qtopia::AddressUid:
                      contact.setUid( it.data().toInt() );
                      break;
                      case Qtopia::AddressCategory:
                      contact.setCategories( Qtopia::Record::idsFromString( it.data( )));
                      break;
                    */
                case FIELDID_ACTION:
                    action = OPimRecord::ChangeAction(it.data().toInt());
                    owarn << "ODefBack(journal)::ACTION found: " << action << oendl;
                    break;
                default: // no conversion needed add them to the map
                    contactMap.insert( *find, it.data() );
                    break;
                }
            }
            /* now generate the Contact contact */
            OPimContact contact( contactMap );

            for (customIt = customMap.begin(); customIt != customMap.end(); ++customIt ) {
                contact.setCustomField( customIt.key(),  customIt.data() );
            }

            applyAction( action, contact );

            /* Move to next element */
            element = element->nextChild();
        }

        m_journalEnabled = true;
        
        return true;
    }
    else {
        owarn << "XML document null!" << oendl;
        return false;
    }
}