-
Notifications
You must be signed in to change notification settings - Fork 0
/
move.h
58 lines (52 loc) · 1.33 KB
/
move.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
#ifndef _MOVE_H_CHESS
#define _MOVE_H_CHESS
#include <string>
#include <iostream>
#include "constants.h"
/**
* More or less a POD class to store moves
*/
class Move {
public:
enum MoveType : uint16_t {
Normal = 0,
Castle,
Enpassant,
Promotion
};
/*
* Creates an empty move.
* NOTE: moves are immutable, so doing this cannot be changed
*/
Move();
Move(const Move& other) = default;
Move(Square from, Square to, MoveType moveType, Piece promotionPiece = Piece::Knight);
Move& operator=(const Move& move) = default;
bool operator==(const Move& move) const;
bool operator!=(const Move& move) const;
Square getFrom() const;
Square getTo() const;
Square getEnpassantSquareCaptured(Color turn) const;
MoveType getMoveType() const;
Piece getPromoType() const;
bool isMoveNone() const;
bool isMovePromotion() const;
void print(std::ostream& out) const;
std::string toString() const;
private:
Square from;
Square to;
MoveType moveType;
Piece promotionType;
};
/**
* For use with unordered_map, just hash based on the from and to squares
*/
namespace std {
template <> struct hash<Move> {
std::size_t operator()(const Move& move) const {
return move.getFrom() | (move.getTo() << 6);
}
};
}
#endif