예제 소스
장기로 이해하는 규칙 엔진과 평가 함수 탐색 · 파일 59개
SetupDialog.cpp
#include "SetupDialog.h"
#include <QCheckBox>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QFormLayout>
#include <QLabel>
#include <QPushButton>
#include <QSpinBox>
#include <QVBoxLayout>
SetupDialog::SetupDialog(QWidget* parent) : QDialog(parent) {
setWindowTitle(QStringLiteral("새 대국"));
setModal(true);
auto* layout = new QVBoxLayout(this);
auto* intro = new QLabel(QStringLiteral("상·마 배치를 고른 뒤 대국을 시작하세요. 초(楚)가 먼저 둡니다."));
intro->setWordWrap(true);
layout->addWidget(intro);
auto* form = new QFormLayout();
choFormation_ = new QComboBox;
hanFormation_ = new QComboBox;
for (Formation f : {Formation::InnerElephant, Formation::OuterElephant, Formation::LeftElephant,
Formation::RightElephant}) {
const QString name = QString::fromUtf8(formationNameKo(f));
choFormation_->addItem(name, static_cast<int>(f));
hanFormation_->addItem(name, static_cast<int>(f));
}
mode_ = new QComboBox;
mode_->addItem(QStringLiteral("사람과 컴퓨터 (내가 초)"), static_cast<int>(GameSettings::Mode::HumanCho));
mode_->addItem(QStringLiteral("사람과 컴퓨터 (내가 한)"), static_cast<int>(GameSettings::Mode::HumanHan));
mode_->addItem(QStringLiteral("사람과 사람"), static_cast<int>(GameSettings::Mode::HumanVsHuman));
depth_ = new QSpinBox;
depth_->setRange(1, 4);
depth_->setValue(3);
depth_->setSuffix(QStringLiteral(" 수 앞"));
bikjang_ = new QCheckBox(QStringLiteral("빅장이면 무승부 선언 가능"));
bikjang_->setChecked(true);
form->addRow(QStringLiteral("초 배치"), choFormation_);
form->addRow(QStringLiteral("한 배치"), hanFormation_);
form->addRow(QStringLiteral("대국 방식"), mode_);
form->addRow(QStringLiteral("컴퓨터 깊이"), depth_);
form->addRow(QString(), bikjang_);
layout->addLayout(form);
auto* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
buttons->button(QDialogButtonBox::Ok)->setText(QStringLiteral("대국 시작"));
buttons->button(QDialogButtonBox::Cancel)->setText(QStringLiteral("취소"));
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
layout->addWidget(buttons);
}
GameSettings SetupDialog::settings() const {
GameSettings s;
s.choFormation = static_cast<Formation>(choFormation_->currentData().toInt());
s.hanFormation = static_cast<Formation>(hanFormation_->currentData().toInt());
s.mode = static_cast<GameSettings::Mode>(mode_->currentData().toInt());
s.aiDepth = depth_->value();
s.bikjangEnabled = bikjang_->isChecked();
return s;
}