Commit 6f286cde authored by Denis Kuplyakov's avatar Denis Kuplyakov

Restored hint functionality.

Now KReversiPlayer count number of used hints, and hints are disabled
for computer moves.
parent bd1a5e0f
......@@ -24,7 +24,7 @@
#include "kreversicomputerplayer.h"
KReversiComputerPlayer::KReversiComputerPlayer(ChipColor color, QString name):
KReversiPlayer(color, name), m_lowestSkill(100) // setting it big enough
KReversiPlayer(color, name, false), m_lowestSkill(100) // setting it big enough
{
m_engine = new Engine(1);
}
......
......@@ -273,6 +273,13 @@ MoveList KReversiGame::getHistory() const
return l;
}
bool KReversiGame::isHintAllowed() const
{
if (m_curPlayer == NoColor)
return false;
return m_player[m_curPlayer]->isHintAllowed();
}
void KReversiGame::blackPlayerMove(KReversiMove move)
{
qDebug() << "Game: black move";
......@@ -314,6 +321,7 @@ void KReversiGame::whiteReady()
KReversiMove KReversiGame::getHint() const
{
/// FIXME: dimsuz: don't use true, use m_competitive
m_player[m_curPlayer]->hintUsed();
return m_engine->computeMove(*this, true);
}
......
......@@ -117,6 +117,11 @@ public:
* @return History of moves as MoveList
*/
MoveList getHistory() const;
/**
* @return Is hint allowed for current player
*/
bool isHintAllowed() const;
private slots:
/**
* Starts next player turn.
......
......@@ -24,7 +24,7 @@
#include "kreversihumanplayer.h"
KReversiHumanPlayer::KReversiHumanPlayer(ChipColor color, QString name):
KReversiPlayer(color, name)
KReversiPlayer(color, name, true)
{
}
......
......@@ -23,8 +23,8 @@
#include "kreversiplayer.h"
KReversiPlayer::KReversiPlayer(ChipColor color, QString name):
m_state(UNKNOWN), m_color(color), m_name(name)
KReversiPlayer::KReversiPlayer(ChipColor color, QString name, bool hintAllowed):
m_state(UNKNOWN), m_color(color), m_name(name), m_hintAllowed(hintAllowed), m_hintCount(0)
{
}
......@@ -37,3 +37,18 @@ QString KReversiPlayer::getName() const
{
return m_name;
}
bool KReversiPlayer::isHintAllowed() const
{
return m_hintAllowed;
}
void KReversiPlayer::hintUsed()
{
m_hintCount++;
}
int KReversiPlayer::getHintsCount()
{
return m_hintCount;
}
......@@ -39,7 +39,7 @@ class KReversiPlayer: public QObject
{
Q_OBJECT
public:
explicit KReversiPlayer(ChipColor color, QString name);
explicit KReversiPlayer(ChipColor color, QString name, bool hintAllowed);
/**
* Used to get player color
......@@ -53,6 +53,21 @@ public:
*/
QString getName() const;
/**
* @return is hint allowed for player or not
*/
bool isHintAllowed() const;
/**
* KReversiGame triggers it to to increase used hints count
*/
void hintUsed();
/**
* @return how many times player has used hints
*/
int getHintsCount();
public slots:
/**
* Triggered by KReversiGame before game starts
......@@ -107,6 +122,16 @@ protected:
* Player's name to be shown at UI
*/
QString m_name;
/**
* Are hints enabled for player
*/
bool m_hintAllowed;
/**
* How many times player has used hint
*/
int m_hintCount;
};
#endif // KREVERSIPLAYER_H
......@@ -106,7 +106,6 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent, bool startDemo)
// create main game view
m_view = new KReversiView(m_game, this);
// m_view->setChipsPrefix(Preferences::useColoredChips() ? Colored : BlackWhite);
setCentralWidget(m_view);
// initialise actions
......@@ -135,7 +134,8 @@ void KReversiMainWindow::setupActionsInit()
// m_undoAct->setEnabled(false); // nothing to undo at the start of the game
// // Hint
// m_hintAct = KStandardGameAction::hint(m_view, SLOT(slotHint()), actionCollection());
m_hintAct = KStandardGameAction::hint(m_view, SLOT(slotHint()), actionCollection());
m_hintAct->setEnabled(false);
// m_demoAct = KStandardGameAction::demo(this, SLOT(slotToggleDemoMode()), actionCollection());
// Last move
......@@ -235,9 +235,6 @@ void KReversiMainWindow::slotShowMovesHistory(bool toggled)
void KReversiMainWindow::slotNewGame()
{
// if (m_hintAct)
// m_hintAct->setEnabled(true);
// if (m_demoAct) {
// m_demoAct->setChecked(false);
// m_demoAct->setIcon(KIcon(QLatin1String("media-playback-start")));
......@@ -251,7 +248,7 @@ void KReversiMainWindow::slotNewGame()
void KReversiMainWindow::slotGameOver()
{
// m_hintAct->setEnabled(false);
m_hintAct->setEnabled(false);
// //TODO: only if it is not computer-computer match
// m_undoAct->setEnabled(m_game->canUndo());
......@@ -332,11 +329,12 @@ void KReversiMainWindow::slotGameOver()
void KReversiMainWindow::slotMoveFinished()
{
qDebug() << "sdfsdf";
// m_undoAct->setEnabled(m_game->canUndo());
updateHistory();
updateStatusBar();
m_hintAct->setEnabled(m_game->isHintAllowed());
}
void KReversiMainWindow::updateHistory() {
......@@ -472,4 +470,6 @@ void KReversiMainWindow::receivedGameStartInformation(GameStartInformation info)
updateStatusBar();
updateHistory();
m_hintAct->setEnabled(m_game->isHintAllowed());
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment