-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
stats.cpp
160 lines (124 loc) · 2.59 KB
/
stats.cpp
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/**
* stats.cpp
*
* the MicroChess project: https://github.com/ripred/MicroChess
*
* MicroChess statistics and timing functions
*
*/
#include <Arduino.h>
#include "MicroChess.h"
#include "stats.h"
/*
******************************************************************************************
* movetime_t objects
*
*/
// Constructor
movetime_t::movetime_t()
{
init();
}
// init method
void movetime_t::init()
{
start = 0;
stop = 0;
dur = 0;
count = 0;
running = False;
moves_per_sec = 0.0;
depth = 0;
}
// Begin the timer
void movetime_t::begin()
{
if (!running) {
start = millis();
stop = start;
dur = 0;
count = 0;
moves_per_sec = 0.0;
running = True;
}
}
// End the timer
void movetime_t::end()
{
if (running) {
stop = millis();
dur = stop - start;
running = False;
if ((0 != count) && (0 == dur)) {
dur = 1;
}
if ((0 != dur) && (0 != count)) {
moves_per_sec = double(count) / (double(dur) / 1000.0);
}
}
}
// Get the time so far in milliseconds, or the total time,
// depending on whether the timer is running or not.
uint32_t movetime_t::duration() const
{
if (running) {
return millis() - start;
}
return dur;
}
// Increment the counter
uint32_t movetime_t::increment()
{
if (running) count++;
return count;
}
// Get the counter
uint32_t movetime_t::counter() const
{
return count;
}
// Get the moves per second
double movetime_t::moveps() const
{
// return moves_per_sec;
return double(count) / (duration() / 1000.0);
}
/*
******************************************************************************************
* stat_t objects
*
*/
// Constructor:
stat_t::stat_t() {
init();
}
// Init method
void stat_t::init() {
game_stats.init();
move_stats.init();
}
// Increase the number of moves evaluated
void stat_t::inc_moves_count() {
game_stats.increment();
move_stats.increment();
}
// Start the game timers and clear out the game counts
void stat_t::start_game_stats() {
game_stats.begin();
}
// Stop the game timers and calc the game stats
void stat_t::stop_game_stats() {
game_stats.end();
}
// Start the move timers and clear out the move counts
void stat_t::start_move_stats() {
move_stats.begin();
}
// Get the number of moves evaluated so far
uint32_t stat_t::move_count_so_far() const {
return move_stats.counter();
}
// Stop the move timers and calc the move stats
void stat_t::stop_move_stats() {
move_stats.end();
}