Preserve Classic reschedule targets after undo (by Codex)

This commit is contained in:
Codex committed 2026-10-30 14:21:55 +01:00
1 parent dcfb724ebe
commit 81fc772a15
3 files changed
+15 -3

No files matched your search

+8 -1
View File
@@ -228,15 +228,22 @@ bool undo_reschedule(GameState& g, int manager, int day) {
if (std::none_of(moved.begin(), moved.end(), [&](const LeagueMatchRef& m) { return m.day == day; })) return false;
const int team = manager_team(g, manager);
// UndoReschedule(day, 1, team): every replay of the club on that day, whatever its league
int kept = 0; // local_18: the replays of other clubs that stay on the day
for (int e = 0; e < kPostponedEntries; e++) {
const uint32_t at = kPostponed + uint32_t(e) * 6;
if (g.memory.u16(at) != uint16_t(day)) continue;
const int league = g.memory.u8(at + 3), round = g.memory.u8(at + 2), m = g.memory.u8(at + 4);
const Fixture f = round_fixtures(league, round).at(size_t(m));
if (f.home != team && f.away != team) continue;
if (f.home != team && f.away != team) { ++kept; continue; }
g.results.at(result_at(league, round, m)) = kNotPlayed;
g.memory.set16(at, 0);
}
// with no replay left the day loses its replay bit 0x4000 again (calendar high byte & 0xbf),
// so it can be a target once more
if (kept == 0) {
const uint32_t high = kCalendar + uint32_t(day) * 2 + 1;
g.memory.set8(high, uint8_t(g.memory.u8(high) & 0xbf));
}
return true;
}
+2 -2
View File
@@ -15,8 +15,8 @@
// matchday the 0xCE turns into 0xCD (matchday_setup) and the match is played on the
// new day like a winter postponement.
// 4. A click on the new day of a moved match takes the move back (UndoReschedule(day, 1,
// team)): the entry is freed and the result byte is 0xCC again. The calendar keeps bit
// 0x4000, as in the original.
// team)): the entry is freed and the result byte is 0xCC again. When no replay of another
// club stays on that day, the day loses bit 0x4000 again and can be a target once more.
//
// Everything here works on the saved GameState only: no random numbers are drawn, so a
// rescheduled career stays deterministic.
+5
View File
@@ -76,6 +76,11 @@ void reschedule_test(GameState g) {
check(undone.memory.u16(at) == 0 && undone.results.at(size_t(m.match) + size_t(m.round) * 10 + size_t(league) * 0x17c) == kNotPlayed,
"undo frees the entry and restores 0xCC");
check(reschedulable_matches(undone, 0).size() == matches.size(), "the match is movable again");
// UndoReschedule clears the replay bit when no other replay stays on the day: the same
// target days as before the move (issue 16)
check((undone.memory.u16(::bmh::layout::CompetitionCalendar + uint32_t(target) * 2) & 0x4000) == 0,
"undo clears the calendar replay bit");
check(reschedule_target_days(undone, 0, m) == days, "the same target days after the undo");
std::cout << "moved round " << m.round + 1 << " from day " << m.day << " to day " << target << " (" << days.size()
<< " days offered)\n";
}