00001 // cwchessboard -- A C++ chessboard tool set 00002 // 00003 //! @file Move.h This file contains the definition of class Move. 00004 // 00005 // Copyright (C) 2008, by 00006 // 00007 // Carlo Wood, Run on IRC <carlo@alinoe.com> 00008 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt 00009 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 00010 // 00011 // This program is free software: you can redistribute it and/or modify 00012 // it under the terms of the GNU General Public License as published by 00013 // the Free Software Foundation, either version 2 of the License, or 00014 // (at your option) any later version. 00015 // 00016 // This program is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU General Public License 00022 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00023 00024 #ifndef MOVE_H 00025 #define MOVE_H 00026 00027 #ifndef USE_PCH 00028 #endif 00029 00030 #include "Index.h" 00031 #include "Type.h" 00032 00033 namespace cwchess { 00034 00035 /** @brief A chess move in a particular chess position. 00036 * 00037 * This class represents a move as can be done in a particular chess position. 00038 * That means that it cannot be used to do the same move in another position 00039 * where that move is possible too. The reason for that is that it's internal 00040 * representation only stores the squares, and not piece information. 00041 * 00042 * A Move is therefore always used in combination with a ChessPosition. 00043 * / 00044 class Move { 00045 private: 00046 Index M_from; //!< Where the piece comes from. 00047 Index M_to; //!< Where the piece moves to. 00048 Type M_promotion_type; //!< Set to 'nothing' if not a promotion. 00049 00050 public: 00051 /** @name Constructors* / 00052 //@{ 00053 00054 //! Construct an uninitialized Move. 00055 Move(void) { } 00056 00057 /** @brief Construct a Move from square \a from to square \a to. 00058 * 00059 * If this move represents a pawn promotion then \a promotion 00060 * must be one of queen, rook, knight, bishop. Otherwise it 00061 * must be empty. 00062 * / 00063 Move(Index from, Index to, Type promotion) : M_from(from), M_to(to), M_promotion_type(promotion) { } 00064 00065 //! Copy-constructor. 00066 Move(Move const& move) : M_from(move.M_from), M_to(move.M_to), M_promotion_type(move.M_promotion_type) { } 00067 00068 //@} 00069 00070 /** @name Assignment operator* / 00071 //@{ 00072 00073 Move& operator=(Move const& move) { M_from = move.M_from; M_to = move.M_to; M_promotion_type = move.M_promotion_type; return* this; } 00074 00075 //@} 00076 00077 /** @name Comparision operators* / 00078 //@{ 00079 00080 bool operator==(Move const& move) const 00081 { 00082 if (move.M_to == index_end) return M_to == index_end; 00083 return M_from == move.M_from && M_to == move.M_to && M_promotion_type == move.M_promotion_type; 00084 } 00085 00086 bool operator!=(Move const& move) const 00087 { 00088 if (move.M_to == index_end) return M_to != index_end; 00089 return M_to != move.M_to || M_from != move.M_from || M_promotion_type != move.M_promotion_type; 00090 } 00091 00092 //@} 00093 00094 /** @name Accessors* / 00095 //@{ 00096 00097 //! Return TRUE if this move is a pawn promotion. 00098 bool is_promotion(void) const { return M_promotion_type != nothing; } 00099 00100 //! Return the square the piece moves from. 00101 Index from(void) const { return M_from; } 00102 00103 //! Return the square the piece moves to. 00104 Index to(void) const { return M_to; } 00105 00106 //! Return the promotion type. Returns empty if this isn't a promotion. 00107 Type promotion_type(void) const { return M_promotion_type; } 00108 00109 //@} 00110 00111 /** @name Manipulators* / 00112 //@{ 00113 00114 //! Set a different promotion type. 00115 void set_promotion(Type promotion) { M_promotion_type = promotion; } 00116 00117 //! Set different target square. 00118 void set_to(Index to) { M_to = to; } 00119 00120 //! Set from, to and promotion type. 00121 void set_move(Index from, Index to, Type promotion) { M_from = from; M_to = to; M_promotion_type = promotion; } 00122 00123 //@} 00124 }; 00125 00126 } // namespace cwchess 00127 00128 #endif // MOVE_H