From cbde7b367ee4ae9b11dc31698495bf8ceb814958 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 28 Oct 2026 15:11:01 +0100 Subject: [PATCH] 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 --- src/game/reschedule.cpp | 9 ++++++++- src/game/reschedule.hpp | 4 ++-- src/modern/game/reschedule.cpp | 9 ++++++++- src/modern/game/reschedule.hpp | 4 ++-- tests/modern_ui_contract_tests.cpp | 9 +++++++++ tests/reschedule_tests.cpp | 5 +++++ 6 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/game/reschedule.cpp b/src/game/reschedule.cpp index ca8fd12..1112eac 100644 --- a/src/game/reschedule.cpp +++ b/src/game/reschedule.cpp @@ -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; } diff --git a/src/game/reschedule.hpp b/src/game/reschedule.hpp index a19246f..c58ee6a 100644 --- a/src/game/reschedule.hpp +++ b/src/game/reschedule.hpp @@ -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. diff --git a/src/modern/game/reschedule.cpp b/src/modern/game/reschedule.cpp index db2841a..3af5f1b 100644 --- a/src/modern/game/reschedule.cpp +++ b/src/modern/game/reschedule.cpp @@ -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; } diff --git a/src/modern/game/reschedule.hpp b/src/modern/game/reschedule.hpp index f1fd457..20c2763 100644 --- a/src/modern/game/reschedule.hpp +++ b/src/modern/game/reschedule.hpp @@ -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. diff --git a/tests/modern_ui_contract_tests.cpp b/tests/modern_ui_contract_tests.cpp index 1a780bd..51e856a 100644 --- a/tests/modern_ui_contract_tests.cpp +++ b/tests/modern_ui_contract_tests.cpp @@ -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); diff --git a/tests/reschedule_tests.cpp b/tests/reschedule_tests.cpp index 5b6d75a..d1f6a77 100644 --- a/tests/reschedule_tests.cpp +++ b/tests/reschedule_tests.cpp @@ -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"; }