summaryrefslogtreecommitdiff
path: root/docs/random/shenzhen_io_review.md
blob: e4287cbe5b4f8073ee029bd09cd993ec74c008fb (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# Shenzhen I/O Game Review

I don't usually game.<sup>[citation needed]</sup>

Sometime in 2021, in my first days of university, I felt bored and bought
this game. Also out of vanity to show how different I am from my league of
legends roommates. (it didn't work because i got stuck at assignment eight
and gave up, until december 2023 when i decided to give it another spin
now that i've made a few PCBs and written some assembly in real life)

## What is this game

[Shenzhen I/O](https://www.zachtronics.com/shenzhen-io/) is a "nerd puzzle
game" (my words) by Zachtronics.

You move to Shenzhen and work as an employee at 龙腾 (Longteng), where you
combine chips into circuits that meet client specifications. In each level
(assignment), you are given a canvas like this one:

![Blank circuit board next to a waveform viewer and part
selector](img/shenzhen_io_review/canvas.png)

Then you complete these tasks, in the general order:

- Drag parts from the sidebar
- Connect parts with each other and I/O pins on the sides
- Write assembly for the programmable chips
- Simulate and debug until output matches expected waveform

The assembly language in question is invented specifically for the game.
The chips are fictional, too. It doesn't actually require prior embedded
systems knowledge. A few differences from real-life embedded systems:

- No need to explicitly power the chips
- No need to worry about clock cycles
- Everything seems to use decimal, not binary
- Hardly any boolean operations
- Voltage levels range from 0 to 100
- ADC/DAC are perfectly accurate
- Integers range from -999 to 999
- MCUs have two registers max (`acc` and `dat`), and no SRAM
- XBus, the asynchronous protocol, seems too complicated for one clock
  cycle
- Multidriver problems are handled simply by `input = max({outputs})`, and
  can be abused

And mostly importantly, the debugger is something I wish I had in real
life. You can literally step through the instructions! Imagine if you were
able to freeze time, poke an ATmega328P and know which loop it's stuck in.

That said, I'm not the best at this game. Hell, I'm not even _good_, as
I have created abominations like:

<details markdown="1">
<summary>Spoiler</summary>
![Circuit with five MCUs and wires that almost fill the entire canvas](img/shenzhen_io_review/traffic_signal.png)
</details>

After you complete each assignment, the game shows you where you are among
all the players. The data I got was:

![Three histograms, showing my data float much worse than
average](img/shenzhen_io_review/traffic_signal_histograms.png)

The current best for three metrics on the leaderboard are:

- Lowest cost: 6 yuan (mine costs 20)
- Power usage: 123 (mine uses 1.7K)
- Lines of code: 9 (mine has 45)

As you can see, my solution is far from good in whichever way, but
nevertheless it works. This is because there are so many ways to solve
a problem, and to optimize a solution.

That said, am I going to optimize my solution? No.

## Why is it fun

Like all puzzle games, it is fun because it's intellectually challenging.
It's not the kind of Genshin Impact minigame.

Another reason is the plot. For most of the game's target audience, living
in Shenzhen would be a foreign experience, and it's a lot of fun reading
coworkers (both Chinese and from abroad) react to projects and life. The
game's UI involves a mail client, where you receive emails from your
supervisors and coworkers, and honestly that's half the fun.

(lets ignore the fact that most chinese companies dont discuss everything
over email)

<details markdown="1">
<summary>Spoiler alert!</summary>

My favorite emails are:

- When you designed a vape as merchandise for musician Cool Dad, who, once
  the vapes were manufactured, got arrested for possession of
  amphetamines. Also, Carl absolutely _roasted_ Cool Dad's music.
- When you designed a laser/illuminator apparatus for law enforcement
  weapons and Carl responded with brutal sarcasm out of moral concerns.
  I kinda wonder if the correct move is _not_ to design it, but it's too
  late.
- When Joe proposed a haunted doll implemented with unmarked chips of
  unknown origin, and was then forbidden from venturing further in the
  field of "ghost electronics"
- When a Japanese company claims to have developed a "traditional yarrow
  stalk _I Ching_ divination" with "MEMS technology"
</details>

## Why is it hard

### You have to read the datasheet

The game comes with no manual; instead it ships a PDF containing all the
datasheets and supplementary materials. Fortunately they are much easier
to understand than those in real life. And they are (mostly) typeset very
well. Much more pleasant to the eye than many actual industrial
datasheets. In the one case it isn't, it's definitely intentional for
a "sketchy" vibe.

### Chips are intentionally underpowered

We know modern chips are extremely powerful. So powerful it would render
the game pointless. So the chips and assembly language in this game are
intentionally limited. The smaller chip only holds 9 instructions, the
larger one 14.

I sometimes find it hard to implement any meaningful logic with such an
underpowered chip. Once I found a solution that was 15 lines long, but
I had to split them in two chips, and then I had to write extra code so
they could communicate, which is another 10+ lines of overhead.

Hardware-wise, the chip has 6 pins max, and you can't just use _any_ pin,
because some pins are "simple", and some are "XBus".

### Conditional instructions are cursed

There's no actual "conditional branch". Give the chip a condition (e.g.
`teq acc 1` tests if `acc == 1`) and it sets a global state (+/-). Then
you can prepend a +/- to an instruction so that it only runs in the state.
The global state makes it really hard to emulate nested `if` statements.
Pretty sure there were actual ISAs that used this mechanism, but I always
get confused on this logic.

### Labels count as lines?

If you wanted to jump to an instruction, you have to label the line, like

```
loop:
  add 1
  jmp loop
```

It should make sense to any programmer that labels are not real. They are
just a fancy way to refer to the line number it precedes, and thus should
not count as a line. But in the above code it does, because the text area
only has so many rows. This leaves me with one less line for actual
instructions. It took me way too long to realize that this is legal:

```
loop: add 1
  jmp loop
```

The datasheet never mentioned this! I was looking at the
[leaderboard](https://www.reddit.com/r/shenzhenIO/wiki/index/) when
I found out.

### Canvas size is limited

The wire traces take a significant amount of space and there is only one
side, so no vias. They will sometimes block pins. The only way to cross
two wires is to use a bridge, which only comes in one size and direction.
I have more than once made a circuit that looks like an absolute jumbled
mess. Like what even is this

<details markdown="1">
<summary>Spoiler</summary>
![Circuit with four bridges](img/shenzhen_io_review/sandwich_machine.png)
</details>

There was one level where I just _can't_ get the wires to go where they
should. I tried every direction possible to route the wires, but there's
either not enough horizontal space or enough vertical space. The most
disgusting thing is this kind of notch that you can't route wires through.
These notches made two hours of my life miserable. I almost gave up.

![Tiny notch in circuit board with wires around it, but not through it](img/shenzhen_io_review/shoes_notch.png)

Then I downloaded a solution from the leaderboard, only to find that, like
in real life, you can route traces _below_ the chips. _Nobody mentioned
that!_ There was nothing in the manual that explicitly said this was ok,
nor was there any hint in the game. The hack is only accessible if you
hold Tab, which enters "show wires" mode, and the chips become translucent
so you can route traces underneath.

<details markdown="1">
<summary>Spoiler</summary>
Normal view:

![Circuit board with chips and wires](img/shenzhen_io_review/shoes.png)

When holding Tab:

![Same circuit but wires under chips are visible](img/shenzhen_io_review/shoes_wires.png)
</details>

I doubt this assignment is possible without this kind of hack. Anyway,
I deleted the leaderboard solution and made my own version, and I'm never
looking back.

## Hardest assignments

These are a list of assignments that I felt stuck on for more than an
hour.

<details markdown="1">
<summary>Spoiler</summary>

- Virtual reality buzzer (the level that led me to quitting in 2021)
- Precision food scale
- Traffic signal
- Color changing shoes (titled "Would you believe it?" in game)
</details>

Again, I'm not good at this. If I had to find an excuse, it would be that
I try my best to come up with the most elegant solution possible, however
many lines it takes. I'd use a divide & conquer approach that's as
symmetric as possible, which is not always optimal, and sometimes uses up
too much of space and makes a mess of wires.

## A nitpick on the awkwardness of languages

The game is created by a bunch of Americans, for, I suppose, a primarily
English-speaking audience. Despite this, the game and the datasheets are
available in both English and simplified Chinese. The problems are:

- The Chinese does not sound Chinese
- The English does not sound Chinese

If you tried to play the Chinese version as a Chinese person, as I have,
you will find the Chinese dialog awkward. The translator did their best,
but it sounds un-Chinese.

They are grammatically correct, but I find this sort of conversation out
of place in a Chinese workplace. However, I would prefer if real life
workplace conversations sounded like this. Light-hearted without much
客套话 (formalities). Let's hope society evolves that way.

On the other hand, if you play in English, you'll find that your Chinese
coworkers have extraordinarily high English competency, atypical of
current day Shenzhen (but the game is set in the future, so one can hope).

## Minigame: Shenzhen Solitaire

Early in the game a coworker introduces a solitaire-style game with
Mahjong-themed cards. It's a way to relax when I'm stressed out solving
a puzzle. I like it so much that I [rewrote it in
Rust](https://git.sr.ht/~fkfd/shenzhen_solitaire).

## Conclusion

At the time of writing, I have not finished the game (yet). So far it's
really enjoyable. I did stress myself out a handful times halfway; that
was because I was not treating it as a game. Once I accepted the fact that
I'm just a casual player and being unable to solve the puzzles does not
result in any loss of self worth, I was again ready to have fun.