I am making a diplomacy tool, for the board game diplomacy. I need to make a map of each territory. I have a 75 #define MAP_"NAME" lines but I don't know how to set them to a mask value that can be checked since I don't know any 75-bit or larger datastructures that can be declared as datatype=0x<lots of digits>. How do I make a new datatype of X-bytes to store this that can be defined as such? Any help would be appreciated!!!

Dani AI

Generated

Quick expert addendum referencing 's pointer to fixed and dynamic bit containers and 's choice to store indices 0–74. For a 75-territory Diplomacy map the practical options are: a fixed-size bit container (std::bitset<75>) or a dynamic bit container (Boost dynamic_bitset or similar), a compact custom two-word mask, or simple index lists (vector<int>). Bit containers give O(1) membership tests and extremely fast set ops (bitwise AND/OR). Index lists are often simpler for sparse holdings and easy to iterate or serialize as lists.

A small, safe custom mask that fits 75 bits and exposes set/test/bitwise ops:

#include <cstdint>
#include <cstddef>

struct Mask75 {
    uint64_t lo;   // bits 0..63
    uint16_t hi;   // bits 64..74 (low 11 bits used)

    Mask75(): lo(0), hi(0) {}

    void set(std::size_t i) {
        if (i < 64) lo |= (uint64_t(1) << i);
        else          hi |= (uint16_t(1) << (i - 64));
    }

    void reset(std::size_t i) {
        if (i < 64) lo &= ~(uint64_t(1) << i);
        else          hi &= ~(uint16_t(1) << (i - 64));
    }

    bool test(std::size_t i) const {
        return (i < 64) ? (lo & (uint64_t(1) << i)) != 0
                        : (hi & (uint16_t(1) << (i - 64))) != 0;
    }

    Mask75 operator|(const Mask75& o) const {
        Mask75 r; r.lo = lo | o.lo; r.hi = hi | o.hi; return r;
    }
    Mask75 operator&(const Mask75& o) const {
        Mask75 r; r.lo = lo & o.lo; r.hi = hi & o.hi; return r;
    }
};

Notes and pitfalls: C++ integer literals cannot directly hold 75-bit hex constants, so initialize bit containers from strings or parse hex into words. Avoid std::vector<bool> (proxy reference semantics). Keep a stable mapping from territory name to bit index (enum or const array) so saved games remain consistent. For sparse data where iteration dominates, index lists (vector<int> per country) are compact and easy. For frequent set algebra, prefer std::bitset/ dynamic bitset or the custom two-word approach above (fast, compact, simple to serialize). Watch shifts: never shift by >= the operand width (undefined behavior), and define endianness explicitly when writing raw bytes.

Recommended Answers

All 2 Replies

Thanks, I decided to go with integers from 0-74 and use dynamic arrays to pass multiple countries, thanks anyways.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.