mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-12-25 21:59:30 +01:00
Topping: integrate hints
This commit is contained in:
parent
b80ca397ad
commit
7cd6313dac
7 changed files with 78 additions and 27 deletions
|
@ -261,6 +261,12 @@ vector<Move> PublicGame::toppingGetTriedMoves() const
|
|||
return getTypedGame<Topping>(m_game).getTriedMoves();
|
||||
}
|
||||
|
||||
|
||||
Move PublicGame::toppingGetTopMove() const
|
||||
{
|
||||
return getTypedGame<Topping>(m_game).getTopMove();
|
||||
}
|
||||
|
||||
/***************************/
|
||||
|
||||
void PublicGame::duplicateSetPlayer(unsigned int p)
|
||||
|
|
|
@ -222,6 +222,8 @@ public:
|
|||
|
||||
vector<Move> toppingGetTriedMoves() const;
|
||||
|
||||
Move toppingGetTopMove() const;
|
||||
|
||||
/***************
|
||||
* Duplicate games
|
||||
* These methods throw an exception if the current game is not in
|
||||
|
|
|
@ -171,17 +171,19 @@ void Topping::addPlayer(Player *iPlayer)
|
|||
}
|
||||
|
||||
|
||||
int Topping::getTopScore() const
|
||||
Move Topping::getTopMove() const
|
||||
{
|
||||
BestResults results;
|
||||
results.search(getDic(), getBoard(), m_players[0]->getCurrentRack().getRack(),
|
||||
getHistory().beforeFirstRound());
|
||||
if (results.size() == 0)
|
||||
{
|
||||
// Just to be safe
|
||||
return -1;
|
||||
ASSERT(results.size() != 0, "No top move found");
|
||||
return Move(results.get(0));
|
||||
}
|
||||
return results.get(0).getPoints();
|
||||
|
||||
|
||||
int Topping::getTopScore() const
|
||||
{
|
||||
return getTopMove().getScore();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -72,6 +72,11 @@ public:
|
|||
*/
|
||||
vector<Move> getTriedMoves() const;
|
||||
|
||||
/**
|
||||
* Return the best possible move (or one of them, if there are several ones).
|
||||
*/
|
||||
Move getTopMove() const;
|
||||
|
||||
private:
|
||||
/// Private constructor and destructor to force using the GameFactory class
|
||||
Topping(const GameParams &iParams, const Game *iMasterGame);
|
||||
|
@ -86,7 +91,6 @@ private:
|
|||
|
||||
/**
|
||||
* Return the score of the top move.
|
||||
* If no move is possible at all, return -1.
|
||||
*/
|
||||
int getTopScore() const;
|
||||
|
||||
|
|
|
@ -24,12 +24,14 @@
|
|||
#include <QtGui/QSortFilterProxyModel>
|
||||
|
||||
#include "topping_widget.h"
|
||||
#include "qtcommon.h"
|
||||
#include "play_word_mediator.h"
|
||||
#include "hints_dialog.h"
|
||||
#include "qtcommon.h"
|
||||
|
||||
#include "player.h"
|
||||
#include "hints.h"
|
||||
#include "dic.h"
|
||||
#include "move.h"
|
||||
#include "pldrack.h"
|
||||
#include "public_game.h"
|
||||
#include "game_exception.h"
|
||||
#include "debug.h"
|
||||
|
@ -44,7 +46,10 @@ ToppingWidget::ToppingWidget(QWidget *parent, PlayModel &iPlayModel, PublicGame
|
|||
: QWidget(parent), m_game(iGame), m_autoResizeColumns(true)
|
||||
{
|
||||
setupUi(this);
|
||||
tableViewMoves->setAlternatingRowColors(true);
|
||||
|
||||
m_hintsDialog = new HintsDialog(this);
|
||||
QObject::connect(m_hintsDialog, SIGNAL(hintUsed(const AbstractHint&)),
|
||||
this, SLOT(hintUsed(const AbstractHint&)));
|
||||
|
||||
blackPalette = lineEditRack->palette();
|
||||
redPalette = lineEditRack->palette();
|
||||
|
@ -90,6 +95,9 @@ ToppingWidget::ToppingWidget(QWidget *parent, PlayModel &iPlayModel, PublicGame
|
|||
|
||||
tableViewMoves->horizontalHeader()->resizeSection(1, 140);
|
||||
|
||||
QObject::connect(pushButtonGetHints, SIGNAL(clicked()),
|
||||
this, SLOT(showHintsDialog()));
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
@ -105,7 +113,7 @@ void ToppingWidget::refresh()
|
|||
}
|
||||
else
|
||||
{
|
||||
wstring rack = m_game->getPlayer(0).getCurrentRack().toString(PlayedRack::RACK_SIMPLE);
|
||||
wstring rack = m_game->getCurrentRack().toString(PlayedRack::RACK_SIMPLE);
|
||||
// Update the rack only if it is needed, to avoid losing cursor position
|
||||
if (qfw(rack) != lineEditRack->text())
|
||||
lineEditRack->setText(qfw(rack));
|
||||
|
@ -164,6 +172,22 @@ void ToppingWidget::lockSizesChanged(bool checked)
|
|||
}
|
||||
|
||||
|
||||
void ToppingWidget::showHintsDialog()
|
||||
{
|
||||
const Move &move = m_game->toppingGetTopMove();
|
||||
m_hintsDialog->setMove(move);
|
||||
// We don't care about the return value
|
||||
m_hintsDialog->exec();
|
||||
}
|
||||
|
||||
|
||||
void ToppingWidget::hintUsed(const AbstractHint &iHint)
|
||||
{
|
||||
// TODO
|
||||
LOG_INFO("Hint " << iHint.getName() << " used for a cost of " << iHint.getCost());
|
||||
}
|
||||
|
||||
|
||||
QSize ToppingWidget::sizeHint() const
|
||||
{
|
||||
return QSize(160, 300);
|
||||
|
|
|
@ -28,10 +28,11 @@
|
|||
|
||||
class QStandardItemModel;
|
||||
class QString;
|
||||
class QPoint;
|
||||
class PlayModel;
|
||||
class PlayWordMediator;
|
||||
class PublicGame;
|
||||
class HintsDialog;
|
||||
class AbstractHint;
|
||||
|
||||
class ToppingWidget: public QWidget, private Ui::ToppingWidget
|
||||
{
|
||||
|
@ -56,6 +57,8 @@ protected:
|
|||
|
||||
private slots:
|
||||
void lockSizesChanged(bool checked);
|
||||
void showHintsDialog();
|
||||
void hintUsed(const AbstractHint&);
|
||||
|
||||
private:
|
||||
/// Encapsulated training game, can be NULL
|
||||
|
@ -70,6 +73,9 @@ private:
|
|||
/// Mediator for the "play word" controls
|
||||
PlayWordMediator *m_mediator;
|
||||
|
||||
/// Dialog used to display hints
|
||||
HintsDialog *m_hintsDialog;
|
||||
|
||||
/// Palette to write text in black
|
||||
QPalette blackPalette;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>560</width>
|
||||
<height>123</height>
|
||||
<height>150</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
|
@ -68,6 +68,19 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
|
@ -92,19 +105,6 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLineEdit" name="lineEditPoints">
|
||||
<property name="enabled">
|
||||
|
@ -124,6 +124,13 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="QPushButton" name="pushButtonGetHints">
|
||||
<property name="text">
|
||||
<string>_("Get hints...")</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QTableView" name="tableViewMoves">
|
||||
|
|
Loading…
Reference in a new issue