Exemplo n.º 1
0
  uptr<Action> chooseAction(State* state) {
    if (!haveSeenState(state)) {
      handleNewState(state);
    }

    return chooseActionForState(state);
  }
Exemplo n.º 2
0
void GameClient::connectToServer(QString host, int port)
{
    QString ipAddress;
    QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
    // use the first non-localhost IPv4 address
    for(int i = 0; i < ipAddressesList.size(); ++i) {
        if(ipAddressesList.at(i) != QHostAddress::LocalHost &&
           ipAddressesList.at(i).toIPv4Address()) {
            ipAddress = ipAddressesList.at(i).toString();
            break;
        }
    }

    m_connection = new Connection(Connection::Client);

    // bind the connection to a certain port
    int i = 0;
    bool ok;
    do {
        i ++;
        ok = m_connection->bind(QHostAddress(ipAddress), StartBindPort+1000*i);
    } while(!ok);
    m_connBindPort = StartBindPort + 1000 * i;
    m_connection->connectToHost(host, port);
    // each connection use the same port as first time

    connect(m_connection, SIGNAL(newGreeting(QByteArray)), this, SLOT(handleNewGreeting(QByteArray)));
    connect(m_connection, SIGNAL(newState(QByteArray)), this, SLOT(handleNewState(QByteArray)));
    connect(m_connection, SIGNAL(newBackupServer(QByteArray)), this, SLOT(handleNewBackupServer(QByteArray)));
    connect(this, SIGNAL(haveMessageToSend(Connection::DataType,QByteArray)), m_connection, SLOT(sendMessage(Connection::DataType,QByteArray)));

    emit newPrimaryServerInfo(host+','+QString::number(port));
}
Exemplo n.º 3
0
/**
 * @brief SCGraphicsView::createGraph
 * add all states and transitions to the graphics view
 */
void SCGraphicsView::createGraph()
{
    QList<SCState*> states;
    _dm->getAllStates(states);

    // connect the top state
    connectState(_dm->getTopState());

    // first load all states
    for(int s = 0; s < states.count(); s++)
    {
        handleNewState(states[s]);
    }

    // load all transitions
    for(int i = 0; i< states.count(); i++)
    {
        QList<SCTransition*> transitions;
        states[i]->getTransitions(transitions);

        for(int t = 0; t < transitions.count(); t ++)
        {
            handleNewTransition(transitions[t]);
        }
    }
}
Exemplo n.º 4
0
  void ActionOutcome(pair<State *, Action *> performed, pair<State *, double> outcome) {
    State *startState = performed.first;
    Action *actionPerformed = performed.second;

    State *resultState = outcome.first;
    double reward = outcome.second;

    if (!haveSeenState(startState)) {
      handleNewState(startState);
    }

    if (!haveSeenState(resultState)) {
      handleNewState(resultState);
    }

    ActionValue *curValue = findActionValue(startState, actionPerformed);
    assert(curValue != nullptr);

    double newQ = reward + futureDiscount * maxQ(resultState);
    // cout << "r: " << reward << " fd: " << futureDiscount << " newQ: " << newQ << endl;
    curValue->value += learnRate * (newQ - curValue->value);
    // cout << "v : " << curValue->value << endl;
    // getchar();
  }
Exemplo n.º 5
0
  void actionOutcome(pair<State*, Action*> performed, pair<State*, double> outcome) {
    State *startState = performed.first;
    Action *actionPerformed = performed.second;

    State *resultState = outcome.first;
    double reward = outcome.second;

    assert(haveSeenState(startState));

    if (!haveSeenState(resultState)) {
      handleNewState(resultState);
    }

    ActionValue *curValue = findActionValue(startState, actionPerformed);
    assert(curValue != nullptr);

    double newQ = reward + futureDiscount * maxQ(resultState);
    curValue->value += learnRate * (newQ - curValue->value);
  }