5/9 pfp
5/9
@fiveoutofnine.eth
How to represent a game of Tic-tac-toe with just 2.25 bytes: https://zora.co/collect/base:0x93625454e26f407ad6c3f62b3245bb197af44e80/3
2 replies
3 recasts
24 reactions

5/9 pfp
5/9
@fiveoutofnine.eth
First, you may come up with something like the following as your first representation. Besides the player addresses, this representation uses 104 bits and 2 storage slots.
1 reply
0 recast
1 reaction

5/9 pfp
5/9
@fiveoutofnine.eth
After tightly packing the struct, the representation is actually quite good already. On the EVM, setting empty storage slots costs a lot more gas than setting nonzero ones, and you need a minimum of 2 storage slots to store the player addresses (i.e. no significant savings).
1 reply
0 recast
0 reaction

5/9 pfp
5/9
@fiveoutofnine.eth
However, it's a fun exercise to understand for when you *do* need that extra granularity/control in your code, so let's continue exploring ways to reduce the representation :)
1 reply
0 recast
0 reaction

5/9 pfp
5/9
@fiveoutofnine.eth
To start, take a look at `uint8[9] board`. We definitely don't need 8 bits to store data for a position on the board. There are only 3 valid states, so 2 bits are enough: * Empty (00) * Occupied by "O" (01) * Occupied by "X" (10)
1 reply
0 recast
0 reaction