-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction_history.h
61 lines (44 loc) · 1.68 KB
/
action_history.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
#ifndef ACTION_HISTORY_H
#define ACTION_HISTORY_H
#include "delta_t.h"
#include "piece_action.h"
#include <iosfwd>
#include <vector>
class action_history
{
public:
action_history(
const std::vector<std::pair<delta_t, piece_action>>& timed_actions = {}
);
/// Add an action, when started
void add_action(const delta_t& t, const piece_action& action) noexcept;
const auto& get_timed_actions() const noexcept { return m_timed_actions; }
private:
/// The history of actions (i.e when they started), in chrononical order
std::vector<std::pair<delta_t, piece_action>> m_timed_actions;
};
/// Collect all the actions that started in the timespan
std::vector<piece_action> collect_actions_in_timespan(
const action_history& history,
const delta_t from,
const delta_t to
);
/// Has this piece (i.e. a pawn) just finish a double move forward last time unit?
/// Only pawns can do this, e.g. e2-e4 or e7-e5
/// For example, when at t=0.5, e2-e4 is played,
/// from t=1.5 to t=2.5 this function will return true.
/// Before that, the piece was moving
/// After that, it was too long ago for en-passant
bool has_just_double_moved(
const action_history& action_history,
const delta_t when
);
const piece_action& get_last_action(const action_history& history);
bool has_actions(const action_history& history) noexcept;
/// Combine action histories and sort these
action_history merge_action_histories(const std::vector<action_history> histories);
/// Test this class and its free functions
void test_action_history();
std::string to_str(const action_history& history) noexcept;
std::ostream& operator<<(std::ostream& os, const action_history& history) noexcept;
#endif // ACTION_HISTORY_H