File: Output.h

package info (click to toggle)
pentobi 26.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 4,068 kB
  • sloc: cpp: 25,986; javascript: 897; xml: 57; makefile: 13; sh: 11
file content (72 lines) | stat: -rw-r--r-- 1,778 bytes parent folder | download | duplicates (5)
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
//-----------------------------------------------------------------------------
/** @file twogtp/Output.h
    @author Markus Enzenberger
    @copyright GNU General Public License version 3 or later */
//-----------------------------------------------------------------------------

#ifndef TWOGTP_OUTPUT_H
#define TWOGTP_OUTPUT_H

#include <string>
#include <map>
#include <mutex>
#include "OutputTree.h"
#include "libboardgame_base/Timer.h"
#include "libboardgame_base/WallTimeSource.h"

using libboardgame_base::Timer;
using libboardgame_base::WallTimeSource;

//-----------------------------------------------------------------------------

/** Handles the output files of TwoGtp and their concurrent access. */
class Output
{
public:
    Output(Variant variant, const string& prefix, bool create_tree);

    ~Output();

    void set_save_interval(double seconds) { m_save_interval = seconds; }

    void add_result(unsigned n, float result, const Board& bd,
                    unsigned player_black, double cpu_black, double cpu_white,
                    const string& sgf,
                    const array<bool, Board::max_moves>& is_real_move);

    unsigned get_next();

    bool check_sentinel();

    bool generate_fast_open_move(bool is_player_black, const Board& bd,
                                 Color to_play, Move& mv);

private:
    bool m_create_tree;

    unsigned m_next = 0;

    int m_lock_fd;

    string m_prefix;

    mutex m_mutex;

    map<unsigned, string> m_games;

    OutputTree m_output_tree;

    ostringstream m_sgf_buffer;

    WallTimeSource m_time_source;

    Timer m_timer;

    double m_save_interval = 60;

    void save();
};

//-----------------------------------------------------------------------------

#endif // TWOGTP_OUTPUT_H