Files
Dreierpack-Manager/src/game/source_tip.cpp
T
ClaudeandClaude Sonnet 5.5 287b5a9251 Add header comments to the source files
Every source file in ui, app, game, formats, cli, audio and launch that had none
now starts with a short English comment: what it implements, what state it owns
and how it relates to its neighbours (request/acknowledge flow, pairs of files,
random generator use). Comment lines only; the full build and the runnable
tests are unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-06 09:15:23 +01:00

44 lines
1.8 KiB
C++

// SPDX-License-Identifier: GPL-3.0-only
// Score arithmetic of the computer's league table forecast tip: from team ratings and secondary
// values it produces one predicted result using the game generator.
// A pure function of its arguments; each call consumes a fixed pattern of GameRandom draws.
// Interface in source_tip.hpp; used by table_forecast.cpp.
#include "game/source_tip.hpp"
#include <bit>
#include <cstdint>
namespace bmh {
uint8_t source_tip_result(GameRandom& game, const std::array<uint8_t, 10>& gap,
int home_rating, int away_rating,
int home_secondary, int away_secondary) {
uint8_t home = uint8_t((away_secondary + 0x14 < home_secondary) + game.range(0, 1));
uint8_t away = uint8_t((away_secondary < home_secondary) + game.range(0, 1));
const uint32_t wrapped = uint32_t(home_rating) - uint32_t(away_rating);
const int32_t signed_difference = std::bit_cast<int32_t>(wrapped);
int32_t scaled = signed_difference / 10;
if (scaled < 0) scaled = -scaled;
uint8_t local_c = uint8_t(scaled);
if (home_rating > away_rating) {
if (local_c > 9) local_c = 9;
home = uint8_t(home + game.range(0, int(gap[local_c]) + 1));
}
if (home_rating < away_rating) {
// ComputeLeagueTableForecast negates the byte before clamping it to the gap table.
local_c = uint8_t(-int(local_c));
if (local_c > 9) local_c = 9;
away = uint8_t(away + game.range(0, int(gap[local_c])));
if (local_c < 5) home = uint8_t(home + 1);
}
for (;;) {
const int cap = game.range(2, 6);
if (int(home) + int(away) <= cap) break;
if (home) --home;
if (away) --away;
}
return uint8_t((home << 4) | away);
}
} // namespace bmh