Skip to content

Commit fe1fa97

Browse files
author
richelbilderbeek
committed
Can replay a 'game', progress #22
1 parent 4a715a1 commit fe1fa97

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

replay.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,33 @@ std::string get_scholars_mate_as_pgn_str() noexcept
4242
return "1. e4 e5 2. Qh5 Nc6 3. Bc4 Nf6?? Qxf7# 1-0";
4343
}
4444

45-
void play_game(const replay& r)
45+
void play_game(const replay& r, const bool verbose)
4646
{
4747
game g;
4848
const auto& moves{r.get_moves()};
4949
const int n_moves = moves.size();
5050
for (int i{0}; i!=n_moves; ++i)
5151
{
5252
const auto& m{moves[i]};
53-
std::clog << i << ": " << m << '\n';
53+
if (verbose) std::clog << i << ": " << m << '\n';
5454
start_chess_move(g, m);
5555
for (int j{0}; j!=4; ++j) g.tick(delta_t(0.25));
56-
std::clog << to_board_str(
56+
if (verbose) std::clog << to_board_str(
5757
g.get_pieces(),
5858
board_to_text_options(true, true)
5959
) << '\n';
60+
const auto messages{collect_messages(g)};
61+
const long n_cannot{
62+
std::count_if(
63+
std::begin(messages),
64+
std::end(messages),
65+
[](const auto& msg)
66+
{
67+
return msg.get_message_type() == message_type::cannot;
68+
}
69+
)
70+
};
71+
assert(n_cannot == 0);
6072
}
6173
}
6274

replay.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ replay get_replay_1() noexcept;
3434

3535
/// Play a replay, using \link{game} (not \link{game_controller})
3636
/// as the actor
37-
void play_game(const replay& r);
37+
void play_game(
38+
const replay& r,
39+
const bool verbose = false
40+
);
3841

3942
/// Split the PGN string into its moves
4043
/// E.g. '1. e4 e5 2. Nc3' will be split into {'e4', 'e5', 'Nc3'}

0 commit comments

Comments
 (0)