예제 #1
0
void OddsDialog::switchSides()
{
    QString left = leftSide->text();
    QString right = rightSide->text();
    // the method below will change the value of [left|right]Side
    updateLeftSide(left);
    updateRightSide(right);

    updateOdds();
}
예제 #2
0
void MapGenerator::processScanPoint(double start_x, double start_y, double angle, double distance) {
    // anti-aliased ray tracing, taken from:
    // http://en.wikipedia.org/wiki/Xiaolin_Wu%27s_line_algorithm
    double x0 = (start_x - x_min) / map_resolution;
    double y0 = (start_y - y_min) / map_resolution;

    // account for robot itself
    for (int i = -2; i <= 2; i++) {
        for (int j = -2; j <= 2; j++) {
            updateOdds(x0 + i, y0 + j, start_x, start_y, distance);
        }
    }

    double end_x = start_x + range_max * cos(angle);
    double end_y = start_y + range_max * sin(angle);
    double x1 = (end_x - x_min) / map_resolution;
    double y1 = (end_y - y_min) / map_resolution;

    double dx = x1 - x0;
    double dy = y1 - y0;
    bool steep = false;
    if (fabs(dx) < fabs(dy)) {
        swap(&x0, &y0);
        swap(&x1, &y1);
        swap(&dx, &dy);
        steep = true;
    }
    if (x1 < x0) {
        swap(&x0, &x1);
        swap(&y0, &y1);
    }
    double gradient = dy / dx;

    double xend = round(x0);
    double yend = y0 + gradient * (xend - x0);
    double xgap = rfpart(x0 + 0.5);
    int xpxl1 = (int) xend;
    int ypxl1 = (int) yend;

    if (steep) {
        updateOdds(ypxl1, xpxl1, start_x, start_y, distance);
        updateOdds(ypxl1+1, xpxl1, start_x, start_y, distance);
    } else {
        updateOdds(xpxl1, ypxl1, start_x, start_y, distance);
        updateOdds(xpxl1, ypxl1+1, start_x, start_y, distance);
    }
    double intery = yend + gradient;

    xend = round(x1);
    yend = y1 + gradient * (xend - x1);
    xgap = fpart(x1 + 0.5);
    int xpxl2 = (int) xend;
    int ypxl2 = (int) yend;
    // plot xpxl2, ypxl2, rfpart(yend) * xgap
    // plot xpxl2, ypxl2 + 1, fpart(yend) * xgap

    // main loop
    for (int x = xpxl1 + 1; x <= xpxl2 - 1; x++) {
        // plot x,
        if (steep) {
            updateOdds((int) intery, x, start_x, start_y, distance);
            updateOdds((int) (intery+1), x, start_x, start_y, distance);
        } else {
            updateOdds(x, (int) intery, start_x, start_y, distance);
            updateOdds(x, (int) (intery+1), start_x, start_y, distance);
        }
        intery += gradient;
    }
}
예제 #3
0
OddsDialog::OddsDialog(QWidget *parent)
    : QDialog(parent)
{
    setWindowTitle(tr("庄家总是稳赢不赔的啦"));
    vs = new QLabel(tr("VS"));

    leftSide = new QLineEdit;
    leftSide->setPlaceholderText(tr("左边"));
    rightSide = new QLineEdit;
    rightSide->setPlaceholderText(tr("右边"));
    leftMoney = new QLineEdit;
    leftMoney->setPlaceholderText(tr("注金"));
    rightMoney = new QLineEdit;
    rightMoney->setPlaceholderText(tr("注金"));

    dealer = new QLabel(tr("庄家抽成:"));
    fee = new QLineEdit;
    percent = new QLabel(tr("%"));

    switchBox = new QGroupBox(tr(""));
    leftVsRight = new QRadioButton(tr("左比右"));
    leftVsRight->setChecked(true);
    rightVsLeft = new QRadioButton(tr("右比左"));

    QHBoxLayout *groupBoxLayout = new QHBoxLayout;
    groupBoxLayout->addWidget(leftVsRight);
    groupBoxLayout->addStretch();
    groupBoxLayout->addWidget(rightVsLeft);
    switchBox->setLayout(groupBoxLayout);

    int eachSide = 150;
    firstSide = new QLabel(tr("左边"));
    setCenterAndFixedHalfSide(firstSide, eachSide);
    secondSide = new QLabel(tr("右边"));
    setCenterAndFixedHalfSide(secondSide, eachSide);
    oddsFirst = new QLabel(tr("1"));
    setCenterAndFixedHalfSide(oddsFirst, eachSide);
    compare = new QLabel(tr(":"));
    compare->setAlignment(Qt::AlignHCenter);
    oddsSecond = new QLabel(tr("1"));
    setCenterAndFixedHalfSide(oddsSecond, eachSide);

    QVBoxLayout *leftSideLayout = new QVBoxLayout;
    leftSideLayout->addWidget(leftSide);
    leftSideLayout->addWidget(leftMoney);
    QVBoxLayout *vsSideLayout = new QVBoxLayout;
    vsSideLayout->addWidget(vs);
    vsSideLayout->addStretch();
    QVBoxLayout *rightSideLayout = new QVBoxLayout;
    rightSideLayout->addWidget(rightSide);
    rightSideLayout->addWidget(rightMoney);
    QHBoxLayout *inputArea = new QHBoxLayout;
    inputArea->addLayout(leftSideLayout);
    inputArea->addLayout(vsSideLayout);
    inputArea->addLayout(rightSideLayout);

    QHBoxLayout *dealerArea = new QHBoxLayout;
    dealerArea->addWidget(dealer);
    dealerArea->addWidget(fee);
    dealerArea->addWidget(percent);

    QVBoxLayout *firstSideLayout = new QVBoxLayout;
    firstSideLayout->addWidget(firstSide);
    firstSideLayout->addWidget(oddsFirst);
    QVBoxLayout *compareSideLayout = new QVBoxLayout;
    compareSideLayout->addWidget(compare);
    compareSideLayout->addStretch();
    QVBoxLayout *secondSideLayout = new QVBoxLayout;
    secondSideLayout->addWidget(secondSide);
    secondSideLayout->addWidget(oddsSecond);
    QHBoxLayout *outputArea = new QHBoxLayout;
    outputArea->addLayout(firstSideLayout);
    outputArea->addLayout(compareSideLayout);
    outputArea->addLayout(secondSideLayout);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addLayout(inputArea);
    mainLayout->addLayout(dealerArea);
    mainLayout->addWidget(switchBox);
    mainLayout->addLayout(outputArea);

    setLayout(mainLayout);

    connect(leftSide, SIGNAL(textChanged(QString)),this,
            SLOT(updateLeftSide(QString)));
    connect(rightSide, SIGNAL(textChanged(QString)),this,
            SLOT(updateRightSide(QString)));

    connect(leftMoney, SIGNAL(textChanged(QString)), this, SLOT(updateOdds()));
    connect(rightMoney, SIGNAL(textChanged(QString)), this, SLOT(updateOdds()));
    connect(fee, SIGNAL(textChanged(QString)), this, SLOT(updateOdds()));

    connect(leftVsRight, SIGNAL(toggled(bool)), this, SLOT(switchSides()));
    connect(rightVsLeft, SIGNAL(toggled(bool)), this, SLOT(switchSides()));
}