aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: c272428affaf0a253adfb48c4db45fff634f6e3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# yhtz - a yahtzee CLI game with 8 bytes of state

Inspired by [The Bitwise Gamedev Challenge](https://github.com/zesterer/the-bitwise-challenge). 
Not sure if this *technically* counts since there aren't really "frames", but 
the spirit of the challenge is there -- the game should be able to be picked up 
at any point using the single 8 byte state struct.

## State layout

### Byte 1

* Roll count: 2 bits (high)
* "Top" section flags: 6 bits, one for each number, indicating whether we've played it yet

```
	00 000000
roll    ^^ ^^^^^^
count---|| ||||||
           654321
```

### Byte 2

* "Top" rolling score: 7 bits (low)
* High bit is ignored

### Byte 3

* "Bottom" section flags: 7 bits (low), one for each category
* High bit is ignored

### Byte 4

* "Bottom" rolling score: 8 bits

### Bytes 5-6

* Dice: 5 total dice, each die has 3 bits, representing their current value
* High bit is ignored

```
x 000 000 000 000 000
  D4. D3. D2. D1. D0.
```

### Bytes 7-8

* Seed: a 16-bit unsigned integer representing the seed for the random number generator.
   Uses Dr. Lemire's [16-bit WyHash example](https://lemire.me/blog/2019/07/03/a-fast-16-bit-random-number-generator/).