-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove.hpp
105 lines (82 loc) · 2 KB
/
move.hpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#pragma once
#include "figures.hpp"
#include <iostream>
#include <vector>
struct Point {
int x;
int y;
Point() = default;
Point(int x_, int y_)
: x(x_)
, y(y_)
{
}
bool operator==(const Point& p) const
{
return x == p.x && y == p.y;
}
};
static std::ostream& operator<<(std::ostream& os, const Point& p)
{
os << static_cast<char>(p.x + 'a') << (p.y + 1);
return os;
}
struct MoveBase {
Point from;
Point to;
Square toSq;
MoveBase() = default;
MoveBase(Point from_, Point to_, Square toSq_)
: from(from_)
, to(to_)
, toSq(toSq_)
{
}
virtual ~MoveBase() = default;
bool operator==(const MoveBase& mb) const
{
return from == mb.from && to == mb.to && toSq == mb.toSq;
}
};
enum class MoveType {
STANDARD,
CASTLING,
EN_PASSANT
};
struct Move : MoveBase {
MoveType type;
Move() = default;
Move(Point from_, Point to_, Square toSq_, MoveType type_ = MoveType::STANDARD)
: MoveBase(std::move(from_), std::move(to_), toSq_)
, type(type_)
{
}
Move(int fx, int fy, int tx, int ty, Square toSq_, MoveType type_ = MoveType::STANDARD)
: Move(Point { fx, fy }, Point { tx, ty }, toSq_, type_)
{
}
bool operator==(const Move& m) const
{
return MoveBase::operator==(m) && type == m.type;
}
};
static std::ostream& operator<<(std::ostream& os, const Move& m)
{
return os << m.from << m.to;
}
struct UndoMove : MoveBase {
Square fromSq;
int score;
UndoMove(Point from_, Point to_, Square fromSq_, Square toSq_, int score_)
: MoveBase(std::move(from_), std::move(to_), toSq_)
, fromSq(fromSq_)
, score(score_)
{
}
UndoMove(int fx, int fy, int tx, int ty, Square fromSq_, Square toSq_, int score)
: UndoMove(Point { fx, fy }, Point { tx, ty }, fromSq_, toSq_, score)
{
}
};
using Moves = std::vector<Move>;
using UndoMoves = std::vector<UndoMove>;