Async ai + option dialog + board background
parent
a1bac12ede
commit
39c3cde25e
Binary file not shown.
After Width: | Height: | Size: 581 B |
Binary file not shown.
After Width: | Height: | Size: 581 B |
Binary file not shown.
After Width: | Height: | Size: 92 KiB |
Binary file not shown.
After Width: | Height: | Size: 53 KiB |
@ -0,0 +1,81 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2009 by Stefan Bühler *
|
||||
* stbuehler@web.de *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#include "optiondlg.h"
|
||||
#include <QPushButton>
|
||||
|
||||
namespace toruschess {
|
||||
|
||||
OptionDlg::OptionDlg(Game *game, QWidget *parent)
|
||||
: QDialog(parent), m_game(game) {
|
||||
m_curMode = m_game->gameMode();
|
||||
m_curAIStrength = m_game->aiStrength();
|
||||
setupUi(this);
|
||||
|
||||
m_bgMode = new QButtonGroup(this);
|
||||
m_bgMode->addButton(rb_mode1, HUMAN_HUMAN);
|
||||
m_bgMode->addButton(rb_mode2, HUMAN_COMPUTER);
|
||||
m_bgMode->addButton(rb_mode3, COMPUTER_HUMAN);
|
||||
m_bgMode->addButton(rb_mode4, COMPUTER_COMPUTER);
|
||||
|
||||
dlgReset();
|
||||
|
||||
connect(m_game, SIGNAL(changedMode(GameMode)), this, SLOT(gameChangedMode(GameMode)));
|
||||
connect(m_game, SIGNAL(changedAIStrength(int)), this, SLOT(gameChangedAIStrength(int)));
|
||||
|
||||
connect(this, SIGNAL(accepted()), this, SLOT(dlgAccept()));
|
||||
connect(this, SIGNAL(rejected()), this, SLOT(dlgReset()));
|
||||
|
||||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
connect(buttonBox->button(QDialogButtonBox::Reset), SIGNAL(clicked()), this, SLOT(dlgReset()));
|
||||
}
|
||||
|
||||
void OptionDlg::gameChangedMode(GameMode mode) {
|
||||
if (m_curMode != mode) {
|
||||
if (m_bgMode->checkedId() == m_curMode) {
|
||||
m_bgMode->button(mode)->setChecked(true);
|
||||
}
|
||||
m_curMode = mode;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionDlg::gameChangedAIStrength(int aiStrength) {
|
||||
if (m_curAIStrength != aiStrength) {
|
||||
if (sb_aiStrength->value() == m_curAIStrength) {
|
||||
sb_aiStrength->setValue(aiStrength);
|
||||
}
|
||||
m_curAIStrength = aiStrength;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionDlg::dlgReset() {
|
||||
sb_aiStrength->setValue(m_curAIStrength);
|
||||
m_bgMode->button(m_curMode)->setChecked(true);
|
||||
}
|
||||
|
||||
void OptionDlg::dlgAccept() {
|
||||
m_curAIStrength = sb_aiStrength->value();
|
||||
m_game->setAiStrength(m_curAIStrength);
|
||||
m_curMode = (GameMode) m_bgMode->checkedId();
|
||||
m_game->setGameMode(m_curMode);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2009 by Stefan Bühler *
|
||||
* stbuehler@web.de *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
#ifndef TORUSCHESSOPTIONDLG_H
|
||||
#define TORUSCHESSOPTIONDLG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QButtonGroup>
|
||||
#include "ui_optiondlg.h"
|
||||
|
||||
#include "toruschess.h"
|
||||
|
||||
/**
|
||||
@author Stefan Bühler <stbuehler@web.de>
|
||||
*/
|
||||
namespace toruschess {
|
||||
class OptionDlg : public QDialog, private Ui::OptionDlg {
|
||||
Q_OBJECT
|
||||
public:
|
||||
OptionDlg(Game *game, QWidget *parent = 0);
|
||||
|
||||
private slots:
|
||||
void gameChangedMode(GameMode mode);
|
||||
void gameChangedAIStrength(int aiStrength);
|
||||
|
||||
void dlgReset();
|
||||
void dlgAccept();
|
||||
|
||||
private:
|
||||
Game *m_game;
|
||||
GameMode m_curMode;
|
||||
int m_curAIStrength;
|
||||
QButtonGroup *m_bgMode;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,123 @@
|
||||
<ui version="4.0" >
|
||||
<class>OptionDlg</class>
|
||||
<widget class="QWidget" name="OptionDlg" >
|
||||
<property name="windowModality" >
|
||||
<enum>Qt::ApplicationModal</enum>
|
||||
</property>
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>373</width>
|
||||
<height>227</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<string>Options</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout" >
|
||||
<item row="0" column="0" colspan="2" >
|
||||
<widget class="QGroupBox" name="groupBox" >
|
||||
<property name="title" >
|
||||
<string>Opponent</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2" >
|
||||
<item>
|
||||
<widget class="QRadioButton" name="rb_mode1" >
|
||||
<property name="text" >
|
||||
<string>Human vs. Human</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="rb_mode2" >
|
||||
<property name="text" >
|
||||
<string>Human vs. Computer</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="rb_mode3" >
|
||||
<property name="text" >
|
||||
<string>Computer vs. Human</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="rb_mode4" >
|
||||
<property name="text" >
|
||||
<string>Computer vs. Computer</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" >
|
||||
<property name="sizeConstraint" >
|
||||
<enum>QLayout::SetMinimumSize</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Minimum" hsizetype="Preferred" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>Computer strength (recursion depth)</string>
|
||||
</property>
|
||||
<property name="buddy" >
|
||||
<cstring>sb_aiStrength</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer" >
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0" >
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="sb_aiStrength" >
|
||||
<property name="alignment" >
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="minimum" >
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="maximum" >
|
||||
<number>7</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" >
|
||||
<widget class="QDialogButtonBox" name="buttonBox" >
|
||||
<property name="standardButtons" >
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>rb_mode1</tabstop>
|
||||
<tabstop>rb_mode2</tabstop>
|
||||
<tabstop>rb_mode3</tabstop>
|
||||
<tabstop>rb_mode4</tabstop>
|
||||
<tabstop>sb_aiStrength</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in New Issue