Hold back live chance statistics until the result of the chance
Prepare verified release / draft (push) Canceled after 0s
Prepare verified release / draft (push) Canceled after 0s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
09b92c9b2a
commit
93ca832c71
5 files changed
+44
-5
No files matched your search
+4
-1
@@ -3291,7 +3291,10 @@ int main(int argc, char** argv) {
|
||||
}, [&](const LiveChanceEvent& event, const std::vector<MatchGroup>& groups,
|
||||
const GameState& state) {
|
||||
if (!running || live_skipped) return;
|
||||
const auto frame = ui::live_matchday_frame(event.minute, groups, state);
|
||||
// Preview: the chance is already in the event log, but its statistics must not count yet.
|
||||
const auto frame = event.stage == LiveChanceStage::preview
|
||||
? ui::live_matchday_frame_before_chance(event.minute, groups, state, event)
|
||||
: ui::live_matchday_frame(event.minute, groups, state);
|
||||
live_score_reveal.observe(event.stage, frame);
|
||||
if (frame.matches.empty()) return;
|
||||
const auto chance = ui::live_chance_projection(event, groups, state, season_exe);
|
||||
|
||||
@@ -140,6 +140,18 @@ LiveMatchdayFrame live_matchday_frame(int minute, const std::vector<MatchGroup>&
|
||||
return frame;
|
||||
}
|
||||
|
||||
LiveMatchdayFrame live_matchday_frame_before_chance(int minute, const std::vector<MatchGroup>& groups,
|
||||
const GameState& state, const LiveChanceEvent& event) {
|
||||
// MatchEngine::chance writes two log pairs (outcome, then kind/distance) = 4 words before the preview hook.
|
||||
// The copy is small: chances are rare and only the log of one group is shortened.
|
||||
if (event.group < 0 || size_t(event.group) >= groups.size() || groups[size_t(event.group)].log.size() < 4)
|
||||
return live_matchday_frame(minute, groups, state);
|
||||
std::vector<MatchGroup> before = groups;
|
||||
auto& log = before[size_t(event.group)].log;
|
||||
log.resize(log.size() - 4);
|
||||
return live_matchday_frame(minute, before, state);
|
||||
}
|
||||
|
||||
LiveChanceProjection live_chance_projection(const LiveChanceEvent& event,
|
||||
const std::vector<MatchGroup>& groups, const GameState& state, const LeImage& exe) {
|
||||
if (event.group < 0 || size_t(event.group) >= groups.size() || event.match < 0 ||
|
||||
|
||||
@@ -51,8 +51,14 @@ struct LiveMatchdayFrame {
|
||||
LiveMatchdayFrame live_matchday_frame(int minute, const std::vector<MatchGroup>& groups,
|
||||
const GameState& state);
|
||||
|
||||
// Frame of the matchday as it looked before the chance of the event was written to the event log. The engine
|
||||
// logs a chance (two log pairs) before its preview hook, so the statistics rows (chances, shots, ...) would
|
||||
// otherwise count it before the presentation has even started.
|
||||
LiveMatchdayFrame live_matchday_frame_before_chance(int minute, const std::vector<MatchGroup>& groups,
|
||||
const GameState& state, const LiveChanceEvent& event);
|
||||
|
||||
// The engine commits a chance before its ball/set-piece/shot presentation. Keep
|
||||
// the observed preview scores until the result hook, without delaying simulation.
|
||||
// the observed preview scores and statistics until the result hook, without delaying simulation.
|
||||
class LiveScoreReveal {
|
||||
public:
|
||||
void observe(LiveChanceStage stage, const LiveMatchdayFrame& frame) {
|
||||
@@ -66,6 +72,8 @@ public:
|
||||
row.home_goals = before.home_goals;
|
||||
row.away_goals = before.away_goals;
|
||||
row.score_known = before.score_known;
|
||||
row.home_stats = before.home_stats;
|
||||
row.away_stats = before.away_stats;
|
||||
break;
|
||||
}
|
||||
return frame;
|
||||
|
||||
@@ -26,6 +26,18 @@ int main() {
|
||||
reveal.observe(bmh::LiveChanceStage::result,resolved);
|
||||
if(reveal.project(resolved)!=resolved)throw std::runtime_error("result did not reveal goal");
|
||||
}
|
||||
// Statistics (chances, shots, ...) count a chance only at its result, like the score.
|
||||
{
|
||||
LiveScoreReveal stats_reveal;
|
||||
stats_reveal.observe(bmh::LiveChanceStage::preview,frame);
|
||||
auto counted=frame;counted.matches[0].home_stats={11,4,2,1};counted.matches[0].away_stats={11,3,0,0};
|
||||
counted.matches[0].home_stats[1]++;
|
||||
const auto shown=stats_reveal.project(counted);
|
||||
if(shown.matches[0].home_stats!=frame.matches[0].home_stats||shown.matches[0].away_stats!=frame.matches[0].away_stats||
|
||||
shown.matches[1]!=counted.matches[1])throw std::runtime_error("statistics counted before the result");
|
||||
stats_reveal.observe(bmh::LiveChanceStage::result,counted);
|
||||
if(stats_reveal.project(counted)!=counted)throw std::runtime_error("result did not reveal statistics");
|
||||
}
|
||||
reveal.observe(bmh::LiveChanceStage::preview,frame);
|
||||
if(reveal.project(frame)!=frame)throw std::runtime_error("miss changed score");
|
||||
auto next=frame;next.minute++;
|
||||
|
||||
Reference in new issue
Block a user