![intro](https://i.imgur.com/z6ewOd9.png)

This challenge presented a website with a game programmed in WebAssembly. The
game is very close to the puzzles you see in the video game [The Witness
(2016)](https://en.wikipedia.org/wiki/The_Witness_(2016_video_game)), where
the goal is to make continuous line from the starting position (marked with a
red A) to an ending position (red B). Depending on its path, the line will
also segment the board into groups.

![example puzzle](https://i.imgur.com/aJKc90a.png)

The line also has to follow certain conditions, depending on the symbols. If
you fullfil all of the rules when your line hits the ending position, you win.
But if you haven't managed to hit every condition, the line simply disappears
instead and you'll have to try again. For this specific implementation of the
game, there are two modes: offline and online. In the offline mode, all of the
6 obstructions can appear freely, but you have unlimited time to complete the
puzzle. If you solve it, you are taken back to the main menu. If you don't
solve it, the JS console will give you some hints about what is wrong (number
of mistakes and sometimes the constraint id you didn't meet the criteria for).
Solutions are checked for consistency with not only the various obstructions,
but also that the line does not go out of bounds or any such trickery.

In the online mode however, you query the server API and receive a data blob
with the definition for 5 boards. The blob with the boards contain a
timestamp, and is also signed from the server. When you start to play in this
mode, the same music from the original game's secret timed challenge starts
playing, and whenever it finishes the game also stops. If you finish all the 5
boards within the time limit, the solutions will be sent to the server (and
possibly verified server-side), then the server will return the flag in the
response to that query. It's worth noting that the boards you receive in the
online mode are getting progressively more difficult, while in the offline
mode it's pretty randomized what you get.

Now for the constraint types. 3 of these existed in the original game (type 1,
3 and 4). The rest we had to dive into the JS and WASM code to figure out,
though we were able to ascertain a lot of the properties by sharing
screenshots of invalid and valid solves and making some hypotheses about the
restrictions they imposed. In the end, we never figured out what the purple
triangles did, but we had some luck when playing the game.

* Constraint 1: Single colored circle. No segment can contain multiple single circles of more than one color.  
* Constraint 2: Two colored circles. Must be grouped with exactly 1 other double-circle or single circle of the same color, but tolerates other colors fine.  
* Constraint 3: Tetris blocks. Must be in a segment where that block can fit exactly. Multiple blocks can be in the same segment, and rotations of them are allowed.  
* Constraint 4: 1-3 blue squares. Needs 1-3 sides around the symbol to be touched, depending on the number of squares.  
* Constraint 5: Purple (#673AB7) triangle. Unknown.  
* Constraint 6: Small, colored rectangle. Avoid touching the lines around it.

When playing, the first level will contain constraints 1, 4 and 6. Then
constraint 2 is introduced in the next level, followed by 3 and finally 5. We
solved it by just playing the game manually, knowing these rules, and got it
just as the final crescendo of "In the hall of the Mountain King" ended :)

\- UnblvR