Debug poem generation

This commit is contained in:
Andrew Cooper
2022-10-03 21:22:44 +11:00
parent f27908a3e4
commit 617053b1f4
5 changed files with 24 additions and 11 deletions

View File

@@ -2,10 +2,10 @@ namespace Poetry;
internal class Context internal class Context
{ {
public int U { get; set; }
public int I { get; set; } public int I { get; set; }
public int J { get; set; } public int J { get; set; }
public int K { get; set; } public int K { get; set; }
public int U { get; set; }
public bool SkipComma { get; set; } public bool SkipComma { get; set; }
public bool UseGroup2 { get; set; } public bool UseGroup2 { get; set; }
} }

View File

@@ -66,11 +66,14 @@ internal class Phrase
public static Phrase GetPhrase(Context context) public static Phrase GetPhrase(Context context)
{ {
var group = context.UseGroup2 ? _phrases[1] : _phrases[context.J]; var group = GetGroup(context.UseGroup2 ? 2 : context.J);
context.UseGroup2 = false; context.UseGroup2 = false;
return group[context.I % 5]; return group[Math.Max(context.I - 1, 0)];
} }
private static Phrase[] GetGroup(int groupNumber) => _phrases[Math.Max(groupNumber - 1, 0)];
public void Write(IReadWrite io, Context context) public void Write(IReadWrite io, Context context)
{ {
if (_condition.Invoke(context)) if (_condition.Invoke(context))

View File

@@ -10,13 +10,14 @@ internal class Poem
{ {
io.WritePhrase(context); io.WritePhrase(context);
if (!context.SkipComma && context.U != 0 && random.NextFloat() <= 0.19) if (!context.SkipComma && random.NextFloat() <= 0.19F && context.U != 0)
{ {
io.Write(","); io.Write(",");
context.U = 2; context.U = 2;
} }
context.SkipComma = false;
if (random.NextFloat() <= 0.65) if (random.NextFloat() <= 0.65F)
{ {
io.Write(" "); io.Write(" ");
context.U += 1; context.U += 1;
@@ -38,7 +39,7 @@ internal class Poem
io.Write(" "); io.Write(" ");
} }
if (context.J < 4) { break; } if (context.J < 5) { break; }
context.J = 0; context.J = 0;
io.WriteLine(); io.WriteLine();

View File

@@ -2,4 +2,4 @@ global using Games.Common.IO;
global using Games.Common.Randomness; global using Games.Common.Randomness;
global using Poetry; global using Poetry;
Poem.Compose(new ConsoleIO(), new RandomNumberGenerator()); Poem.Compose(new ConsoleIO(), new RandomNumberGenerator());

View File

@@ -1,3 +1,8 @@
5 Y=RND(-1)
6 REM FOR X = 1 TO 100
7 REM PRINT RND(1);","
8 REM NEXT X
9 REM GOTO 999
10 PRINT TAB(30);"POETRY" 10 PRINT TAB(30);"POETRY"
20 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY" 20 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
30 PRINT:PRINT:PRINT 30 PRINT:PRINT:PRINT
@@ -26,17 +31,21 @@
133 PRINT "SLOWLY CREEPING";:GOTO 210 133 PRINT "SLOWLY CREEPING";:GOTO 210
134 PRINT "...EVERMORE";:GOTO 210 134 PRINT "...EVERMORE";:GOTO 210
135 PRINT "NEVERMORE"; 135 PRINT "NEVERMORE";
210 IF U=0 OR RND(1)>.19 THEN 212 210 GOSUB 500 : IF U=0 OR X>.19 THEN 212
211 PRINT ",";:U=2 211 PRINT ",";:U=2
212 IF RND(1)>.65 THEN 214 212 GOSUB 500 : IF X>.65 THEN 214
213 PRINT " ";:U=U+1:GOTO 215 213 PRINT " ";:U=U+1:GOTO 215
214 PRINT : U=0 214 PRINT : U=0
215 I=INT(INT(10*RND(1))/2)+1 215 GOSUB 500 : I=INT(INT(10*X)/2)+1
220 J=J+1 : K=K+1 220 J=J+1 : K=K+1
225 REM PRINT "I=";I;"; J=";J;"; K=";K;"; U=";U
230 IF U>0 OR INT(J/2)<>J/2 THEN 240 230 IF U>0 OR INT(J/2)<>J/2 THEN 240
235 PRINT " "; 235 PRINT " ";
240 ON J GOTO 90,110,120,130,250 240 ON J GOTO 90,110,120,130,250
250 J=0 : PRINT : IF K>20 THEN 270 250 J=0 : PRINT : IF K>20 THEN 270
260 GOTO 215 260 GOTO 215
270 PRINT : U=0 : K=0 : GOTO 110 270 PRINT : U=0 : K=0 : GOTO 110
500 X = RND(1)
505 REM PRINT "#";X;"#"
510 RETURN
999 END 999 END