From 05825e751d69cde554c21ddfd00e646049425e31 Mon Sep 17 00:00:00 2001 From: rodri Date: Tue, 26 Sep 2023 18:39:02 +0000 Subject: initial work towards spectator mode. --- util.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'util.c') diff --git a/util.c b/util.c index cdd1d52..eee2a3d 100644 --- a/util.c +++ b/util.c @@ -100,6 +100,9 @@ fprintmap(int fd, Map *m) switch(m->map[j][i]){ case Twater: fprint(fd, "W"); break; case Tship: fprint(fd, "S"); break; + case Thit: fprint(fd, "X"); break; + case Tmiss: fprint(fd, "O"); break; + default: fprint(fd, "?"); break; } fprint(fd, "\n"); } @@ -153,3 +156,44 @@ min(int a, int b) { return a < b? a: b; } + +int +bitpackmap(uchar *buf, ulong len, Map *m) +{ + int i, j, off, n; + + assert(len >= BY2MAP); + + off = n = 0; + *buf = 0; + for(i = 0; i < MAPW; i++) + for(j = 0; j < MAPH; j++){ + if(off >= 8){ + buf[++n] = 0; + off = 0; + } + buf[n] |= (m->map[i][j] & TMASK) << off; + off += TBITS; + } + return n+1; +} + +int +bitunpackmap(Map *m, uchar *buf, ulong len) +{ + int i, j, off, n; + + assert(len >= BY2MAP); + + off = n = 0; + for(i = 0; i < MAPW; i++) + for(j = 0; j < MAPH; j++){ + if(off >= 8){ + n++; + off = 0; + } + m->map[i][j] = buf[n] >> off & TMASK; + off += TBITS; + } + return n+1; +} -- cgit v1.2.3