-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathCMove.h
73 lines (57 loc) · 2.07 KB
/
CMove.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef _C_MOVE_H_
#define _C_MOVE_H_
#include "CSquare.h"
typedef enum {
EM = 0, // Empty
WP = 1, // White Pawn
WN = 2, // White Knight
WB = 3, // White Bishop
WR = 4, // White Rook
WQ = 5, // White Queen
WK = 6, // White King
BP = -1, // Black Pawn
BN = -2, // Black Knight
BB = -3, // Black Bishop
BR = -4, // Black Rook
BQ = -5, // Black Queen
BK = -6, // Black King
IV = 99 // INVALID
} e_piece;
/***************************************************************
* declaration of CMove
***************************************************************/
class CMove
{
public:
friend class CBoard;
friend std::ostream& operator <<(std::ostream &os, const CMove &rhs);
// Constructors
CMove() : m_piece(IV), m_captured(IV) {}
CMove(const char *str) : m_captured(IV) { FromString(str); }
CMove(int8_t piece, const CSquare& from, const CSquare& to, int8_t captured = EM, int8_t promoted=EM) :
m_from(from), m_to(to), m_piece(piece), m_captured(captured), m_promoted(promoted) {}
const char * FromString(const char *s); // Returns NULL if error
// Accessor functions
std::string ToShortString() const;
std::string ToLongString() const;
CSquare From(void) const {return m_from;}
CSquare To(void) const {return m_to;}
bool Valid(void) const { return m_captured != IV; }
bool is_captured_piece_a_king(void) const { return (m_captured == WK || m_captured == BK); }
bool is_it_a_capture(void) const { return (m_captured != EM); }
bool operator==(const CMove& rhs) const
{
if (rhs.From() != From())
return false;
if (rhs.To() != To())
return false;
return true;
}
private:
CSquare m_from;
CSquare m_to;
int8_t m_piece;
int8_t m_captured;
int8_t m_promoted;
}; /* end of CMove */
#endif // _C_MOVE_H_