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