While building my letter construction game WordGlyph, (https://wordglyph.xyz ), I explored two approaches to implement how players assemble letters using segments: bitwise operations and array patterns. Both are viable and interesting, but each comes with its tradeoffs. Here's an overview of both, how they work, and why I ultimately chose arrays for my game.
In the bitwise method, each letter is represented as a 12-bit number, where each bit corresponds to a stick or segment position. This makes it compact (12 bits per letter) and efficient for operations like checking valid moves or completed letters.
Each letter is defined as a binary number. You can use bitwise operators to check if the current sticks plus a new stick match a letter.
In the array method, each letter is represented as an array of segment IDs. This approach is more intuitive: you define each letter as a list of required segments, and validation checks involve iterating through arrays.