Skip to content

Commit

Permalink
Debug poem generation
Browse files Browse the repository at this point in the history
  • Loading branch information
drew-cooper committed Oct 3, 2022
1 parent f27908a commit 617053b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
4 changes: 2 additions & 2 deletions 70_Poetry/csharp/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ namespace Poetry;

internal class Context
{
public int U { get; set; }
public int I { get; set; }
public int J { get; set; }
public int J { get; set; }
public int K { get; set; }
public int U { get; set; }
public bool SkipComma { get; set; }
public bool UseGroup2 { get; set; }
}
7 changes: 5 additions & 2 deletions 70_Poetry/csharp/Phrase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,14 @@ private Phrase(Predicate<Context> condition, string text, Action<Context> update

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;
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)
{
if (_condition.Invoke(context))
Expand Down
7 changes: 4 additions & 3 deletions 70_Poetry/csharp/Poem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ internal static void Compose(IReadWrite io, IRandom random)
{
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(",");
context.U = 2;
}
context.SkipComma = false;

if (random.NextFloat() <= 0.65)
if (random.NextFloat() <= 0.65F)
{
io.Write(" ");
context.U += 1;
Expand All @@ -38,7 +39,7 @@ internal static void Compose(IReadWrite io, IRandom random)
io.Write(" ");
}

if (context.J < 4) { break; }
if (context.J < 5) { break; }

context.J = 0;
io.WriteLine();
Expand Down
2 changes: 1 addition & 1 deletion 70_Poetry/csharp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
global using Games.Common.Randomness;
global using Poetry;

Poem.Compose(new ConsoleIO(), new RandomNumberGenerator());
Poem.Compose(new ConsoleIO(), new RandomNumberGenerator());
15 changes: 12 additions & 3 deletions 70_Poetry/poetry.bas
Original file line number Diff line number Diff line change
@@ -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"
20 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
30 PRINT:PRINT:PRINT
Expand Down Expand Up @@ -26,17 +31,21 @@
133 PRINT "SLOWLY CREEPING";:GOTO 210
134 PRINT "...EVERMORE";:GOTO 210
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
212 IF RND(1)>.65 THEN 214
212 GOSUB 500 : IF X>.65 THEN 214
213 PRINT " ";:U=U+1:GOTO 215
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
225 REM PRINT "I=";I;"; J=";J;"; K=";K;"; U=";U
230 IF U>0 OR INT(J/2)<>J/2 THEN 240
235 PRINT " ";
240 ON J GOTO 90,110,120,130,250
250 J=0 : PRINT : IF K>20 THEN 270
260 GOTO 215
270 PRINT : U=0 : K=0 : GOTO 110
500 X = RND(1)
505 REM PRINT "#";X;"#"
510 RETURN
999 END

0 comments on commit 617053b

Please sign in to comment.