2008-01-08 14:52:32 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Eliot
|
2012-01-17 00:27:32 +01:00
|
|
|
* Copyright (C) 2007-2012 Olivier Teulière
|
2008-01-08 14:52:32 +01:00
|
|
|
* 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
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2009-11-29 17:01:31 +01:00
|
|
|
#ifndef MOVE_H_
|
|
|
|
#define MOVE_H_
|
2008-01-08 14:52:32 +01:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "round.h"
|
2012-02-18 22:26:52 +01:00
|
|
|
#include "logging.h"
|
2008-01-08 14:52:32 +01:00
|
|
|
|
2008-11-23 09:18:03 +01:00
|
|
|
class PlayedRack;
|
2008-01-08 14:52:32 +01:00
|
|
|
using std::wstring;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A Move is what a player can do during the game:
|
|
|
|
* - play a valid word
|
|
|
|
* - play an invalid or misplaced word
|
|
|
|
* - pass the turn (freegame only)
|
|
|
|
* - change letters (freegame only)
|
2012-01-17 00:27:32 +01:00
|
|
|
* - play nothing (timeout, for example)
|
2008-01-08 14:52:32 +01:00
|
|
|
*
|
|
|
|
* Moves are useful to record what happened, even if the board doesn't keep
|
|
|
|
* a trace of the move (e.g.: an invalid move which was rejected will still
|
|
|
|
* be remembered in the player history).
|
|
|
|
*/
|
|
|
|
class Move
|
|
|
|
{
|
2012-02-18 22:26:52 +01:00
|
|
|
DEFINE_LOGGER();
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
public:
|
2012-01-17 00:27:32 +01:00
|
|
|
/**
|
|
|
|
* Default constructor, corresponding to no move
|
|
|
|
*/
|
|
|
|
Move();
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
/**
|
|
|
|
* Constructor taking a (valid) round
|
|
|
|
*/
|
|
|
|
explicit Move(const Round &iRound);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor taking a word and its coordinates, corresponding
|
|
|
|
* to an invalid move by the player (invalid word, invalid coordinates,
|
|
|
|
* letters not corresponding to the rack, ...)
|
2009-07-03 23:40:14 +02:00
|
|
|
* Note: the invalid word must be given in the display form.
|
2008-01-08 14:52:32 +01:00
|
|
|
*/
|
2012-01-17 00:27:32 +01:00
|
|
|
Move(const wstring &iWord, const wstring &iCoord);
|
2008-01-08 14:52:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor taking letters to change.
|
|
|
|
* An empty string means that the player simply passes without
|
|
|
|
* changing any letter.
|
|
|
|
* The given letters must have been already validated for correctness.
|
|
|
|
*/
|
2012-01-17 00:27:32 +01:00
|
|
|
Move(const wstring &iLetters);
|
2008-01-08 14:52:32 +01:00
|
|
|
|
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
VALID_ROUND,
|
|
|
|
INVALID_WORD,
|
|
|
|
PASS,
|
2012-01-17 00:27:32 +01:00
|
|
|
CHANGE_LETTERS,
|
|
|
|
NO_MOVE,
|
2008-01-08 14:52:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Return the type of move
|
|
|
|
Type getType() const { return m_type; }
|
|
|
|
|
|
|
|
/// Get the score of this move (0 unless the round is valid)
|
2009-11-29 17:01:31 +01:00
|
|
|
int getScore() const { return m_score; }
|
2008-01-08 14:52:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the round associated with the move, or throw an exception
|
|
|
|
* if this move was not constructed from a valid round
|
|
|
|
*/
|
|
|
|
const Round & getRound() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the word played at this move associated with the move, or
|
|
|
|
* throw an exception if this move was not constructed from an invalid
|
|
|
|
* pair (word, coord)
|
|
|
|
*/
|
|
|
|
const wstring & getBadWord() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the coordinates of the (incorrect) word played at this move,
|
|
|
|
* or throw an exception if this move was not constructed from an
|
|
|
|
* invalid pair (cord, coord)
|
|
|
|
*/
|
|
|
|
const wstring & getBadCoord() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the changed letters (possibly an empty string if the player
|
|
|
|
* simply wanted to pass the turn), or throw an exception if this move
|
|
|
|
* does not correspond to a passed turn
|
|
|
|
*/
|
|
|
|
const wstring & getChangedLetters() const;
|
|
|
|
|
2008-11-23 09:18:03 +01:00
|
|
|
/**
|
|
|
|
* Return the rack obtained from the given one, after playing the
|
|
|
|
* given move.
|
|
|
|
* The move is supposed to be possible for the given rack.
|
|
|
|
*/
|
2012-04-07 14:27:59 +02:00
|
|
|
static PlayedRack ComputeRackForMove(const PlayedRack &iOldRack,
|
|
|
|
const Move &iMove);
|
2008-11-23 09:18:03 +01:00
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
/// To help debugging
|
|
|
|
wstring toString() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// Type of move
|
|
|
|
Type m_type;
|
|
|
|
|
|
|
|
/// Score associated with this move
|
|
|
|
int m_score;
|
|
|
|
|
|
|
|
/// Round played at this turn
|
|
|
|
Round m_round;
|
|
|
|
|
|
|
|
/// Word played (incorrectly)
|
|
|
|
wstring m_word;
|
|
|
|
|
|
|
|
/// Coordinates of the word played (incorrectly)
|
|
|
|
wstring m_coord;
|
|
|
|
|
|
|
|
/// Changed letters (or empty string for passed turn)
|
|
|
|
wstring m_letters;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|