QString TrustAI::askForKingdom() {
    QString role;
    ServerPlayer *lord = room->getLord();
    QStringList kingdoms = Sanguosha->getKingdoms();
    kingdoms.removeOne("god");
    if (!lord) return kingdoms.at(qrand() % kingdoms.length());

    switch(self->getRoleEnum()) {
    case Player::Lord: role = kingdoms.at(qrand() % kingdoms.length()); break;
    case Player::Renegade:
    case Player::Rebel: {
            if ((lord->hasLordSkill("xueyi") && self->getRoleEnum() == Player::Rebel) || lord->hasLordSkill("shichou"))
                role = "wei";
            else
                role = lord->getKingdom();
            break;
    }
    case Player::Loyalist: {
            if (lord->getGeneral()->isLord())
                role = lord->getKingdom();
            else if (lord->getGeneral2() && lord->getGeneral2()->isLord())
                role = lord->getGeneral2()->getKingdom();
            else {
                if (lord->hasSkill("yongsi")) kingdoms.removeOne(lord->getKingdom());
                role = kingdoms.at(qrand() % kingdoms.length());
            }
            break;
        }
    default:
            break;
    }

    return role;
}
Exemple #2
0
QString TrustAI::askForKingdom()
{
    QString role;
    ServerPlayer *lord = room->getLord();
    QStringList kingdoms = Sanguosha->getKingdoms();
    kingdoms.removeOne("zhu");
    kingdoms.removeOne("touhougod");
    QString selfKingdom = self->getGeneral()->getKingdom();
    if (!lord) return kingdoms.at(qrand() % kingdoms.length());

    switch (self->getRoleEnum()) {
    case Player::Lord: role = kingdoms.at(qrand() % kingdoms.length()); break;
    case Player::Renegade:{
        if (lord->getGeneral()->isLord() || self->hasSkill("hongfo"))
            role = lord->getKingdom();
        else if (lord->getGeneral2() && lord->getGeneral2()->isLord())
            role = lord->getGeneral2()->getKingdom();
        else
            role = kingdoms.at(qrand() % kingdoms.length());
        break;
    }
    case Player::Rebel: {
        if (self->hasSkill("hongfo")) {
            kingdoms.removeOne(lord->getKingdom());
            role = kingdoms.at(qrand() % kingdoms.length());
        } else if (lord->getGeneral()->isLord())
            role = lord->getKingdom();
        else
            role = kingdoms.at(qrand() % kingdoms.length());
        break;
    }
    case Player::Loyalist: {
        if (lord->getGeneral()->isLord() || self->hasSkill("hongfo"))
            role = lord->getKingdom();
        else if (lord->getGeneral2() && lord->getGeneral2()->isLord())
            role = lord->getGeneral2()->getKingdom();
        else {
            role = kingdoms.at(qrand() % kingdoms.length());
        }
        break;
    }
    default:
        break;
    }
    if (kingdoms.contains(role))
        return role;
    else
        return "wai";
}
QString GeneralSelector::selectFirst(ServerPlayer *player, const QStringList &candidates)
{
    QMap<QString, qreal> values;
    QString role = player->getRole();
    ServerPlayer *lord = player->getRoom()->getLord();
    foreach (QString candidate, candidates) {
        qreal value = 5.0;
        const General *general = Sanguosha->getGeneral(candidate);
        if (role == "loyalist" && lord && (general->getKingdom() == lord->getKingdom() || general->getKingdom() == "god"))
            value *= 1.04;
        if (role == "rebel" && lord && lord->getGeneral() && lord->getGeneral()->hasSkill("xueyi")
            && general->getKingdom() == "qun")
            value *= 0.8;
        if (role != "loyalist" && lord && lord->getGeneral() && lord->getGeneral()->hasSkill("shichou")
            && general->getKingdom() == "shu")
            value *= 0.1;
        if (role == "rebel" && lord && lord->getGeneral() && lord->getGeneral()->hasSkill("guiming")
            && general->getKingdom() == "wu")
            value *= 0.5;
        QString key = QString("_:%1:%2").arg(candidate).arg(role);
        value *= qPow(1.1, first_general_table.value(key, 0.0));
        if (lord) {
            QString key2 = QString("%1:%2:%3").arg(lord->getGeneralName()).arg(candidate).arg(role);
            value *= qPow(1.1, first_general_table.value(key2, 0.0));
        }
        values.insert(candidate, value);
    }
Exemple #4
0
QString TrustAI::askForKingdom()
{
    QString role;
    ServerPlayer *lord = room->getLord();
    QStringList kingdoms = Sanguosha->getKingdoms();
    kingdoms.removeOne("god");
    if (!lord) return kingdoms.at(qrand() % kingdoms.length());

    switch (self->getRoleEnum()) {
    case Player::Lord: role = kingdoms.at(qrand() % kingdoms.length()); break;
    case Player::Renegade:
    case Player::Rebel: {
            role = lord->getKingdom();
        break;
    }
    case Player::Loyalist: {
            role = kingdoms.at(qrand() % kingdoms.length());
        break;
    }
    default:
        break;
    }

    return role;
}
QString GeneralSelector::selectFirst(ServerPlayer *player, const QStringList &candidates){
    QString role = player->getRole();
    int seat = player->getSeat();
    int player_count = Sanguosha->getPlayerCount(player->getRoom()->getMode());
    int index = seat;
    if(player_count < 8 && seat == player_count)
        index = 8;
    else if(player_count > 8 && seat > 8)
        index = 8;

    int max = -1;
    QString max_general;

    qreal default_value;
    if(role == "loyalist")
        default_value = 6.5;
    else if(role == "rebel")
        default_value = 7.3;
    else
        default_value = 6.3;

    ServerPlayer *lord = player->getRoom()->getLord();
    QString lord_kingdom, suffix = QString();
    if(lord->getGeneral() && lord->getGeneral()->isLord()){
        lord_kingdom = lord->getKingdom();
        suffix = lord->getGeneralName();
    }

    foreach(QString candidate, candidates){
        QString key = QString("%1:%2:%3:%4").arg(candidate).arg(role).arg(index).arg(suffix);
        qreal value = first_general_table.value(key, default_value);

        if(!lord_kingdom.isNull() && (role == "loyalist" || role == "renegade")){
            const General *general = Sanguosha->getGeneral(candidate);
            if(general->getKingdom() == lord_kingdom)
                value += 0.5;
        }

        if(value > max){
            max = value;
            max_general = candidate;
        }
    }