File indexing completed on 2024-05-19 04:05:42
0001 /*************************************************************************** 0002 File : move.h 0003 Project : Knights 0004 Description : Class representing a chess move 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2016 Alexander Semke (alexander.semke@web.de) 0007 SPDX-FileCopyrightText: 2009-2011 Miha Čančula (miha@noughmad.eu) 0008 0009 ***************************************************************************/ 0010 0011 /*************************************************************************** 0012 * * 0013 * SPDX-License-Identifier: GPL-2.0-or-later 0014 * * 0015 * This program is distributed in the hope that it will be useful, * 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0018 * GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program; if not, write to the Free Software * 0022 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0023 * Boston, MA 02110-1301 USA * 0024 * * 0025 ***************************************************************************/ 0026 0027 #ifndef KNIGHTS_MOVE_H 0028 #define KNIGHTS_MOVE_H 0029 0030 #include "piece.h" 0031 0032 #include <QSharedDataPointer> 0033 0034 namespace Knights { 0035 class MovePrivate; 0036 0037 class Move { 0038 public: 0039 0040 typedef QList<Move> List; 0041 0042 enum MoveFlag { 0043 None = 0x000, 0044 Take = 0x001, 0045 Promote = 0x002, 0046 Castle = 0x004, 0047 EnPassant = 0x008, 0048 Check = 0x010, 0049 CheckMate = 0x020, 0050 Additional = 0x040, 0051 Forced = 0x080, 0052 Illegal = 0x100 0053 }; 0054 0055 enum CastlingSide { 0056 QueenSide, 0057 KingSide 0058 }; 0059 0060 enum Notation { 0061 NoNotation, /**< No string has been set */ 0062 Algebraic, /**< It omits the starting file and rank of the piece, unless it is necessary to disambiguate the move. */ 0063 Coordinate, /**< specifies the starting and end position */ 0064 LongAlgebraic /**< specifies almost everything */ 0065 }; 0066 Q_DECLARE_FLAGS(Flags, MoveFlag) 0067 0068 static Move castling(CastlingSide, Color); 0069 0070 Move(Pos from, Pos to, Flags flags = None); 0071 explicit Move(QString); 0072 Move(); 0073 Move(const Move& other); 0074 virtual ~Move(); 0075 0076 void operator=(const Move& other); 0077 0078 Pos from() const; 0079 Pos to() const; 0080 QString string(bool includeX = true) const; 0081 Move reverse() const; 0082 0083 void setFrom(const Pos&); 0084 void setFrom(int first, int second); 0085 void setTo(const Pos&); 0086 void setTo(int first, int second); 0087 void setString(QString); 0088 0089 bool flag(Move::MoveFlag) const; 0090 Flags flags() const; 0091 void setFlag(MoveFlag, bool value); 0092 void setFlags(Flags); 0093 0094 const QList<Move>& additionalMoves() const; 0095 void setAdditionalMoves(const QList<Move>&); 0096 0097 PieceType promotedType() const; 0098 void setPromotedType(PieceType); 0099 0100 const PieceDataMap& removedPieces() const; 0101 void setRemovedPieces(const PieceDataMap&); 0102 void addRemovedPiece(const Pos&, const PieceData&); 0103 0104 const PieceDataMap& addedPieces() const; 0105 void setAddedPieces(const PieceDataMap&); 0106 void addAddedPiece(const Pos&, const PieceData&); 0107 0108 Notation notation() const; 0109 0110 bool operator==(Move other ) const; 0111 0112 void setTime(const QTime&); 0113 QTime time(); 0114 0115 void setPieceData(const PieceData&); 0116 PieceData pieceData() const; 0117 0118 bool isValid() const; 0119 0120 void setStringForNotation(Notation, const QString&); 0121 QString stringForNotation(Notation) const; 0122 0123 private: 0124 QSharedDataPointer<MovePrivate> d; 0125 }; 0126 Q_DECLARE_OPERATORS_FOR_FLAGS(Move::Flags) 0127 } 0128 0129 QDebug operator<<(QDebug debug, const Knights::Move &move); 0130 0131 Q_DECLARE_METATYPE(Knights::Move) 0132 Q_DECLARE_METATYPE(Knights::Move::List) 0133 0134 #endif // KNIGHTS_MOVE_H