mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-12-25 21:59:30 +01:00
Hints system, to retrieve partial information about a Move.
This is only the core part, no interface integration is done yet.
This commit is contained in:
parent
4153d45377
commit
3f19d6ae49
3 changed files with 319 additions and 0 deletions
|
@ -34,6 +34,7 @@ libgame_a_SOURCES= \
|
|||
bag.cpp bag.h \
|
||||
turn_data.cpp turn_data.h \
|
||||
history.cpp history.h \
|
||||
hints.cpp hints.h \
|
||||
player.cpp player.h \
|
||||
cmd/topping_move_cmd.cpp cmd/topping_move_cmd.h \
|
||||
cmd/player_event_cmd.cpp cmd/player_event_cmd.h \
|
||||
|
|
173
game/hints.cpp
Normal file
173
game/hints.cpp
Normal file
|
@ -0,0 +1,173 @@
|
|||
/*****************************************************************************
|
||||
* Eliot
|
||||
* Copyright (C) 2013 Olivier Teulière
|
||||
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
|
||||
*
|
||||
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*****************************************************************************/
|
||||
|
||||
#include <boost/format.hpp>
|
||||
|
||||
#include "config.h"
|
||||
#if ENABLE_NLS
|
||||
# include <libintl.h>
|
||||
# define _(String) gettext(String)
|
||||
#else
|
||||
# define _(String) String
|
||||
#endif
|
||||
|
||||
|
||||
#include "hints.h"
|
||||
#include "move.h"
|
||||
#include "encoding.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
INIT_LOGGER(game, AbstractHint);
|
||||
|
||||
|
||||
AbstractHint::AbstractHint(const string &iName, const string &iDescription, int iCost)
|
||||
: m_name(iName), m_description(iDescription), m_cost(iCost)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
ScoreHint::ScoreHint()
|
||||
: AbstractHint(_("Score"),
|
||||
_("Get the score of the move"), 60)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
string ScoreHint::giveHint(const Move &iMove) const
|
||||
{
|
||||
return str(boost::format(_("Score: %1%")) % iMove.getScore());
|
||||
}
|
||||
|
||||
|
||||
|
||||
OrientationHint::OrientationHint()
|
||||
: AbstractHint(_("Orientation"),
|
||||
_("Get the orientation of the move (horizontal/vertical)"), 20)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
string OrientationHint::giveHint(const Move &iMove) const
|
||||
{
|
||||
ASSERT(iMove.isValid(), "Hints only make sense for valid moves");
|
||||
const Coord &coord = iMove.getRound().getCoord();
|
||||
boost::format fmt(_("Orientation: %1%"));
|
||||
if (coord.getDir() == Coord::HORIZONTAL)
|
||||
fmt % _("horizontal");
|
||||
else
|
||||
fmt % _("vertical");
|
||||
return fmt.str();
|
||||
}
|
||||
|
||||
|
||||
|
||||
PositionHint::PositionHint()
|
||||
: AbstractHint(_("Position"),
|
||||
_("Get the coordinates of the move"), 80)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
string PositionHint::giveHint(const Move &iMove) const
|
||||
{
|
||||
ASSERT(iMove.isValid(), "Hints only make sense for valid moves");
|
||||
return str(boost::format(_("Position: %1%"))
|
||||
% lfw(iMove.getRound().getCoord().toString()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
LengthHint::LengthHint()
|
||||
: AbstractHint(_("Length"),
|
||||
_("Get the length of the word"), 40)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
string LengthHint::giveHint(const Move &iMove) const
|
||||
{
|
||||
ASSERT(iMove.isValid(), "Hints only make sense for valid moves");
|
||||
return str(boost::format(_("Length: %1% letters"))
|
||||
% iMove.getRound().getWordLen());
|
||||
}
|
||||
|
||||
|
||||
|
||||
BoardLettersHint::BoardLettersHint()
|
||||
: AbstractHint(_("Letters from board"),
|
||||
_("Get the letters of the word coming from the board"), 70)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
string BoardLettersHint::giveHint(const Move &iMove) const
|
||||
{
|
||||
ASSERT(iMove.isValid(), "Hints only make sense for valid moves");
|
||||
// Retrieve the letters coming from the board
|
||||
wstring fromBoard;
|
||||
for (unsigned i = 0; i < iMove.getRound().getWordLen(); ++i)
|
||||
{
|
||||
if (!iMove.getRound().isPlayedFromRack(i))
|
||||
fromBoard.push_back(iMove.getRound().getTile(i).toChar());
|
||||
}
|
||||
|
||||
return str(boost::format(_("Letters from board: %1%"))
|
||||
% (fromBoard == L"" ? _("(none)") : lfw(fromBoard)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
WordLettersHint::WordLettersHint()
|
||||
: AbstractHint(_("Word letters"),
|
||||
_("Get the letters of the word in alphabetical order"), 120)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
string WordLettersHint::giveHint(const Move &iMove) const
|
||||
{
|
||||
ASSERT(iMove.isValid(), "Hints only make sense for valid moves");
|
||||
wstring word = iMove.getRound().getWord();
|
||||
// Sort the letters
|
||||
std::sort(word.begin(), word.end());
|
||||
|
||||
return str(boost::format(_("Word letters: %1%"))
|
||||
% lfw(word));
|
||||
}
|
||||
|
||||
|
||||
|
||||
FirstLetterHint::FirstLetterHint()
|
||||
: AbstractHint(_("First letter"),
|
||||
_("Get the first letter of the word"), 120)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
string FirstLetterHint::giveHint(const Move &iMove) const
|
||||
{
|
||||
ASSERT(iMove.isValid(), "Hints only make sense for valid moves");
|
||||
return str(boost::format(_("First letter: %1%"))
|
||||
% lfw(iMove.getRound().getTile(0).toChar()));
|
||||
}
|
||||
|
||||
|
145
game/hints.h
Normal file
145
game/hints.h
Normal file
|
@ -0,0 +1,145 @@
|
|||
/*****************************************************************************
|
||||
* Eliot
|
||||
* Copyright (C) 2013 Olivier Teulière
|
||||
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
|
||||
*
|
||||
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef HINTS_H_
|
||||
#define HINTS_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "logging.h"
|
||||
|
||||
|
||||
using std::string;
|
||||
|
||||
class Move;
|
||||
|
||||
|
||||
/**
|
||||
* Interface common to all the hints.
|
||||
*/
|
||||
class AbstractHint
|
||||
{
|
||||
DEFINE_LOGGER();
|
||||
public:
|
||||
AbstractHint(const string &iName, const string &iDescription, int iCost);
|
||||
virtual ~AbstractHint() {}
|
||||
|
||||
/// Get a name (or title) for the hint
|
||||
string getName() const { return m_name; }
|
||||
|
||||
/// Get a longer description for the hint
|
||||
string getDescription() const { return m_description; }
|
||||
|
||||
/// Get the cost (time penalty, in seconds) for using this hint
|
||||
int getCost() const { return m_cost; }
|
||||
|
||||
/**
|
||||
* Actual hint processing, to help guess the given Move.
|
||||
* Since different hints can return different types of information,
|
||||
* a string is expected in all cases.
|
||||
*/
|
||||
virtual string giveHint(const Move &iMove) const = 0;
|
||||
|
||||
private:
|
||||
string m_name;
|
||||
string m_description;
|
||||
int m_cost;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Hint giving the score of the move
|
||||
*/
|
||||
class ScoreHint : public AbstractHint
|
||||
{
|
||||
public:
|
||||
ScoreHint();
|
||||
virtual string giveHint(const Move &iMove) const;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Hint giving the orientation of the move (horizontal/vertical)
|
||||
*/
|
||||
class OrientationHint : public AbstractHint
|
||||
{
|
||||
public:
|
||||
OrientationHint();
|
||||
virtual string giveHint(const Move &iMove) const;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Hint giving the position of the move
|
||||
*/
|
||||
class PositionHint : public AbstractHint
|
||||
{
|
||||
public:
|
||||
PositionHint();
|
||||
virtual string giveHint(const Move &iMove) const;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Hint giving the length of the word
|
||||
*/
|
||||
class LengthHint : public AbstractHint
|
||||
{
|
||||
public:
|
||||
LengthHint();
|
||||
virtual string giveHint(const Move &iMove) const;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Hint giving the letters of the move which come from the board
|
||||
*/
|
||||
class BoardLettersHint : public AbstractHint
|
||||
{
|
||||
public:
|
||||
BoardLettersHint();
|
||||
virtual string giveHint(const Move &iMove) const;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Hint giving the letters of the word in alphabetical order
|
||||
*/
|
||||
class WordLettersHint : public AbstractHint
|
||||
{
|
||||
public:
|
||||
WordLettersHint();
|
||||
virtual string giveHint(const Move &iMove) const;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Hint giving the first letter of the word
|
||||
*/
|
||||
class FirstLetterHint : public AbstractHint
|
||||
{
|
||||
public:
|
||||
FirstLetterHint();
|
||||
virtual string giveHint(const Move &iMove) const;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in a new issue