Cute Chess  0.1
move.h
1 /*
2  This file is part of Cute Chess.
3 
4  Cute Chess is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  Cute Chess is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with Cute Chess. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef MOVE_H
19 #define MOVE_H
20 
21 #include <QtGlobal>
22 #include <QMetaType>
23 
24 namespace Chess {
25 
41 class Move
42 {
43  public:
45  Move();
50  Move(int sourceSquare,
51  int targetSquare,
52  int promotion = 0);
53 
60  int sourceSquare() const;
62  int targetSquare() const;
70  int promotion() const;
71 
73  bool isNull() const;
75  bool operator==(const Move& other) const;
77  bool operator!=(const Move& other) const;
78 
79  private:
80  quint32 m_data;
81 };
82 
83 
84 inline Move::Move()
85  : m_data(0)
86 {
87 }
88 
89 inline Move::Move(int sourceSquare,
90  int targetSquare,
91  int promotion)
92  : m_data(sourceSquare |
93  (targetSquare << 10) |
94  (promotion << 20))
95 {
96  Q_ASSERT(sourceSquare >= 0 && sourceSquare <= 0x3FF);
97  Q_ASSERT(targetSquare >= 0 && targetSquare <= 0x3FF);
98  Q_ASSERT(promotion >= 0 && promotion <= 0x3FF);
99 }
100 
101 inline bool Move::isNull() const
102 {
103  return (m_data == 0);
104 }
105 
106 inline bool Move::operator==(const Move& other) const
107 {
108  return (m_data == other.m_data);
109 }
110 
111 inline bool Move::operator!=(const Move& other) const
112 {
113  return (m_data != other.m_data);
114 }
115 
116 inline int Move::sourceSquare() const
117 {
118  return m_data & 0x3FF;
119 }
120 
121 inline int Move::targetSquare() const
122 {
123  return (m_data >> 10) & 0x3FF;
124 }
125 
126 inline int Move::promotion() const
127 {
128  return (m_data >> 20) & 0x3FF;
129 }
130 
131 } // namespace Chess
132 
133 Q_DECLARE_METATYPE(Chess::Move)
134 
135 #endif // MOVE_H
bool operator==(const Move &other) const
Definition: move.h:106
bool isNull() const
Definition: move.h:101
Definition: boardscene.h:28
Move()
Definition: move.h:84
int sourceSquare() const
Definition: move.h:116
int promotion() const
Definition: move.h:126
int targetSquare() const
Definition: move.h:121
bool operator!=(const Move &other) const
Definition: move.h:111
A small and efficient chessmove class.
Definition: move.h:41