WIP nightmare

This commit is contained in:
2019-01-03 14:16:56 -05:00
parent ed2dc8ba39
commit bba4279ca5
8 changed files with 82 additions and 21 deletions

2
.gitignore vendored
View File

@@ -1,2 +1,2 @@
transcript.hanktest
*.hanktest
examples/shave/

View File

@@ -53,9 +53,9 @@ var smashingWindowItem = NONE;
~ var longgrasshooperframe = false;
// DEBUG mode adds a few shortcuts - remember to set to false in release!
```
// DEBUG mode adds a few shortcuts
// In Hank, DEBUG is set automatically based on the debug argument of the Story() constructor
```
if (DEBUG) {
// Haxe blocks in Hank can contain also Hank blocks!
// The syntax for this is 3 commas, like below.
@@ -98,15 +98,20 @@ if (DEBUG) {
* Hut 14[]. The door was locked after I sat down.
I don't even have a pen to do any work. There's a copy of the morning's intercept in my pocket, but staring at the jumbled letters will only drive me mad.
I am not a machine, whatever they say about me.
```
var idx = 0;
var sequence = ["", "I rattle my fingers on the field table.", ""];
```
- (opts)
{|I rattle my fingers on the field table.|}
// {|I rattle my fingers on the field table.|} // TODO implement alternative sequences
{sequence[idx++]}
* (think) [Think]
They suspect me to be a traitor. They think I stole the component from the calculating machine. They will be searching my bunk and cases.
When they don't find it, {plan:then} they'll come back and demand I talk.
When they don't find it, {if (plan) "then"} they'll come back and demand I talk.
-> opts
* (plan) [Plan]
{not think:What I am is|I am} a problem—solver. Good with figures, quick with crosswords, excellent at chess.
{if (!think) "What I am is" else "I am"} a problem—solver. Good with figures, quick with crosswords, excellent at chess.
But in this scenario — in this trap — what is the winning play?
* * (cooperate) [Co—operate]
I must co—operate. My credibility is my main asset. To contradict myself, or another source, would be fatal.

View File

@@ -5,7 +5,7 @@ B: {choice_b}
C: {choice_c}
* (choice_a) Choice A
* (choice_b) Choice B
* (choice_c) {choice_b + choice_a == 2} Choice C
* (choice_c) {choice_b + choice_a == 2} Choice C // TODO need a better way to && variables
-> end
- -> start

View File

@@ -14,15 +14,30 @@ if (start <= 2) {
- -> sanity
,,,
} else {
, -> the_end
, -> one_more_thing
}
```
This line is a red herring. It should never appear!
== sanity
A brief moment of sanity.
-> start
== the_end
== one_more_thing
Thank God it's over!
One more thing. We need all of the lines
+ after a choice[] to be executed
BEFORE the gather is processed.
```
if (one_more_thing >= 2) {
, -> the_end
}
```
- What up
-> one_more_thing
== the_end
Now it's really over!

View File

@@ -1,2 +1,18 @@
They are keeping me waiting.
* Hut 14
* Hut 14
>>> 0
Hut 14. The door was locked after I sat down.
I don't even have a pen to do any work. There's a copy of the morning's intercept in my pocket, but staring at the jumbled letters will only drive me mad.
I am not a machine, whatever they say about me.
* Think
* Plan
* Wait
>>> 0
They suspect me to be a traitor. They think I stole the component from the calculating machine. They will be searching my bunk and cases.
I rattle my fingers on the field table.
* Plan
* Wait
>>> 0
I am a problem—solver. Good with figures, quick with crosswords, excellent at chess.

View File

@@ -179,11 +179,19 @@ class Story {
}
else if (StringTools.startsWith(trimmedLine, "*") || StringTools.startsWith(trimmedLine, "+")) {
var expires = StringTools.startsWith(trimmedLine, "*");
var depth = 1;
while (trimmedLine.charAt(depth) == trimmedLine.charAt(depth-1)) {
depth += 1;
}
var startingSymbol = trimmedLine.charAt(0);
var expires = startingSymbol == '*';
// For deep choices, spaces between choice symbols are acceptable, i.e. * * as seen in The Intercept source
var depth = 0;
var index = 0;
var c = ' ';
do {
c = trimmedLine.charAt(index);
if (c == startingSymbol) {
depth++;
}
index++;
} while (c == startingSymbol || c == ' ');
// Check for a label in parens
var remainder = StringTools.trim(trimmedLine.substr(depth));

View File

@@ -1,6 +1,7 @@
package src;
import utest.Assert;
import src.StoryFrame;
class StoryTestCase extends utest.Test {
/**
@@ -12,13 +13,16 @@ class StoryTestCase extends utest.Test {
}
private function validateAgainstTranscript(storyFile: String, transcriptFile: String, fullTranscript: Bool = true, debug: Bool = false) {
var story: Story = new Story(debug);
var story: Story = new Story(debug,'validating.hanktest');
story.loadScript(storyFile);
var transcriptLines = sys.io.File.getContent(transcriptFile).split('\n');
var i = 0;
while (i < transcriptLines.length) {
var line = transcriptLines[i];
var frame = story.nextFrame();
trace('Frame ${i}: ${Std.string(frame)}');
if (StringTools.startsWith(line, "*")) {
// Collect the expected set of choices from the transcript.
@@ -28,14 +32,16 @@ class StoryTestCase extends utest.Test {
line = transcriptLines[++i];
} while (line != null && StringTools.startsWith(line, "*"));
trace(choices);
// Assert that the storyframe is a corresponding HasChoices enum
Assert.equals('HasChoices(${Std.string(choices)})', Std.string(story.nextFrame()));
assertComplexEquals(HasChoices(choices), frame);
continue;
} else if (StringTools.startsWith(line, ">>>")) {
// Make the choice given.
var output = story.choose(Std.parseInt(StringTools.trim(line.substr(3))));
trace(output);
if (fullTranscript || transcriptLines.length > i+1) {
// Assert that its output equals the transcript's expected choice output.
Assert.equals(transcriptLines[++i], output);
@@ -46,7 +52,7 @@ class StoryTestCase extends utest.Test {
}
else if (line.length > 0) {
// Assert that the story's next frame is HasText(line)
Assert.equals('HasText(${line})', Std.string(story.nextFrame()));
assertComplexEquals(HasText(line), frame);
}
i += 1;

View File

@@ -11,12 +11,13 @@ class StoryTest extends src.StoryTestCase {
utest.UTest.run([new StoryTest()]);
}
@Ignored
public function testParseHelloWorld() {
var story: Story = new Story();
story.loadScript("examples/hello.hank");
assertComplexEquals(OutputText('Hello, world!'), story.scriptLines[0].type);
story.loadScript("examples/hello.hank"); assertComplexEquals(OutputText('Hello, world!'), story.scriptLines[0].type);
}
@Ignored
public function testHelloWorld() {
var story: Story = new Story();
story.loadScript("examples/hello.hank");
@@ -25,10 +26,12 @@ class StoryTest extends src.StoryTestCase {
Assert.equals(StoryFrame.Finished, story.nextFrame());
}
@Ignored
public function testRunFullSpec2() {
validateAgainstTranscript("examples/main.hank", "examples/tests/main1.hanktest");
}
@Ignored
public function testRunFullSpec3() {
validateAgainstTranscript("examples/main.hank", "examples/tests/main2.hanktest");
}
@@ -36,6 +39,7 @@ class StoryTest extends src.StoryTestCase {
/**
Keep this clunky thing around to sanity check validateAgainstTranscript()
**/
@Ignored
public function testRunFullSpec1() {
var story: Story = new Story(true, "transcript.hanktest");
story.loadScript("examples/main.hank");
@@ -85,6 +89,7 @@ class StoryTest extends src.StoryTestCase {
validateAgainstTranscript("examples/main.hank", "transcript.hanktest");
}
@Ignored
public function testViewCounts() {
var story = new Story(true);
story.loadScript("examples/main.hank");
@@ -96,6 +101,7 @@ class StoryTest extends src.StoryTestCase {
Assert.equals(0, story.interp.variables['choice_example']);
}
@Ignored
public function testParseLine() {
var story = new Story();
assertComplexEquals(IncludeFile("examples/extra.hank"),story.parseLine("INCLUDE examples/extra.hank", []));
@@ -103,6 +109,7 @@ class StoryTest extends src.StoryTestCase {
// TODO test edge cases of all line types (maybe with more separate functions too)
}
@Ignored
public function testParseFullSpec() {
// Parse the main.hank script and test that all lines are correctly parsed
var story = new Story(true);
@@ -170,6 +177,7 @@ class StoryTest extends src.StoryTestCase {
validateAgainstTranscript("examples/TheIntercept.hank", "examples/tests/intercept1.hanktest", false);
}
@Ignored
public function testRunInterceptDebug1() {
validateAgainstTranscript(
"examples/TheIntercept.hank",
@@ -183,17 +191,20 @@ class StoryTest extends src.StoryTestCase {
validateAgainstTranscript("examples/mindfuck.hank", "examples/tests/mindfuck.hanktest", true, true);
}
@Ignored
public function testConditionalBlocks() {
validateAgainstTranscript("examples/conditional.hank", "examples/tests/conditional1.hanktest", true, false);
validateAgainstTranscript("examples/conditional.hank", "examples/tests/conditionalDebug1.hanktest", true, true);
}
@Ignored
public function testLabels() {
validateAgainstTranscript("examples/labels.hank", "examples/tests/labels1.hanktest");
validateAgainstTranscript("examples/labels.hank", "examples/tests/labels2.hanktest");
}
/** Test one of Nat's private WIP Hank stories **/
@Ignored
public function testPrivateStories() {
if (sys.FileSystem.exists('examples/shave')) {
validateAgainstTranscript('examples/shave/shave-draft2.hank', 'examples/shave/tests/1.hanktest');