-
Notifications
You must be signed in to change notification settings - Fork 2
Issue with Character Input
Issue:
When executing pietquest, the interpreter asked for input multiple times during a single decision point. The game opens by prompting the user to select either 1 or 2, and branches to different code segments depending on the response. Running the program, the interpreter queried the user, but waited for a second input before failing. Examining the Piet code itself confirmed that the program was actually expecting two inputs. We were a tiny bit confused as to why Piet asked for two characters when the user had no way of knowing that it wanted anything more than one.
Investigation:
Tracing through the program using the npiet implementation of the Piet interpreter, we found that pietquest expected both a single character and a newline character from the input stream as two separate inputs. From other Piet programs we've examined, this seems to be the case only with character input and not with integer input.
Resolution:
Apparently, Piet expects a newline to follow all character input (this is not stated in the documentation). Since Scala strips trailing newlines from the standard input, we had to come up with a way to emulate the newline character in the input. We chose a slightly hacky solution, deciding to simply push a newline to the stack for every char input request coming after another char input request (see hueChange5 in Interpreter.scala).