Reschedule undo clears the calendar replay bit (#16)

UndoReschedule of the original clears bit 0x4000 of the calendar day
(high byte & 0xbf) when no replay of another club stays on it; both cores
kept the bit, so the day and its neighbour were no longer offered as
targets after a move was taken back. Tests check the same target days
after the undo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-28 15:11:03 +01:00
1 parent 9fc05d18ee
commit cbde7b367e
6 files changed
+34 -6

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.
+8 -1
View File
@@ -229,15 +229,22 @@ bool undo_reschedule(ModernState& 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
@@ -16,8 +16,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 ModernState only: no random numbers are drawn, so a
// rescheduled career stays deterministic.
+9
View File
@@ -440,6 +440,15 @@ int main(int argc, char** argv) {
check(moved_seen, "calendar: the moved match on its new date");
const J undone = session.ui_command(cmd("request:f2", "fixture.reschedule", O{{"action", "undo"}, {"date", target}}), rev);
check(s(at(undone, "messageType")) == "command_result", "move taken back");
// issue 16: after the undo the match offers the same target dates as before the move
const auto targets_of = [&](const J& read) {
if (const auto* list = at(at(read, "data"), "movable").array())
for (const auto& mv : *list)
if (s(at(mv, "id")) == match) return cli::dump_json(at(mv, "targetDates"));
return std::string{};
};
check(!targets_of(sched).empty() && targets_of(session.ui_read(O{{"kind", "scheduling"}}, rev)) == targets_of(sched),
"the same target dates after the undo");
std::printf("(moved %s to %s and back)\n", match.c_str(), target.c_str());
}
const J friendly = session.ui_read(O{{"kind", "friendly"}, {"opponentId", "team:70"}, {"home", true}}, rev);
+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";
}