Almanac format 3: matches column by column, line-ups against the previous one
Each match field of a season is stored as its own column and every player of a line-up as his slot in the club's previous line-up. Deflate then finds the repeats: a half season shrinks from 294 to 218 KB in the save. Versions 1 and 2 are still read; tests cover a hand-built version 2 season and a reordered line-up with a new player. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ddaebec183
commit
d419943e86
3 files changed
+199
-44
No files matched your search
@@ -41,6 +41,13 @@ AlmanacSeason sample() {
|
||||
m.events.push_back({AlmanacEventKind::Substitution, 80, 0, 0, b, a});
|
||||
m.events.push_back({AlmanacEventKind::ShootoutKick, 121, 1, 1, a, kAlmanacNone});
|
||||
s.matches.push_back(m);
|
||||
// the same club again: two players from its previous line-up in a new order and a new one
|
||||
// (version 3 names them by their slot in the previous line-up)
|
||||
const uint16_t c = s.player({"player:3", "Carl", "Neu", "nation:at"});
|
||||
AlmanacMatch next;
|
||||
next.date = 407, next.type = 0, next.league = 0, next.round = 3, next.home = away, next.away = home;
|
||||
next.lineup[1] = {b, c, a};
|
||||
s.matches.push_back(next);
|
||||
AlmanacTable t;
|
||||
t.league = 0;
|
||||
t.rows.push_back({home, 1, 34, 25, 5, 4, 80, 30, 77});
|
||||
@@ -50,6 +57,49 @@ AlmanacSeason sample() {
|
||||
s.winners.push_back({12, 0xff, 4, 1, 310, away, 0xffff});
|
||||
return s;
|
||||
}
|
||||
|
||||
// A season in the row format of version 2 (one row per match), as older saves hold it.
|
||||
std::string encode_version_2(const AlmanacSeason& s) {
|
||||
std::string o = "OBAL";
|
||||
auto u8 = [&](uint32_t v) { o.push_back(char(v & 0xff)); };
|
||||
auto u16 = [&](uint32_t v) { u8(v), u8(v >> 8); };
|
||||
auto u32 = [&](uint32_t v) { u16(v), u16(v >> 16); };
|
||||
auto str = [&](const std::string& t) { u16(uint32_t(t.size())), o += t; };
|
||||
u16(2), u16(uint32_t(int16_t(s.season))), u16(uint32_t(s.start_year)), u16(uint32_t(s.display_start_year));
|
||||
u16(uint32_t(s.leagues.size()));
|
||||
for (const auto& l : s.leagues) u8(uint32_t(l.index)), str(l.id), str(l.name);
|
||||
u16(uint32_t(s.clubs.size()));
|
||||
for (const auto& c : s.clubs) str(c.id), str(c.name);
|
||||
u32(uint32_t(s.players.size()));
|
||||
for (const auto& p : s.players) str(p.id), str(p.first), str(p.last), str(p.nation);
|
||||
u8(uint32_t(s.managers.size()));
|
||||
for (const auto& m : s.managers) u8(uint32_t(uint8_t(int8_t(m.index)))), str(m.name);
|
||||
u16(uint32_t(s.referees.size()));
|
||||
for (const auto& r : s.referees) str(r);
|
||||
u32(uint32_t(s.matches.size()));
|
||||
for (const AlmanacMatch& m : s.matches) {
|
||||
u32(m.date), u8(m.type), u8(m.league), u8(m.stage), u8(m.round), u16(m.home), u16(m.away);
|
||||
u8(uint8_t(m.home_manager)), u8(uint8_t(m.away_manager));
|
||||
u8(m.home_goals), u8(m.away_goals), u8(m.home_shootout), u8(m.away_shootout), u8(m.decided), u8(m.referee);
|
||||
u32(m.attendance), u8(uint8_t(m.temperature)), u8(m.rain);
|
||||
for (const auto& side : m.lineup) {
|
||||
u8(uint32_t(side.size()));
|
||||
for (uint16_t p : side) u16(p);
|
||||
}
|
||||
u16(uint32_t(m.events.size()));
|
||||
for (const AlmanacEvent& e : m.events) u8(uint32_t(e.kind)), u8(e.minute), u8(e.side), u8(e.detail), u16(e.player), u16(e.other);
|
||||
}
|
||||
u8(uint32_t(s.tables.size()));
|
||||
for (const AlmanacTable& t : s.tables) {
|
||||
u8(t.league), u8(uint32_t(t.rows.size()));
|
||||
for (const AlmanacStanding& r : t.rows)
|
||||
u16(r.club), u8(r.rank), u8(r.played), u8(r.won), u8(r.drawn), u8(r.lost), u8(r.goals_for), u8(r.goals_against),
|
||||
u16(uint32_t(uint16_t(r.points)));
|
||||
}
|
||||
u16(uint32_t(s.winners.size()));
|
||||
for (const AlmanacWinner& x : s.winners) u8(x.type), u8(x.league), u8(x.stage), u8(x.detail), u32(x.date), u16(x.winner), u16(x.runner_up);
|
||||
return o;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
@@ -58,6 +108,8 @@ int main() {
|
||||
const AlmanacSeason back = decode_almanac_season(bytes);
|
||||
check(back == s, "season round trip");
|
||||
check(encode_almanac_season(back) == bytes, "stable encoding");
|
||||
check(decode_almanac_season(encode_version_2(s)) == s, "version 2 saves still read");
|
||||
check(bytes.size() > 6 && bytes[4] == 3 && bytes[5] == 0, "written as version 3");
|
||||
|
||||
AlmanacSeason grown = back; // the lookups survive decoding: no duplicate entries
|
||||
check(grown.club({"club:sued", "FC Südstadt"}) == 0 && grown.clubs.size() == 2, "club lookup after decode");
|
||||
|
||||
Reference in new issue
Block a user