Zork

Project to translate the classic text-based adventure game Zork into Rust

Zork is a classic text-based adventure game, and this project partially re-implemented it in Rust. The original C source for the game is available on the internet, but it's poorly commented with minimal variable names. The first goal of the project was to learn more about the C Foreign Function Interface (FFI) by implementing some functions in Rust and then linking the binaries together. The second goal of the project was to practice reverse engineering algorithms and legacy code.

I made an effort to not just blindly translate the C into Rust for each function. Instead, I figured out what the function was doing, its purpose in the game, and refactored the code as I translated it.

An issue that appeared early on was the difficulty of testing changes. I was able to make unit tests for individual Rust functions, but integration tests were done by manually playing the game. That didn't even work very well; sometimes replacing a function would cause bugs to appear in code I hadn't even looked at yet. To address these issues, I created an integration testing program that recorded manual inputs and the original program's output text. It then ran the C and Rust hybrid binary and checked the output against its recordings. The recordings were large, so I stored them in a separate repository. With proper integration testing set up, I made good progress.

I stopped the project when I reached the command processing code. It was too tangled in unwritten assumptions, indirection, and hacky algorithms for me to rewrite.

Languages:

C, Rust

Gitlab Repo:

Phlosioneer/zork-rs