Poetry
Priskribo de la ĉi-paĝa enhavo
Konvertado de Poetry al pluri program-lingvoj.
Ĉi-tiu programo estas konvertita en 17 program-lingvojn.
Originalo
Origin of poetry.bas:
Unknown author.
Modified and reworked by Jim Bailey, Peggy Ewing, and Dave Ahl at DEC.
Published in "BASIC Computer Games", Creative Computing (Morristown, New Jersey, USA), 1978.
- https://archive.org/details/Basic_Computer_Games_Microcomputer_Edition_1978_Creative_Computing
- https://github.com/chaosotter/basic-games/tree/master/games/BASIC%20Computer%20Games/Poetry
- http://vintage-basic.net/games.html
- http://vintage-basic.net/bcg/poetry.bas
10 PRINT TAB(30); "POETRY"
20 PRINT TAB(15); "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
30 PRINT: PRINT: PRINT: RANDOMIZE TIMER
90 ON I GOTO 100, 101, 102, 103, 104
100 PRINT "MIDNIGHT DREARY";: GOTO 200
101 PRINT "FIERY EYES";: GOTO 200
102 PRINT "BIRD OR FIEND";: GOTO 200
103 PRINT "THING OF EVIL";: GOTO 200
104 PRINT "PROPHET";: GOTO 200
110 ON I GOTO 111, 112, 113, 114, 115
111 PRINT "BEGUILING ME";: U = 2: GOTO 200
112 PRINT "THRILLED ME";: GOTO 200
113 PRINT "STILL SITTING....";: GOTO 212
114 PRINT "NEVER FLITTING";: U = 2: GOTO 200
115 PRINT "BURNED";: GOTO 200
120 ON I GOTO 121, 122, 123, 124, 125
121 PRINT "AND MY SOUL";: GOTO 200
122 PRINT "DARKNESS THERE";: GOTO 200
123 PRINT "SHALL BE LIFTED";: GOTO 200
124 PRINT "QUOTH THE RAVEN";: GOTO 200
125 IF U = 0 THEN 200
126 PRINT "SIGN OF PARTING";: GOTO 200
130 ON I GOTO 131, 132, 133, 134, 135
131 PRINT "NOTHING MORE";: GOTO 200
132 PRINT "YET AGAIN";: GOTO 200
133 PRINT "SLOWLY CREEPING";: GOTO 200
134 PRINT "...EVERMORE";: GOTO 200
135 PRINT "NEVERMORE";
200 ST = TIMER + 0.1
201 IF TIMER < ST THEN 201
210 IF U = 0 OR RND(1) > .19 THEN 212
211 PRINT ",";: U = 2
212 IF RND(1) > .65 THEN 214
213 PRINT " ";: U = U + 1: GOTO 215
214 PRINT: U = 0
215 I = INT(INT(10 * RND(1)) / 2) + 1
220 J = J + 1: K = K + 1
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
999 END
En C#
// Poetry
// Original version in BASIC:
// Unknown author.
// Modified and reworked by Jim Bailey, Peggy Ewing, and Dave Ahl at DEC.
// Published in "BASIC Computer Games", Creative Computing (Morristown, New Jersey, USA), 1978.
// - https://archive.org/details/Basic_Computer_Games_Microcomputer_Edition_1978_Creative_Computing
// - https://github.com/chaosotter/basic-games/tree/master/games/BASIC%20Computer%20Games/Poetry
// - http://vintage-basic.net/games.html
// - http://vintage-basic.net/bcg/poetry.bas
// This improved remake in C#:
// Copyright (c) 2024, Marcos Cruz (programandala.net)
// SPDX-License-Identifier: Fair
//
// Written in 2024-12-24/25.
//
// Last modified: 20251205T1545+0100.
using System;
using System.Threading;
class poetry
{
// Globals {{{1
// =============================================================
const ConsoleColor DEFAULT_COLOR = ConsoleColor.White;
const ConsoleColor INPUT_COLOR = ConsoleColor.Green;
const ConsoleColor TITLE_COLOR = ConsoleColor.Red;
// User input {{{1
// =============================================================
// Print the given prompt and wait until the user enters a string.
//
static string InputString(string prompt = "")
{
Console.ForegroundColor = INPUT_COLOR;
Console.Write(prompt);
string result = Console.ReadLine();
Console.ForegroundColor = DEFAULT_COLOR;
return result;
}
// Print the given prompt and wait until the user presses Enter.
//
static void PressEnter(string prompt)
{
InputString(prompt);
}
// Title and credits {{{1
// =============================================================
// Print the title at the current cursor position.
//
static void PrintTitle()
{
Console.ForegroundColor = TITLE_COLOR;
Console.WriteLine("Poetry");
Console.ForegroundColor = DEFAULT_COLOR;
}
// Print the credits at the current cursor position.
//
static void PrintCredits()
{
PrintTitle();
Console.WriteLine("\nOriginal version in BASIC:");
Console.WriteLine(" Unknown author.");
Console.WriteLine(" Published in \"BASIC Computer Games\",");
Console.WriteLine(" Creative Computing (Morristown, New Jersey, USA), 1978.\n");
Console.WriteLine("This improved remake in C#:");
Console.WriteLine(" Copyright (c) 2024, Marcos Cruz (programandala.net)");
Console.WriteLine(" SPDX-License-Identifier: Fair");
}
// Main {{{1
// =============================================================
// Is the given integer even?
//
static bool IsEven(int n)
{
return (n % 2) == 0;
}
static void Play()
{
const int MAX_PHRASES_AND_VERSES = 20;
// counters:
int action = 0;
int phrase = 0;
int phrasesAndVerses = 0;
int verseChunks = 0;
while (true)
{
verse:
bool manageTheVerseContinuation = true;
bool maybeAddComma = true;
switch (action)
{
case 0:
case 1:
switch (phrase)
{
case 0: Console.Write("MIDNIGHT DREARY"); break;
case 1: Console.Write("FIERY EYES"); break;
case 2: Console.Write("BIRD OR FIEND"); break;
case 3: Console.Write("THING OF EVIL"); break;
case 4: Console.Write("PROPHET"); break;
}
break;
case 2:
switch (phrase)
{
case 0:
Console.Write("BEGUILING ME");
verseChunks = 2;
break;
case 1:
Console.Write("THRILLED ME");
break;
case 2:
Console.Write("STILL SITTING…");
maybeAddComma = false;
break;
case 3:
Console.Write("NEVER FLITTING");
verseChunks = 2;
break;
case 4:
Console.Write("BURNED");
break;
}
break;
case 3:
switch (phrase)
{
case 0:
Console.Write("AND MY SOUL");
break;
case 1:
Console.Write("DARKNESS THERE");
break;
case 2:
Console.Write("SHALL BE LIFTED");
break;
case 3:
Console.Write("QUOTH THE RAVEN");
break;
case 4:
if (verseChunks != 0)
{
Console.Write("SIGN OF PARTING");
}
break;
}
break;
case 4:
switch (phrase)
{
case 0: Console.Write("NOTHING MORE"); break;
case 1: Console.Write("YET AGAIN"); break;
case 2: Console.Write("SLOWLY CREEPING"); break;
case 3: Console.Write("…EVERMORE"); break;
case 4: Console.Write("NEVERMORE"); break;
}
break;
case 5:
action = 0;
Console.WriteLine();
if (phrasesAndVerses > MAX_PHRASES_AND_VERSES)
{
Console.WriteLine();
verseChunks = 0;
phrasesAndVerses = 0;
action = 2;
goto verse;
}
else
{
manageTheVerseContinuation = false;
}
break;
}
Random rand = new Random();
if (manageTheVerseContinuation)
{
Thread.Sleep(250); // milliseconds
if (maybeAddComma && ! (verseChunks == 0 || rand.NextDouble() > 0.19))
{
Console.Write(",");
verseChunks = 2;
}
if (rand.NextDouble() > 0.65)
{
Console.WriteLine();
verseChunks = 0;
}
else
{
Console.Write(" ");
verseChunks += 1;
}
}
action += 1;
phrase = rand.Next(5);
phrasesAndVerses += 1;
if (! (verseChunks > 0 || IsEven(action)))
{
Console.Write(" ");
}
}
// verse loop
}
static void Main()
{
Console.Clear();
PrintCredits();
PressEnter("\nPress the Enter key to start. ");
Console.Clear();
Play();
}
}
En C3
// Poetry
//
// Original version in BASIC:
// Unknown author.
// Modified and reworked by Jim Bailey, Peggy Ewing, and Dave Ahl at DEC.
// Published in "BASIC Computer Games", Creative Computing (Morristown, New Jersey, USA), 1978.
// https://archive.org/details/Basic_Computer_Games_Microcomputer_Edition_1978_Creative_Computing
// https://github.com/chaosotter/basic-games/tree/master/games/BASIC%20Computer%20Games/Poetry
// http://vintage-basic.net/games.html
//
// This improved remake in C3:
// Copyright (c) 2025, Marcos Cruz (programandala.net)
// SPDX-License-Identifier: Fair
//
// Written on 2025-03-08.
//
// Last modified: 20250308T2019+0100.
// Modules {{{1
// =============================================================================
import std::io;
import std::math::random;
import std::thread;
// Terminal {{{1
// =============================================================================
const int BLACK = 0;
const int RED = 1;
const int GREEN = 2;
const int YELLOW = 3;
const int BLUE = 4;
const int MAGENTA = 5;
const int CYAN = 6;
const int WHITE = 7;
const int DEFAULT = 9;
const int STYLE_OFF = 20;
const int FOREGROUND = 30;
const int BACKGROUND = 40;
const int BRIGHT = 60;
const int NORMAL_STYLE = 0;
fn void moveCursorHome() {
io::print("\e[H");
}
fn void setStyle(int style) {
io::printf("\e[%sm", style);
}
fn void resetAttributes() {
setStyle(NORMAL_STYLE);
}
fn void eraseScreen() {
io::print("\e[2J");
}
fn void clearScreen() {
eraseScreen();
resetAttributes();
moveCursorHome();
}
const int DEFAULT_INK = FOREGROUND + WHITE;
const int INPUT_INK = FOREGROUND + BRIGHT + GREEN;
const int TITLE_INK = FOREGROUND + BRIGHT + RED;
// User input {{{1
// =============================================================================
fn String acceptString(String prompt = "") {
io::print(prompt);
String! s = io::readline();
if (catch excuse = s) {
return "";
} else {
return s;
}
}
fn void pressEnter(String prompt = "") {
String discard = acceptString(prompt);
free(discard);
}
// Title and credits {{{1
// =============================================================================
// Print the title at the current cursor position.
//
fn void printTitle() {
setStyle(TITLE_INK);
io::printn("Poetry");
setStyle(DEFAULT_INK);
}
// Print the credits at the current cursor position.
//
fn void printCredits() {
printTitle();
io::printn("\nOriginal version in BASIC:");
io::printn(" Unknown author.");
io::printn(" Published in \"BASIC Computer Games\",");
io::printn(" Creative Computing (Morristown, New Jersey, USA), 1978.\n");
io::printn("This improved remake in C3:");
io::printn(" Copyright (c) 2025, Marcos Cruz (programandala.net)");
io::printn(" SPDX-License-Identifier: Fair");
}
// Main {{{1
// =============================================================================
DefaultRandom rand;
fn void randomize() {
random::seed_entropy(&rand);
}
fn bool isEven(int n) {
return n % 2 == 0;
}
fn void play() {
randomize();
const int MAX_PHRASES_AND_VERSES = 20;
// counters:
int action = 0;
int phrase = 0;
int phrases_and_verses = 0;
int verse_chunks = 0;
while VERSE: (true) {
bool manage_the_verse_continuation = true;
bool maybe_add_comma = true;
switch (action) {
case 0:
case 1:
switch (phrase) {
case 0:
io::print("MIDNIGHT DREARY");
break;
case 1:
io::print("FIERY EYES");
break;
case 2:
io::print("BIRD OR FIEND");
break;
case 3:
io::print("THING OF EVIL");
break;
case 4:
io::print("PROPHET");
}
break;
case 2:
switch (phrase) {
case 0:
io::print("BEGUILING ME");
verse_chunks = 2;
break;
case 1:
io::print("THRILLED ME");
break;
case 2:
io::print("STILL SITTING…");
maybe_add_comma = false;
break;
case 3:
io::print("NEVER FLITTING");
verse_chunks = 2;
break;
case 4:
io::print("BURNED");
}
break;
case 3:
switch (phrase) {
case 0:
io::print("AND MY SOUL");
break;
case 1:
io::print("DARKNESS THERE");
break;
case 2:
io::print("SHALL BE LIFTED");
break;
case 3:
io::print("QUOTH THE RAVEN");
break;
case 4:
if (verse_chunks != 0) {
io::print("SIGN OF PARTING");
}
}
break;
case 4:
switch (phrase) {
case 0:
io::print("NOTHING MORE");
break;
case 1:
io::print("YET AGAIN");
break;
case 2:
io::print("SLOWLY CREEPING");
break;
case 3:
io::print("…EVERMORE");
break;
case 4:
io::print("NEVERMORE");
break;
}
break;
case 5:
action = 0;
io::printn();
if (phrases_and_verses > MAX_PHRASES_AND_VERSES) {
io::printn();
verse_chunks = 0;
phrases_and_verses = 0;
action = 2;
continue VERSE;
} else {
manage_the_verse_continuation = false;
}
}
if (manage_the_verse_continuation) {
thread::sleep_ms(250);
if (maybe_add_comma && !(verse_chunks == 0 || random::next_double(&rand) > 0.19)) {
io::print(",");
verse_chunks = 2;
}
if (random::next_double(&rand) > 0.65) {
io::printn();
verse_chunks = 0;
} else {
io::print(" ");
verse_chunks += 1;
}
}
action += 1;
phrase = random::rand(5);
phrases_and_verses += 1;
if (!(verse_chunks > 0 || isEven(action))) {
io::print(" ");
}
} // verse loop
}
fn void main() {
clearScreen();
printCredits();
pressEnter("\nPress the Enter key to start. ");
clearScreen();
play();
}
En Chapel
// Poetry
// Original version in BASIC:
// Unknown author.
// Modified and reworked by Jim Bailey, Peggy Ewing, and Dave Ahl at DEC.
// Published in "BASIC Computer Games", Creative Computing (Morristown, New Jersey, USA), 1978.
// https://archive.org/details/Basic_Computer_Games_Microcomputer_Edition_1978_Creative_Computing
// https://github.com/chaosotter/basic-games/tree/master/games/BASIC%20Computer%20Games/Poetry
// http://vintage-basic.net/games.html
// This improved remake in Chapel:
// Copyright (c) 2025, Marcos Cruz (programandala.net)
// SPDX-License-Identifier: Fair
//
// Written on 2025-04-05.
//
// Last modified: 20250405T2226+0200.
// Modules {{{1
// =============================================================================
import IO;
import Random;
import Time;
// Terminal {{{1
// =============================================================================
const BLACK = 0;
const RED = 1;
const GREEN = 2;
const YELLOW = 3;
const BLUE = 4;
const MAGENTA = 5;
const CYAN = 6;
const WHITE = 7;
const DEFAULT = 9;
const STYLE_OFF = 20;
const FOREGROUND = 30;
const BACKGROUND = 40;
const BRIGHT = 60;
const NORMAL_STYLE = 0;
proc moveCursorHome() {
writef("\x1B[H");
}
proc setStyle(style: int) {
writef("\x1B[%im", style);
}
proc resetAttributes() {
setStyle(NORMAL_STYLE);
}
proc eraseScreen() {
write("\x1B[2J");
}
proc clearScreen() {
eraseScreen();
resetAttributes();
moveCursorHome();
}
const DEFAULT_INK = FOREGROUND + WHITE;
const INPUT_INK = FOREGROUND + BRIGHT + GREEN;
const TITLE_INK = FOREGROUND + BRIGHT + RED;
// Title and credits {{{1
// =============================================================================
proc printTitle() {
setStyle(TITLE_INK);
writeln("Poetry");
setStyle(DEFAULT_INK);
}
proc printCredits() {
printTitle();
writeln("\nOriginal version in BASIC:");
writeln(" Unknown author.");
writeln(" Published in \"BASIC Computer Games\",");
writeln(" Creative Computing (Morristown, New Jersey, USA), 1978.\n");
writeln("This improved remake in Chapel:");
writeln(" Copyright (c) 2025, Marcos Cruz (programandala.net)");
writeln(" SPDX-License-Identifier: Fair");
}
// Main {{{1
// =============================================================================
proc acceptString(prompt: string): string {
write(prompt);
IO.stdout.flush();
return IO.readLine().strip();
}
proc isEven(n: int): bool {
return n % 2 == 0;
}
proc play() {
var MAX_PHRASES_AND_VERSES: int = 20;
// counters:
var action: int = 0;
var phrase: int = 0;
var phrasesAndVerses: int = 0;
var verseChunks: int = 0;
var rsInt = new Random.randomStream(int);
var rsReal = new Random.randomStream(real);
label verse while true {
var manageTheVerseContinuation: bool = true;
var maybeAddComma: bool = true;
select action {
when 0, 1 {
select phrase {
when 0 do write("MIDNIGHT DREARY");
when 1 do write("FIERY EYES");
when 2 do write("BIRD OR FIEND");
when 3 do write("THING OF EVIL");
when 4 do write("PROPHET");
}
}
when 2 {
select phrase {
when 0 {
write("BEGUILING ME");
verseChunks = 2;
}
when 1 {
write("THRILLED ME");
}
when 2 {
write("STILL SITTING…");
maybeAddComma = false;
}
when 3 {
write("NEVER FLITTING");
verseChunks = 2;
}
when 4 {
write("BURNED");
}
}
}
when 3 {
select phrase {
when 0 {
write("AND MY SOUL");
}
when 1 {
write("DARKNESS THERE");
}
when 2 {
write("SHALL BE LIFTED");
}
when 3 {
write("QUOTH THE RAVEN");
}
when 4 {
if verseChunks != 0 {
write("SIGN OF PARTING");
}
}
}
}
when 4 {
select phrase {
when 0 do write("NOTHING MORE");
when 1 do write("YET AGAIN");
when 2 do write("SLOWLY CREEPING");
when 3 do write("…EVERMORE");
when 4 do write("NEVERMORE");
}
}
when 5 {
action = 0;
writeln("");
if phrasesAndVerses > MAX_PHRASES_AND_VERSES {
writeln("");
verseChunks = 0;
phrasesAndVerses = 0;
action = 2;
continue verse;
}
else {
manageTheVerseContinuation = false;
}
}
}
if manageTheVerseContinuation {
Time.sleep(0.250);
if maybeAddComma && !(verseChunks == 0 || rsReal.next() > 0.19) {
write(",");
verseChunks = 2;
}
if rsReal.next() > 0.65 {
writeln("");
verseChunks = 0;
}
else {
write(" ");
verseChunks += 1;
}
}
action += 1;
phrase = rsInt.next(0, 4);
phrasesAndVerses += 1;
if !(verseChunks > 0 || isEven(action)) {
write(" ");
}
} // verse loop
}
proc main() {
clearScreen();
printCredits();
acceptString("\nPress the Enter key to start. ");
clearScreen();
play();
}
En Crystal
# Poetry
# Original version in BASIC:
# Unknown author.
# Modified and reworked by Jim Bailey, Peggy Ewing, and Dave Ahl at DEC.
# Published in "BASIC Computer Games", Creative Computing (Morristown, New Jersey, USA), 1978.
# https://archive.org/details/Basic_Computer_Games_Microcomputer_Edition_1978_Creative_Computing
# https://github.com/chaosotter/basic-games/tree/master/games/BASIC%20Computer%20Games/Poetry
# http://vintage-basic.net/games.html
# This improved remake in Crystal:
# Copyright (c) 2024, Marcos Cruz (programandala.net)
# SPDX-License-Identifier: Fair
#
# Written on 2024-11-26, 2024-12-12.
#
# Last modified: 20250421T0020+0200.
# Terminal {{{1
# ==============================================================================
# Screen colors
BLACK = 0
RED = 1
GREEN = 2
YELLOW = 3
BLUE = 4
MAGENTA = 5
CYAN = 6
WHITE = 7
DEFAULT = 9
# Screen attributes
NORMAL = 0
# Screen color offsets
FOREGROUND = +30
BRIGHT = +60
# Moves the cursor to the home position.
def home
print "\e[H"
end
# Clears the screen and moves the cursor to the home position.
def clear_screen
print "\e[2J"
home
end
def set_color(color : Int)
print "\e[#{color}m"
end
def set_attribute(attr : Int)
print "\e[0;#{attr}m"
end
DEFAULT_INK = FOREGROUND + WHITE
INPUT_INK = FOREGROUND + BRIGHT + GREEN
TITLE_INK = FOREGROUND + BRIGHT + RED
# User input {{{1
# =============================================================
# Prompts the user to enter a command and returns it.
def input_string(prompt = "> ") : String
s = nil
set_color(INPUT_INK)
while s.is_a?(Nil)
print prompt
s = gets
end
set_color(DEFAULT_INK)
s
end
# Prints the given prompt and wait until the user presses Enter.
def press_enter(prompt : String)
input_string(prompt)
end
# Title and credits {{{1
# =============================================================
# Prints the title at the current cursor position.
def print_title
set_color(TITLE_INK)
puts "Poetry"
set_color(DEFAULT_INK)
end
# Prints the credits at the current cursor position.
def print_credits
print_title
puts
puts "Original version in BASIC:"
puts " Unknown author."
puts " Published in \"BASIC Computer Games\","
puts " Creative Computing (Morristown, New Jersey, USA), 1978."
puts
puts "This improved remake in Crystal:"
puts " Copyright (c) 2024, Marcos Cruz (programandala.net)"
puts " SPDX-License-Identifier: Fair"
end
# Main {{{1
# =============================================================
# Is the given integer even?
def is_even(n : Int) : Bool
return n % 2 == 0
end
MAX_PHRASES_AND_VERSES = 20
def play
action = 0
phrase = 0
phrases_and_verses = 0
verse_chunks = 0
while true
manage_the_verse_continuation = true
maybe_add_comma = true
case action
when 0, 1
case phrase
when 0; print "MIDNIGHT DREARY"
when 1; print "FIERY EYES"
when 2; print "BIRD OR FIEND"
when 3; print "THING OF EVIL"
when 4; print "PROPHET"
end
when 2
case phrase
when 0; print "BEGUILING ME"; verse_chunks = 2
when 1; print "THRILLED ME"
when 2; print "STILL SITTING…"; maybe_add_comma = false
when 3; print "NEVER FLITTING"; verse_chunks = 2
when 4; print "BURNED"
end
when 3
case phrase
when 0; print "AND MY SOUL"
when 1; print "DARKNESS THERE"
when 2; print "SHALL BE LIFTED"
when 3; print "QUOTH THE RAVEN"
when 4
if verse_chunks != 0
print "SIGN OF PARTING"
end
end
when 4
case phrase
when 0; print "NOTHING MORE"
when 1; print "YET AGAIN"
when 2; print "SLOWLY CREEPING"
when 3; print "…EVERMORE"
when 4; print "NEVERMORE"
end
when 5
action = 0
puts
if phrases_and_verses > MAX_PHRASES_AND_VERSES
puts
verse_chunks = 0
phrases_and_verses = 0
action = 2
next
else
manage_the_verse_continuation = false
end
end
if manage_the_verse_continuation
sleep 250.milliseconds
if maybe_add_comma && !(verse_chunks == 0 || rand > 0.19)
print ","
verse_chunks = 2
end
if rand > 0.65
puts
verse_chunks = 0
else
print " "
verse_chunks += 1
end
end
action += 1
phrase = rand(5)
phrases_and_verses += 1
if !(verse_chunks > 0 || is_even(action))
print " "
end
end
end
clear_screen
print_credits
press_enter("\nPress the Enter key to start. ")
clear_screen
play
En D
// Poetry
// Original version in BASIC:
// Unknown author.
// Modified and reworked by Jim Bailey, Peggy Ewing, and Dave Ahl at DEC.
// Published in "BASIC Computer Games", Creative Computing (Morristown, New Jersey, USA), 1978.
// https://archive.org/details/Basic_Computer_Games_Microcomputer_Edition_1978_Creative_Computing
// https://github.com/chaosotter/basic-games/tree/master/games/BASIC%20Computer%20Games/Poetry
// http://vintage-basic.net/games.html
// This improved remake in D:
// Copyright (c) 2025, Marcos Cruz (programandala.net)
// SPDX-License-Identifier: Fair
//
// Written on 2025-03-22.
//
// Last modified: 20251220T0654+0100.
module poetry;
// Terminal {{{1
// =============================================================================
enum BLACK = 0;
enum RED = 1;
enum GREEN = 2;
enum YELLOW = 3;
enum BLUE = 4;
enum MAGENTA = 5;
enum CYAN = 6;
enum WHITE = 7;
enum DEFAULT = 9;
enum STYLE_OFF = 20;
enum FOREGROUND = 30;
enum BACKGROUND = 40;
enum BRIGHT = 60;
enum NORMAL_STYLE = 0;
void moveCursorHome()
{
import std.stdio : writef;
writef("\x1B[H");
}
void setStyle(int style)
{
import std.stdio : writef;
writef("\x1B[%dm", style);
}
void resetAttributes()
{
setStyle(NORMAL_STYLE);
}
void eraseScreen()
{
import std.stdio : write;
write("\x1B[2J");
}
void clearScreen()
{
eraseScreen();
resetAttributes();
moveCursorHome();
}
enum DEFAULT_INK = FOREGROUND + WHITE;
enum INPUT_INK = FOREGROUND + BRIGHT + GREEN;
enum TITLE_INK = FOREGROUND + BRIGHT + RED;
// Title and credits {{{1
// =============================================================================
void printTitle()
{
import std.stdio : writeln;
setStyle(TITLE_INK);
writeln("Poetry");
setStyle(DEFAULT_INK);
}
void printCredits()
{
import std.stdio : writeln;
printTitle();
writeln("\nOriginal version in BASIC:");
writeln(" Unknown author.");
writeln(" Published in \"BASIC Computer Games\",");
writeln(" Creative Computing (Morristown, New Jersey, USA), 1978.\n");
writeln("This improved remake in D:");
writeln(" Copyright (c) 2025, Marcos Cruz (programandala.net)");
writeln(" SPDX-License-Identifier: Fair");
}
// Main {{{1
// =============================================================================
string acceptString(string prompt)
{
import std.stdio : readln;
import std.stdio : write;
import std.string : strip;
write(prompt);
return strip(readln());
}
bool isEven(int n)
{
return n % 2 == 0;
}
void play()
{
import core.thread.osthread : Thread;
import core.time : msecs;
import std.random : uniform;
import std.random : uniform01;
import std.stdio : write;
import std.stdio : writeln;
int MAX_PHRASES_AND_VERSES = 20;
// counters:
int action = 0;
int phrase = 0;
int phrasesAndVerses = 0;
int verseChunks = 0;
verse: while (true)
{
bool manageTheVerseContinuation = true;
bool maybeAddComma = true;
final switch (action)
{
case 0:
case 1:
final switch (phrase)
{
case 0:
write("MIDNIGHT DREARY");
break;
case 1:
write("FIERY EYES");
break;
case 2:
write("BIRD OR FIEND");
break;
case 3:
write("THING OF EVIL");
break;
case 4:
write("PROPHET");
}
break;
case 2:
final switch (phrase)
{
case 0:
write("BEGUILING ME");
verseChunks = 2;
break;
case 1:
write("THRILLED ME");
break;
case 2:
write("STILL SITTING…");
maybeAddComma = false;
break;
case 3:
write("NEVER FLITTING");
verseChunks = 2;
break;
case 4:
write("BURNED");
}
break;
case 3:
final switch (phrase)
{
case 0:
write("AND MY SOUL");
break;
case 1:
write("DARKNESS THERE");
break;
case 2:
write("SHALL BE LIFTED");
break;
case 3:
write("QUOTH THE RAVEN");
break;
case 4:
if (verseChunks != 0)
{
write("SIGN OF PARTING");
}
}
break;
case 4:
final switch (phrase)
{
case 0:
write("NOTHING MORE");
break;
case 1:
write("YET AGAIN");
break;
case 2:
write("SLOWLY CREEPING");
break;
case 3:
write("…EVERMORE");
break;
case 4: write("NEVERMORE");
}
break;
case 5:
action = 0;
writeln();
if (phrasesAndVerses > MAX_PHRASES_AND_VERSES)
{
writeln();
verseChunks = 0;
phrasesAndVerses = 0;
action = 2;
continue verse;
}
else
{
manageTheVerseContinuation = false;
}
}
if (manageTheVerseContinuation)
{
Thread.sleep(250.msecs);
if (maybeAddComma && !(verseChunks == 0 || uniform01() > 0.19))
{
write(",");
verseChunks = 2;
}
if (uniform01() > 0.65)
{
writeln();
verseChunks = 0;
}
else
{
write(" ");
verseChunks += 1;
}
}
action += 1;
phrase = uniform(0, 5);
phrasesAndVerses += 1;
if (!(verseChunks > 0 || isEven(action)))
{
write(" ");
}
} // verse loop
}
void main()
{
clearScreen();
printCredits();
acceptString("\nPress the Enter key to start. ");
clearScreen();
play();
}
En FreeBASIC
' Poetry
'
' Original version in BASIC:
' Unknown author.
' Modified and reworked by Jim Bailey, Peggy Ewing, and Dave Ahl at DEC.
' Published in "BASIC Computer Games", Creative Computing (Morristown, New Jersey, USA), 1978.
' https://archive.org/details/Basic_Computer_Games_Microcomputer_Edition_1978_Creative_Computing
' https://github.com/chaosotter/basic-games/tree/master/games/BASIC%20Computer%20Games/Poetry
' http://vintage-basic.net/games.html
'
' This improved remake in FreeBASIC:
' Copyright (c) 2025, Marcos Cruz (programandala.net)
' SPDX-License-Identifier: Fair
'
' Written on 2025-05-02.
'
' Last modified: 20250503T1904+0200.
' ==============================================================
const DEFAULT_INK = 7 ' white
const INPUT_INK = 10 ' bright green
const TITLE_INK = 12 ' bright red
const MAX_PHRASES_AND_VERSES = 20
sub print_colored(s as string, c as integer)
color(c)
print s;
color(DEFAULT_INK)
end sub
function input_string(prompt as string = "") as string
dim s as string
print_colored(prompt, INPUT_INK)
line input s
return s
end function
sub print_credits()
print_colored(!"Poetry\n\n", TITLE_INK)
print "Original version in BASIC:"
print " Unknown author."
print !" Published in \"BASIC Computer Games\","
print !" Creative Computing (Morristown, New Jersey, USA), 1978.\n"
print "This improved remake in Julia:"
print " Copyright (c) 2024, Marcos Cruz (programandala.net)"
print " SPDX-License-Identifier: Fair"
end sub
function is_even(n as integer) as boolean
return (n mod 2) = 0
end function
sub play()
dim action as integer = 0
dim phrase as integer = 0
dim phrases_and_verses as integer = 0
dim verse_chunks as integer = 0
do while TRUE ' verse loop
dim manage_the_verse_continuation as integer = TRUE
dim maybe_add_comma as integer = TRUE
select case action
case 0, 1
select case phrase
case 0
print "MIDNIGHT DREARY";
case 1
print "FIERY EYES";
case 2
print "BIRD OR FIEND";
case 3
print "THING OF EVIL";
case 4
print "PROPHET";
end select
case 2
select case phrase
case 0
print "BEGUILING ME";
verse_chunks = 2
case 1
print "THRILLED ME";
case 2
print "STILL SITTING…";
maybe_add_comma = FALSE
case 3
print "NEVER FLITTING";
verse_chunks = 2
case 4
print "BURNED";
end select
case 3
select case phrase
case 0
print "AND MY SOUL";
case 1
print "DARKNESS THERE";
case 2
print "SHALL BE LIFTED";
case 3
print "QUOTH THE RAVEN";
case 4 and verse_chunks <> 0
print "SIGN OF PARTING";
end select
case 4
select case phrase
case 0
print "NOTHING MORE";
case 1
print "YET AGAIN";
case 2
print "SLOWLY CREEPING";
case 3
print "…EVERMORE";
case 4
print "NEVERMORE";
end select
case 5
action = 0
print
if phrases_and_verses > MAX_PHRASES_AND_VERSES then
print
verse_chunks = 0
phrases_and_verses = 0
action = 2
continue do
else
manage_the_verse_continuation = FALSE
end if
end select
if manage_the_verse_continuation then
sleep(250) ' ms
if maybe_add_comma and not (verse_chunks = 0 or rnd > 0.19) then
print ",";
verse_chunks = 2
end if
if rnd > 0.65 then
print
verse_chunks = 0
else
print " ";
verse_chunks += 1
end if
end if
action += 1
phrase = int(rnd * 5)
phrases_and_verses += 1
if not (verse_chunks > 0 or is_even(action)) then
print " ";
end if
loop ' verse loop
end sub
cls
print_credits()
input_string(!"\nPress the Enter key to start. ")
cls
play()
' vim: filetype=freebasic
En Go
/*
Poetry
Original version in BASIC:
Unknown author.
Modified and reworked by Jim Bailey, Peggy Ewing, and Dave Ahl at DEC.
Published in "BASIC Computer Games", Creative Computing (Morristown, New Jersey, USA), 1978.
https://archive.org/details/Basic_Computer_Games_Microcomputer_Edition_1978_Creative_Computing
https://github.com/chaosotter/basic-games/tree/master/games/BASIC%20Computer%20Games/Poetry
http://vintage-basic.net/games.html
This improved remake in Go:
Copyright (c) 2024, Marcos Cruz (programandala.net)
SPDX-License-Identifier: Fair
Written on 2024-12-29.
Last modified: 20250105T1152+0100.
*/
package main
import "fmt"
import "math/rand"
import "time"
func clearScreen() {
fmt.Print("\x1B[0;0H\x1B[2J")
}
func input(prompt string) string {
fmt.Print(prompt)
var s = ""
fmt.Scanf("%s", &s)
return s
}
func printCredits() {
fmt.Println("Poetry")
fmt.Println("\nOriginal version in BASIC:")
fmt.Println(" Unknown author.")
fmt.Println(" Published in \"BASIC Computer Games\",")
fmt.Println(" Creative Computing (Morristown, New Jersey, USA), 1978.\n")
fmt.Println("This improved remake in Go:")
fmt.Println(" Copyright (c) 2024, Marcos Cruz (programandala.Net)")
fmt.Println(" SPDX-License-Identifier: Fair")
}
func isEven(n int) bool {
return n%2 == 0
}
func play() {
rand.Seed(time.Now().UTC().UnixNano())
const maxPhrasesAndVerses int = 20
// counters:
var action = 0
var phrase = 0
var phrasesAndVerses = 0
var verseChunks = 0
verse:
for {
var manageTheVerseContinuation = true
var maybeAddComma = true
switch action {
case 0, 1:
switch phrase {
case 0:
fmt.Print("MIDNIGHT DREARY")
case 1:
fmt.Print("FIERY EYES")
case 2:
fmt.Print("BIRD OR FIEND")
case 3:
fmt.Print("THING OF EVIL")
case 4:
fmt.Print("PROPHET")
}
case 2:
switch phrase {
case 0:
fmt.Print("BEGUILING ME")
verseChunks = 2
case 1:
fmt.Print("THRILLED ME")
case 2:
fmt.Print("STILL SITTING…")
maybeAddComma = false
case 3:
fmt.Print("NEVER FLITTING")
verseChunks = 2
case 4:
fmt.Print("BURNED")
}
case 3:
switch phrase {
case 0:
fmt.Print("AND MY SOUL")
case 1:
fmt.Print("DARKNESS THERE")
case 2:
fmt.Print("SHALL BE LIFTED")
case 3:
fmt.Print("QUOTH THE RAVEN")
case 4:
if verseChunks != 0 {
fmt.Print("SIGN OF PARTING")
}
}
case 4:
switch phrase {
case 0:
fmt.Print("NOTHING MORE")
case 1:
fmt.Print("YET AGAIN")
case 2:
fmt.Print("SLOWLY CREEPING")
case 3:
fmt.Print("…EVERMORE")
case 4:
fmt.Print("NEVERMORE")
}
case 5:
action = 0
fmt.Println()
if phrasesAndVerses > maxPhrasesAndVerses {
fmt.Println()
verseChunks = 0
phrasesAndVerses = 0
action = 2
continue verse
} else {
manageTheVerseContinuation = false
}
}
if manageTheVerseContinuation {
time.Sleep(250 * time.Millisecond)
if maybeAddComma && !(verseChunks == 0 || rand.Float64() > 0.19) {
fmt.Print(",")
verseChunks = 2
}
if rand.Float64() > 0.65 {
fmt.Println()
verseChunks = 0
} else {
fmt.Print(" ")
verseChunks += 1
}
}
action += 1
phrase = rand.Intn(5)
phrasesAndVerses += 1
if !(verseChunks > 0 || isEven(action)) {
fmt.Print(" ")
}
} // verse loop
}
func main() {
clearScreen()
printCredits()
input("\nPress the Enter key to start. ")
clearScreen()
play()
}
En Hare
// Poetry
//
// Original version in BASIC:
// Unknown author.
// Modified and reworked by Jim Bailey, Peggy Ewing, and Dave Ahl at DEC.
// Published in "BASIC Computer Games", Creative Computing (Morristown, New Jersey, USA), 1978.
// https://archive.org/details/Basic_Computer_Games_Microcomputer_Edition_1978_Creative_Computing
// https://github.com/chaosotter/basic-games/tree/master/games/BASIC%20Computer%20Games/Poetry
// http://vintage-basic.net/games.html
//
// This improved remake in Hare:
// Copyright (c) 2025, Marcos Cruz (programandala.net)
// SPDX-License-Identifier: Fair
//
// Written on 2025-02-15.
//
// Last modified: 20260213T1645+0100.
// Modules {{{1
// =============================================================================
use bufio;
use fmt;
use math::random;
use os;
use strconv;
use strings;
use time;
// Terminal {{{1
// =============================================================================
def BLACK = 0;
def RED = 1;
def GREEN = 2;
def YELLOW = 3;
def BLUE = 4;
def MAGENTA = 5;
def CYAN = 6;
def WHITE = 7;
def DEFAULT = 9;
def STYLE_OFF = 20;
def FOREGROUND = 30;
def BACKGROUND = 40;
def BRIGHT = 60;
def NORMAL_STYLE = 0;
fn move_cursor_home() void = {
fmt::print("\x1B[H")!;
};
fn set_style(style: int) void = {
fmt::printf("\x1B[{}m", style)!;
};
fn reset_attributes() void = {
set_style(NORMAL_STYLE);
};
fn erase_screen() void = {
fmt::print("\x1B[2J")!;
};
fn clear_screen() void = {
erase_screen();
reset_attributes();
move_cursor_home();
};
def DEFAULT_INK = FOREGROUND + WHITE;
def INPUT_INK = FOREGROUND + BRIGHT + GREEN;
def TITLE_INK = FOREGROUND + BRIGHT + RED;
// User input {{{1
// =============================================================================
fn print_prompt(prompt: str = "") void = {
fmt::print(prompt)!;
bufio::flush(os::stdout)!;
};
fn accept_string(prompt: str = "") str = {
print_prompt(prompt);
const buffer = match (bufio::read_line(os::stdin)!) {
case let buffer: []u8 =>
yield buffer;
case =>
return "";
};
defer free(buffer);
return strings::dup(strings::fromutf8(buffer)!)!;
};
fn press_enter(prompt: str = "") void = {
free(accept_string(prompt));
};
// Title and credits {{{1
// =============================================================================
// Print the title at the current cursor position.
//
fn print_title() void = {
set_style(TITLE_INK);
fmt::println("Poetry")!;
set_style(DEFAULT_INK);
};
// Print the credits at the current cursor position.
//
fn print_credits() void = {
print_title();
fmt::println("\nOriginal version in BASIC:")!;
fmt::println(" Unknown author.")!;
fmt::println(" Published in \"BASIC Computer Games\",")!;
fmt::println(" Creative Computing (Morristown, New Jersey, USA), 1978.\n")!;
fmt::println("This improved remake in Hare:")!;
fmt::println(" Copyright (c) 2025, Marcos Cruz (programandala.net)")!;
fmt::println(" SPDX-License-Identifier: Fair")!;
};
// Random numbers {{{1
// =============================================================================
let rand: random::random = 0;
fn randomize() void = {
rand = random::init(time::now(time::clock::MONOTONIC).sec: u64);
};
// Main {{{1
// =============================================================================
// Is the given integer even?
//
fn is_even(n: int) bool = {
return n % 2 == 0;
};
fn play() void = {
randomize();
def MAX_PHRASES_AND_VERSES = 20;
// counters:
let action = 0;
let phrase = 0;
let phrases_and_verses = 0;
let verse_chunks = 0;
for :verse (true) {
let manage_the_verse_continuation = true;
let maybe_add_comma = true;
switch (action) {
case 0, 1 =>
switch (phrase) {
case 0 => fmt::print("MIDNIGHT DREARY")!;
case 1 => fmt::print("FIERY EYES")!;
case 2 => fmt::print("BIRD OR FIEND")!;
case 3 => fmt::print("THING OF EVIL")!;
case 4 => fmt::print("PROPHET")!;
case => void;
};
case 2 =>
switch (phrase) {
case 0 =>
fmt::print("BEGUILING ME")!;
verse_chunks = 2;
case 1 =>
fmt::print("THRILLED ME")!;
case 2 =>
fmt::print("STILL SITTING…")!;
maybe_add_comma = false;
case 3 =>
fmt::print("NEVER FLITTING")!;
verse_chunks = 2;
case 4 =>
fmt::print("BURNED")!;
case =>
void;
};
case 3 =>
switch (phrase) {
case 0 =>
fmt::print("AND MY SOUL")!;
case 1 =>
fmt::print("DARKNESS THERE")!;
case 2 =>
fmt::print("SHALL BE LIFTED")!;
case 3 =>
fmt::print("QUOTH THE RAVEN")!;
case 4 =>
if (verse_chunks != 0) {
fmt::print("SIGN OF PARTING")!;
};
case =>
void;
};
case 4 =>
switch (phrase) {
case 0 => fmt::print("NOTHING MORE")!;
case 1 => fmt::print("YET AGAIN")!;
case 2 => fmt::print("SLOWLY CREEPING")!;
case 3 => fmt::print("…EVERMORE")!;
case 4 => fmt::print("NEVERMORE")!;
case => void;
};
case 5 =>
action = 0;
fmt::println()!;
if (phrases_and_verses > MAX_PHRASES_AND_VERSES) {
fmt::println()!;
verse_chunks = 0;
phrases_and_verses = 0;
action = 2;
continue :verse;
} else {
manage_the_verse_continuation = false;
};
case =>
void;
};
if (manage_the_verse_continuation) {
time::sleep(250 * time::MILLISECOND);
if (maybe_add_comma && !(verse_chunks == 0 || random::f64rand(&rand) > 0.19)) {
fmt::print(",")!;
verse_chunks = 2;
};
if (random::f64rand(&rand) > 0.65) {
fmt::println()!;
verse_chunks = 0;
} else {
fmt::print(" ")!;
verse_chunks += 1;
};
};
action += 1;
phrase = random::u32n(&rand, 5): int;
phrases_and_verses += 1;
if (!(verse_chunks > 0 || is_even(action))) {
fmt::print(" ")!;
};
}; // verse loop
};
export fn main() void = {
clear_screen();
print_credits();
press_enter("\nPress the Enter key to start. ");
clear_screen();
play();
};
En Janet
# Poetry
# Original version in BASIC:
# Unknown author.
# Modified and reworked by Jim Bailey, Peggy Ewing, and Dave Ahl at DEC.
# Published in "BASIC Computer Games", Creative Computing (Morristown, New Jersey, USA), 1978.
# https://archive.org/details/Basic_Computer_Games_Microcomputer_Edition_1978_Creative_Computing
# https://github.com/chaosotter/basic-games/tree/master/games/BASIC%20Computer%20Games/Poetry
# http://vintage-basic.net/games.html
# This improved remake in Janet:
# Copyright (c) 2025, Marcos Cruz (programandala.net)
# SPDX-License-Identifier: Fair
#
# Written on 2025-12-26.
#
# Last modified: 20251227T1213+0100.
# Terminal {{{1
# =============================================================================
(def black 0)
(def red 1)
(def green 2)
(def yellow 3)
(def blue 4)
(def magenta 5)
(def cyan 6)
(def white 7)
(def default-color 9)
(def style-off 20)
(def foreground 30)
(def background 40)
(def bright 60)
(def normal-style 0)
(defn move-cursor-home []
(prin "\x1B[H"))
(defn set-style [style]
(prin (string/format "\x1B[%dm" style)))
(defn reset-attributes []
(set-style normal-style))
(defn erase-screen []
(prin "\x1B[2J"))
(defn clear-screen []
(erase-screen)
(move-cursor-home)
(reset-attributes))
(def default-ink (+ foreground white))
(def input-ink (+ foreground bright green))
(def title-ink (+ foreground bright red))
# Input {{{1
# =============================================================
(defn input-string [&opt prompt-text]
(default prompt-text "> ")
(set-style input-ink)
(defer (set-style default-ink)
(do
(prin prompt-text)
(flush)
(string/trim (getline)))))
# Title and credits {{{1
# =============================================================
(defn print-title []
(set-style title-ink)
(print "Poetry")
(set-style default-ink))
(defn print-credits []
(print-title)
(print "\nOriginal version in BASIC:")
(print " Unknown author.")
(print " Published in \"BASIC Computer Games\",")
(print " Creative Computing (Morristown, New Jersey, USA), 1978.\n")
(print "This improved remake in Janet:")
(print " Copyright (c) 2025, Marcos Cruz (programandala.net)")
(print " SPDX-License-Identifier: Fair"))
# Main {{{1
# =============================================================
(defn play []
(def max-phrases-and-verses 20)
(var action 0)
(var phrase 0)
(var phrases-and-verses 0)
(var verse-chunks 0)
(def random-number-generator (math/rng (os/time)))
(defn action-0 []
(case phrase
0 (prin "MIDNIGHT DREARY")
1 (prin "FIERY EYES")
2 (prin "BIRD OR FIEND")
3 (prin "THING OF EVIL")
4 (prin "PROPHET")))
(while true
(prompt :top
(var manage-the-verse-continuation true)
(var maybe-add-comma true)
(case action
0 (action-0)
1 (action-0)
2
(case phrase
0 (do (prin "BEGUILING ME") (set verse-chunks 2))
1 (prin "THRILLED ME")
2 (do (prin "STILL SITTING…") (set maybe-add-comma false))
3 (do (prin "NEVER FLITTING") (set verse-chunks 2))
4 (prin "BURNED"))
3
(case phrase
0 (prin "AND MY SOUL")
1 (prin "DARKNESS THERE")
2 (prin "SHALL BE LIFTED")
3 (prin "QUOTH THE RAVEN")
4 (when (not= verse-chunks 0) (prin "SIGN OF PARTING")))
4
(case phrase
0 (prin "NOTHING MORE")
1 (prin "YET AGAIN")
2 (prin "SLOWLY CREEPING")
3 (prin "…EVERMORE")
4 (prin "NEVERMORE"))
5
(do
(set action 0)
(print)
(if (> phrases-and-verses max-phrases-and-verses)
(do
(print)
(set verse-chunks 0)
(set phrases-and-verses 0)
(set action 2)
(return :top))
(set manage-the-verse-continuation false))))
(when manage-the-verse-continuation
(os/sleep 0.250)
(when (and maybe-add-comma (not (or (= verse-chunks 0) (> (math/random) 0.19))))
(prin ",")
(set verse-chunks 2))
(if (> (math/random) 0.65)
(do
(print)
(set verse-chunks 0))
(do
(prin " ")
(+= verse-chunks 1))))
(+= action 1)
(set phrase (math/rng-int random-number-generator 5))
(+= phrases-and-verses 1)
(when (not (or (> verse-chunks 0) (even? action)))
(prin " ")))))
(defn main [& args]
(clear-screen)
(print-credits)
(input-string "\nPress the Enter key to start. ")
(clear-screen)
(play))
En Julia
#=
Poetry
Original version in BASIC:
Unknown author.
Modified and reworked by Jim Bailey, Peggy Ewing, and Dave Ahl at DEC.
Published in "BASIC Computer Games", Creative Computing (Morristown, New Jersey, USA), 1978.
https://archive.org/details/Basic_Computer_Games_Microcomputer_Edition_1978_Creative_Computing
https://github.com/chaosotter/basic-games/tree/master/games/BASIC%20Computer%20Games/Poetry
http://vintage-basic.net/games.html
This improved remake in Julia:
Copyright (c) 2024, Marcos Cruz (programandala.net)
SPDX-License-Identifier: Fair
Written in 2024-07-08/11, on 2024-12-12.
Last modified: 20241212T2240+0100.
=#
# ==============================================================
const DEFAULT_INK = :white
const INPUT_INK = :light_green
const TITLE_INK = :light_red
const MAX_PHRASES_AND_VERSES = 20
# Move the cursor to the home position.
function home()
print("\e[H")
end
# Clear the screen and move the cursor to the home position.
function clear_screen()
print("\e[2J")
home()
end
# Print the given prompt and wait until the user enters a string.
function input_string(prompt::String = "")::String
printstyled(prompt, color = INPUT_INK)
return readline()
end
# Print the given prompt and wait until the user enters an empty string.
function press_enter(prompt::String)
while ! (input_string(prompt) == "")
end
end
# Print the credits at the current cursor position.
function print_credits()
printstyled("Poetry\n\n", color = TITLE_INK)
println("Original version in BASIC:")
println(" Unknown author.")
println(" Published in \"BASIC Computer Games\",")
println(" Creative Computing (Morristown, New Jersey, USA), 1978.\n")
println("This improved remake in Julia:")
println(" Copyright (c) 2024, Marcos Cruz (programandala.net)")
println(" SPDX-License-Identifier: Fair")
end
function play()
action = 0
phrase = 0
phrases_and_verses = 0
verse_chunks = 0
while true # verse loop
manage_the_verse_continuation = true
maybe_add_comma = true
if action in [0, 1]
if phrase == 0
print("MIDNIGHT DREARY")
elseif phrase == 1
print("FIERY EYES")
elseif phrase == 2
print("BIRD OR FIEND")
elseif phrase == 3
print("THING OF EVIL")
elseif phrase == 4
print("PROPHET")
end
elseif action == 2
if phrase == 0
print("BEGUILING ME")
verse_chunks = 2
elseif phrase == 1
print("THRILLED ME")
elseif phrase == 2
print("STILL SITTING…")
maybe_add_comma = false
elseif phrase == 3
print("NEVER FLITTING")
verse_chunks = 2
elseif phrase == 4
print("BURNED")
end
elseif action == 3
if phrase == 0
print("AND MY SOUL")
elseif phrase == 1
print("DARKNESS THERE")
elseif phrase == 2
print("SHALL BE LIFTED")
elseif phrase == 3
print("QUOTH THE RAVEN")
elseif phrase == 4 && verse_chunks != 0
print("SIGN OF PARTING")
end
elseif action == 4
if phrase == 0
print("NOTHING MORE")
elseif phrase == 1
print("YET AGAIN")
elseif phrase == 2
print("SLOWLY CREEPING")
elseif phrase == 3
print("…EVERMORE")
elseif phrase == 4
print("NEVERMORE")
end
elseif action == 5
action = 0
println()
if phrases_and_verses > MAX_PHRASES_AND_VERSES
println()
verse_chunks = 0
phrases_and_verses = 0
action = 2
continue
else
manage_the_verse_continuation = false
end
end
if manage_the_verse_continuation
sleep(0.250) # 250 ms
if maybe_add_comma && ! (verse_chunks == 0 || rand() > 0.19)
print(",")
verse_chunks = 2
end
if rand() > 0.65
println()
verse_chunks = 0
else
print(" ")
verse_chunks += 1
end
end
action += 1
phrase = rand(0 : 4)
phrases_and_verses += 1
if ! (verse_chunks > 0 || iseven(action))
print(" ")
end
end # verse loop
end
clear_screen()
print_credits()
press_enter("\nPress the Enter key to start. ")
clear_screen()
play()
En Kotlin
/*
Poetry
Original version in BASIC:
Unknown author.
Modified and reworked by Jim Bailey, Peggy Ewing, and Dave Ahl at DEC.
Published in "BASIC Computer Games", Creative Computing (Morristown, New Jersey, USA), 1978.
https://archive.org/details/Basic_Computer_Games_Microcomputer_Edition_1978_Creative_Computing
https://github.com/chaosotter/basic-games/tree/master/games/BASIC%20Computer%20Games/Poetry
http://vintage-basic.net/games.html
This improved remake in Kotlin:
Copyright (c) 2025, Marcos Cruz (programandala.net)
SPDX-License-Identifier: Fair
Written in 2025-05-17/18.
Last modified: 20250731T1954+0200.
*/
import kotlin.random.Random
import kotlin.time.*
// Terminal {{{1
// =============================================================
const val BLACK = 0
const val RED = 1
const val GREEN = 2
const val YELLOW = 3
const val BLUE = 4
const val MAGENTA = 5
const val CYAN = 6
const val WHITE = 7
const val DEFAULT = 9
const val FOREGROUND = +30
const val BACKGROUND = +40
const val BRIGHT = +60
// Move the cursor to the top left position of the terminal.
fun moveCursorHome() {
print("\u001B[H")
}
// Clear the terminal and move the cursor to the top left position.
fun clearScreen() {
print("\u001B[2J")
moveCursorHome()
}
// Set the color.
fun setColor(color: Int) {
print("\u001B[${color}m")
}
// Globals {{{1
// =============================================================
const val DEFAULT_INK = WHITE + FOREGROUND
const val INPUT_INK = BRIGHT + GREEN + FOREGROUND
const val TITLE_INK = BRIGHT + RED + FOREGROUND
// User input {{{1
// =============================================================
fun pressEnter(prompt: String) {
setColor(INPUT_INK)
print(prompt)
readln()
setColor(DEFAULT_INK)
}
// Title and credits {{{1
// =============================================================
fun printTitle() {
setColor(TITLE_INK)
println("Poetry")
setColor(DEFAULT_INK)
}
fun printCredits() {
printTitle()
println("\nOriginal version in BASIC:")
println(" Unknown author.")
println(" Published in \"BASIC Computer Games\",")
println(" Creative Computing (Morristown, New Jersey, USA), 1978.\n")
println("This improved remake in Kotlin:")
println(" Copyright (c) 2025, Marcos Cruz (programandala.net)")
println(" SPDX-License-Identifier: Fair")
}
// Time {{{1
// =============================================================
// Wait the given number of seconds.
//
// Note `Thread.sleep(1000 * seconds)` (provided by `import
// kotlin.concurrent.thread`) would be a simpler alternative, but it's not
// supported by kotlinc-native.
//
fun waitSeconds(seconds: Double) {
val duration: Duration = seconds.toDuration(DurationUnit.SECONDS)
val timeSource = TimeSource.Monotonic
val startTime = timeSource.markNow()
do {
var currentTime = timeSource.markNow()
} while ((currentTime - startTime) < duration)
}
// Main {{{1
// =============================================================
fun isEven(n: Int): Boolean {
return n.rem(2) == 0
}
fun play() {
val MAX_PHRASES_AND_VERSES = 20
// counters:
var action = 0
var phrase = 0
var phrasesAndVerses = 0
var verseChunks = 0
verse@ while (true) {
var manageTheVerseContinuation = true
var maybeAddComma = true
when (action) {
0, 1 ->
when (phrase) {
0 -> print("MIDNIGHT DREARY")
1 -> print("FIERY EYES")
2 -> print("BIRD OR FIEND")
3 -> print("THING OF EVIL")
4 -> print("PROPHET")
}
2 ->
when (phrase) {
0 -> { print("BEGUILING ME"); verseChunks = 2 }
1 -> print("THRILLED ME")
2 -> { print("STILL SITTING…"); maybeAddComma = false }
3 -> { print("NEVER FLITTING"); verseChunks = 2 }
4 -> print("BURNED")
}
3 ->
when (phrase) {
0 -> print("AND MY SOUL")
1 -> print("DARKNESS THERE")
2 -> print("SHALL BE LIFTED")
3 -> print("QUOTH THE RAVEN")
4 -> if (verseChunks != 0) print("SIGN OF PARTING")
}
4 ->
when (phrase) {
0 -> print("NOTHING MORE")
1 -> print("YET AGAIN")
2 -> print("SLOWLY CREEPING")
3 -> print("…EVERMORE")
4 -> print("NEVERMORE")
}
5 -> {
action = 0
println()
if (phrasesAndVerses > MAX_PHRASES_AND_VERSES) {
println()
verseChunks = 0
phrasesAndVerses = 0
action = 2
continue@verse
} else {
manageTheVerseContinuation = false
}
}
}
if (manageTheVerseContinuation) {
waitSeconds(0.25)
if (maybeAddComma && ! (verseChunks == 0 || Random.nextDouble() > 0.19)) {
print(",")
verseChunks = 2
}
if (Random.nextDouble() > 0.65) {
println()
verseChunks = 0
} else {
print(" ")
verseChunks += 1
}
}
action += 1
phrase = Random.nextInt(0, 4)
phrasesAndVerses += 1
if (! (verseChunks > 0 || isEven(action))) {
print(" ")
}
} // verse loop
}
fun main() {
clearScreen()
printCredits()
pressEnter("\nPress the Enter key to start. ")
clearScreen()
play()
}
En Nim
#[
Poetry
Original version in BASIC:
Unknown author.
Modified and reworked by Jim Bailey, Peggy Ewing, and Dave Ahl at DEC.
Published in "BASIC Computer Games", Creative Computing (Morristown, New Jersey, USA), 1978.
https://archive.org/details/Basic_Computer_Games_Microcomputer_Edition_1978_Creative_Computing
https://github.com/chaosotter/basic-games/tree/master/games/BASIC%20Computer%20Games/Poetry
http://vintage-basic.net/games.html
This remake in Nim:
Copyright (c) 2025, Marcos Cruz (programandala.net)
SPDX-License-Identifier: Fair
Written on 2025-01-16.
Last modified: 20250121T0253+0100.
]#
import os
import std/random
import std/terminal
const inputInk = fgGreen
const titleInk = fgRed
proc cursorHome() =
setCursorPos 0, 0
proc clearScreen() =
eraseScreen()
cursorHome()
proc pressAnyKey() =
setForegroundColor(inputInk)
write(stdout, "\nPress any Enter key to start. ")
setForegroundColor(fgDefault)
discard getch()
proc printCredits() =
setForegroundColor(titleInk)
writeLine(stdout, "Poetry")
setForegroundColor(fgDefault)
writeLine(stdout, "\nOriginal version in BASIC:")
writeLine(stdout, " Unknown author.")
writeLine(stdout, " Published in \"BASIC Computer Games\",")
writeLine(stdout, " Creative Computing (Morristown, New Jersey, USA), 1978.\n")
writeLine(stdout, "This improved remake in Nim:")
writeLine(stdout, " Copyright (c) 2025, Marcos Cruz (programandala.net)")
writeLine(stdout, " SPDX-License-Identifier: Fair")
proc isEven(x: int): bool =
return x mod 2 == 0
const MAXPHRASESANDVERSES = 20
# counters:
var action = 0
var phrase = 0
var phrasesAndVerses = 0
var verseChunks = 0
proc verse() =
var manageTheVerseContinuation = true
var maybeAddComma = true
case action
of 0, 1:
case phrase:
of 0: write(stdout, "MIDNIGHT DREARY")
of 1: write(stdout, "FIERY EYES")
of 2: write(stdout, "BIRD OR FIEND")
of 3: write(stdout, "THING OF EVIL")
of 4: write(stdout, "PROPHET")
else: discard
of 2:
case phrase:
of 0:
write(stdout, "BEGUILING ME")
verseChunks = 2
of 1:
write(stdout, "THRILLED ME")
of 2:
write(stdout, "STILL SITTING…")
maybeAddComma = false
of 3:
write(stdout, "NEVER FLITTING")
verseChunks = 2
of 4:
write(stdout, "BURNED")
else:
discard
of 3:
case phrase:
of 0:
write(stdout, "AND MY SOUL")
of 1:
write(stdout, "DARKNESS THERE")
of 2:
write(stdout, "SHALL BE LIFTED")
of 3:
write(stdout, "QUOTH THE RAVEN")
of 4:
if verseChunks != 0:
write(stdout, "SIGN OF PARTING")
else:
discard
of 4:
case phrase:
of 0: write(stdout, "NOTHING MORE")
of 1: write(stdout, "YET AGAIN")
of 2: write(stdout, "SLOWLY CREEPING")
of 3: write(stdout, "…EVERMORE")
of 4: write(stdout, "NEVERMORE")
else: discard
of 5:
action = 0
writeLine(stdout, "")
if phrasesAndVerses > MAXPHRASESANDVERSES:
writeLine(stdout, "")
verseChunks = 0
phrasesAndVerses = 0
action = 2
return
else:
manageTheVerseContinuation = false
else: discard
if manageTheVerseContinuation:
sleep(250) # ms
if maybeAddComma and not (verseChunks == 0 or rand(1.0) > 0.19):
write(stdout, ",")
verseChunks = 2
if rand(1.0) > 0.65:
writeLine(stdout, "")
verseChunks = 0
else:
write(stdout, " ")
verseChunks += 1
action += 1
phrase = rand(5)
phrasesAndVerses += 1
if not (verseChunks > 0 or isEven(action)):
write(stdout, " ")
proc play() =
while true:
verse()
clearScreen()
printCredits()
pressAnyKey()
clearScreen()
play()
En Odin
/*
Poetry
Original version in BASIC:
Unknown author.
Modified and reworked by Jim Bailey, Peggy Ewing, and Dave Ahl at DEC.
Published in "BASIC Computer Games", Creative Computing (Morristown, New Jersey, USA), 1978.
https://archive.org/details/Basic_Computer_Games_Microcomputer_Edition_1978_Creative_Computing
https://github.com/chaosotter/basic-games/tree/master/games/BASIC%20Computer%20Games/Poetry
http://vintage-basic.net/games.html
This improved remake in Odin:
Copyright (c) 2023, 2024, 2025, Marcos Cruz (programandala.net)
SPDX-License-Identifier: Fair
Written on 2023-12-14, 2024-07-11, 2024-12-12/13, 2025-02-27.
Last modified: 20250731T1954+0200.
*/
package poetry
import "../lib/anodino/src/basic"
import "../lib/anodino/src/read"
import "../lib/anodino/src/term"
import "core:fmt"
import "core:math/rand"
import "core:time"
// Globals {{{1
// =============================================================
DEFAULT_INK :: basic.WHITE
INPUT_INK :: basic.BRIGHT_GREEN
TITLE_INK :: basic.BRIGHT_RED
// User input {{{1
// =============================================================
// Print the given prompt and wait until the user enters a string.
//
input_string :: proc(prompt : string = "") -> (string, bool) {
basic.color(INPUT_INK)
defer basic.color(DEFAULT_INK)
fmt.print(prompt)
return read.a_string()
}
// Print the given prompt and wait until the user presses Enter.
//
press_enter :: proc(prompt : string) {
s, _ := input_string(prompt)
delete(s)
}
// Title and credits {{{1
// =============================================================
// Print the title at the current cursor position.
//
print_title :: proc() {
basic.color(TITLE_INK)
fmt.println("Poetry")
basic.color(DEFAULT_INK)
}
// Print the credits at the current cursor position.
//
print_credits :: proc() {
print_title()
fmt.println("\nOriginal version in BASIC:")
fmt.println(" Unknown author.")
fmt.println(" Published in \"BASIC Computer Games\",")
fmt.println(" Creative Computing (Morristown, New Jersey, USA), 1978.\n")
fmt.println("This improved remake in Odin:")
fmt.println(" Copyright (c) 2023, 2024, 2025, Marcos Cruz (programandala.net)")
fmt.println(" SPDX-License-Identifier: Fair")
}
// Main {{{1
// =============================================================
// Wait the given number of nanoseconds.
//
nanoseconds :: proc(ns : i64) {
for end := time.now()._nsec + ns; time.now()._nsec < end; { }
}
// Is the given integer even?
//
is_even :: proc(n : int) -> bool {
return n %% 2 == 0
}
play :: proc() {
basic.randomize()
MAX_PHRASES_AND_VERSES :: 20
// counters:
action := 0
phrase := 0
phrases_and_verses := 0
verse_chunks := 0
verse: for {
manage_the_verse_continuation := true
maybe_add_comma := true
switch action {
case 0, 1 :
switch phrase {
case 0 : fmt.print("MIDNIGHT DREARY")
case 1 : fmt.print("FIERY EYES")
case 2 : fmt.print("BIRD OR FIEND")
case 3 : fmt.print("THING OF EVIL")
case 4 : fmt.print("PROPHET")
}
case 2 :
switch phrase {
case 0 : fmt.print("BEGUILING ME")
verse_chunks = 2
case 1 : fmt.print("THRILLED ME")
case 2 : fmt.print("STILL SITTING…")
maybe_add_comma = false
case 3 : fmt.print("NEVER FLITTING")
verse_chunks = 2
case 4 : fmt.print("BURNED")
}
case 3 :
switch phrase {
case 0 : fmt.print("AND MY SOUL")
case 1 : fmt.print("DARKNESS THERE")
case 2 : fmt.print("SHALL BE LIFTED")
case 3 : fmt.print("QUOTH THE RAVEN")
case 4 : if verse_chunks != 0 do fmt.print("SIGN OF PARTING")
}
case 4 :
switch phrase {
case 0 : fmt.print("NOTHING MORE")
case 1 : fmt.print("YET AGAIN")
case 2 : fmt.print("SLOWLY CREEPING")
case 3 : fmt.print("…EVERMORE")
case 4 : fmt.print("NEVERMORE")
}
case 5 :
action = 0
fmt.println()
if phrases_and_verses > MAX_PHRASES_AND_VERSES {
fmt.println()
verse_chunks = 0
phrases_and_verses = 0
action = 2
continue verse
} else {
manage_the_verse_continuation = false
}
}
if manage_the_verse_continuation {
nanoseconds(250_000_000) // 250 ms
if maybe_add_comma && ! (verse_chunks == 0 || rand.float64() > 0.19) {
fmt.print(",")
verse_chunks = 2
}
if rand.float64() > 0.65 {
fmt.println()
verse_chunks = 0
} else {
fmt.print(" ")
verse_chunks += 1
}
}
action += 1
phrase = rand.int_max(5)
phrases_and_verses += 1
if ! (verse_chunks > 0 || is_even(action)) {
fmt.print(" ")
}
} // verse loop
}
main :: proc() {
term.clear_screen()
print_credits()
press_enter("\nPress the Enter key to start. ")
term.clear_screen()
play()
}
En Pike
#! /usr/bin/env pike
// Poetry
// Original version in BASIC:
// Unknown author.
// Modified and reworked by Jim Bailey, Peggy Ewing, and Dave Ahl at DEC.
// Published in "BASIC Computer Games", Creative Computing (Morristown, New Jersey, USA), 1978.
// https://archive.org/details/Basic_Computer_Games_Microcomputer_Edition_1978_Creative_Computing
// https://github.com/chaosotter/basic-games/tree/master/games/BASIC%20Computer%20Games/Poetry
// http://vintage-basic.net/games.html
// This improved remake in Pike:
// Copyright (c) 2025, Marcos Cruz (programandala.net)
// SPDX-License-Identifier: Fair
//
// Written on 2025-03-08.
//
// Last modified: 20250310T0302+0100.
// Terminal {{{1
// =============================================================================
constant BLACK = 0;
constant RED = 1;
constant GREEN = 2;
constant YELLOW = 3;
constant BLUE = 4;
constant MAGENTA = 5;
constant CYAN = 6;
constant WHITE = 7;
constant DEFAULT = 9;
constant STYLE_OFF = 20;
constant FOREGROUND = 30;
constant BACKGROUND = 40;
constant BRIGHT = 60;
constant NORMAL_STYLE = 0;
void move_cursor_home() {
write("\x1B[H");
}
void set_style(int style) {
write("\x1B[%dm", style);
}
void reset_attributes() {
set_style(NORMAL_STYLE);
}
void erase_screen() {
write("\x1B[2J");
}
void clear_screen() {
erase_screen();
reset_attributes();
move_cursor_home();
}
constant DEFAULT_INK = FOREGROUND + WHITE;
constant INPUT_INK = FOREGROUND + BRIGHT + GREEN;
constant TITLE_INK = FOREGROUND + BRIGHT + RED;
// Title and credits {{{1
// =============================================================================
void print_title() {
set_style(TITLE_INK);
write("Poetry\n");
set_style(DEFAULT_INK);
}
void print_credits() {
print_title();
write("\nOriginal version in BASIC:\n");
write(" Unknown author.\n");
write(" Published in \"BASIC Computer Games\",\n");
write(" Creative Computing (Morristown, New Jersey, USA), 1978.\n\n");
write("This improved remake in Pike:\n");
write(" Copyright (c) 2025, Marcos Cruz (programandala.net)\n");
write(" SPDX-License-Identifier: Fair\n");
}
// Main {{{1
// =============================================================================
string accept_string(string prompt) {
write(prompt);
return Stdio.stdin->gets();
}
bool is_even(int n) {
return n % 2 == 0;
}
void play() {
int MAX_PHRASES_AND_VERSES = 20;
// counters:
int action = 0;
int phrase = 0;
int phrases_and_verses = 0;
int verse_chunks = 0;
verse: while (true) {
bool manage_the_verse_continuation = true;
bool maybe_add_comma = true;
switch (action) {
case 0:
case 1:
switch (phrase) {
case 0:
write("MIDNIGHT DREARY");
break;
case 1:
write("FIERY EYES");
break;
case 2:
write("BIRD OR FIEND");
break;
case 3:
write("THING OF EVIL");
break;
case 4:
write("PROPHET");
}
break;
case 2:
switch (phrase) {
case 0:
write("BEGUILING ME");
verse_chunks = 2;
break;
case 1:
write("THRILLED ME");
break;
case 2:
write("STILL SITTING…");
maybe_add_comma = false;
break;
case 3:
write("NEVER FLITTING");
verse_chunks = 2;
break;
case 4:
write("BURNED");
}
break;
case 3:
switch (phrase) {
case 0:
write("AND MY SOUL");
break;
case 1:
write("DARKNESS THERE");
break;
case 2:
write("SHALL BE LIFTED");
break;
case 3:
write("QUOTH THE RAVEN");
break;
case 4:
if (verse_chunks != 0) {
write("SIGN OF PARTING");
}
}
break;
case 4:
switch (phrase) {
case 0:
write("NOTHING MORE");
break;
case 1:
write("YET AGAIN");
break;
case 2:
write("SLOWLY CREEPING");
break;
case 3:
write("…EVERMORE");
break;
case 4: write("NEVERMORE");
}
break;
case 5:
action = 0;
write("\n");
if (phrases_and_verses > MAX_PHRASES_AND_VERSES) {
write("\n");
verse_chunks = 0;
phrases_and_verses = 0;
action = 2;
continue verse;
} else {
manage_the_verse_continuation = false;
}
}
if (manage_the_verse_continuation) {
sleep(.25);
if (maybe_add_comma && !(verse_chunks == 0 || random(1.0) > 0.19)) {
write(",");
verse_chunks = 2;
}
if (random(1.0) > 0.65) {
write("\n");
verse_chunks = 0;
} else {
write(" ");
verse_chunks += 1;
}
}
action += 1;
phrase = random(5);
phrases_and_verses += 1;
if (!(verse_chunks > 0 || is_even(action))) {
write(" ");
}
} // verse loop
}
void main() {
clear_screen();
print_credits();
accept_string("\nPress the Enter key to start. ");
clear_screen();
play();
}
En Python
# Poetry
# Original version in BASIC:
# Unknown author.
# Modified and reworked by Jim Bailey, Peggy Ewing, and Dave Ahl at DEC.
# Published in "BASIC Computer Games", Creative Computing (Morristown, New Jersey, USA), 1978.
# https://archive.org/details/Basic_Computer_Games_Microcomputer_Edition_1978_Creative_Computing
# https://github.com/chaosotter/basic-games/tree/master/games/BASIC%20Computer%20Games/Poetry
# http://vintage-basic.net/games.html
# This version in Python:
# Copyright (c) 2024, Marcos Cruz (programandala.net)
# SPDX-License-Identifier: Fair
#
# Written on 2024-10-29, 2024-12-12.
#
# Last modified: 20241212T2228+0100.
# ==============================================================
import os
import random
from time import sleep
MAX_PHRASES_AND_VERSES = 20
# Clear the screen.
def clear_screen():
if os.name == 'nt':
_ = os.system('cls')
else:
# on mac and linux, `os.name` is 'posix'
_ = os.system('clear')
# Print the given prompt and wait until the user enters an empty string.
def press_enter(prompt = ""):
input_string = "x"
while not input_string == "":
input_string = input(prompt)
# Print the credits at the current cursor position.
def print_credits():
print("Poetry\n")
print("Original version in BASIC:")
print(" Unknown author.")
print(" Published in \"BASIC Computer Games\",")
print(" Creative Computing (Morristown, New Jersey, USA), 1978.\n")
print("This improved remake in Julia:")
print(" Copyright (c) 2024, Marcos Cruz (programandala.net)")
print(" SPDX-License-Identifier: Fair")
def is_odd(n):
return n % 2 != 0
def play():
action = 0
phrase = 0
phrases_and_verses = 0
verse_chunks = 0
while True: # verse loop
manage_the_verse_continuation = True
maybe_add_comma = True
if action in [0, 1]:
if phrase == 0:
print("MIDNIGHT DREARY", end = "")
elif phrase == 1:
print("FIERY EYES", end = "")
elif phrase == 2:
print("BIRD OR FIEND", end = "")
elif phrase == 3:
print("THING OF EVIL", end = "")
elif phrase == 4:
print("PROPHET", end = "")
elif action == 2 :
if phrase == 0:
print("BEGUILING ME", end = "")
verse_chunks = 2
elif phrase == 1:
print("THRILLED ME", end = "")
elif phrase == 2:
print("STILL SITTING…", end = "")
maybe_add_comma = False
elif phrase == 3:
print("NEVER FLITTING", end = "")
verse_chunks = 2
elif phrase == 4:
print("BURNED", end = "")
elif action == 3 :
if phrase == 0:
print("AND MY SOUL", end = "")
elif phrase == 1:
print("DARKNESS THERE", end = "")
elif phrase == 2:
print("SHALL BE LIFTED", end = "")
elif phrase == 3:
print("QUOTH THE RAVEN", end = "")
elif phrase == 4 and verse_chunks != 0:
print("SIGN OF PARTING", end = "")
elif action == 4 :
if phrase == 0:
print("NOTHING MORE", end = "")
elif phrase == 1:
print("YET AGAIN", end = "")
elif phrase == 2:
print("SLOWLY CREEPING", end = "")
elif phrase == 3:
print("…EVERMORE", end = "")
elif phrase == 4:
print("NEVERMORE", end = "")
elif action == 5 :
action = 0
print()
if phrases_and_verses > MAX_PHRASES_AND_VERSES:
print()
verse_chunks = 0
phrases_and_verses = 0
action = 2
continue
else:
manage_the_verse_continuation = False
if manage_the_verse_continuation:
sleep(0.250) # 250 ms
if maybe_add_comma and not (verse_chunks == 0 or random.random() > 0.19):
print(",", end = "")
verse_chunks = 2
if random.random() > 0.65:
print()
verse_chunks = 0
else:
print(" ", end = "")
verse_chunks += 1
action += 1
phrase = random.randrange(0, 5)
phrases_and_verses += 1
if not (verse_chunks > 0 or not is_odd(action)):
print(" ", end = "")
clear_screen()
print_credits()
press_enter("\nPress the Enter key to start. ")
clear_screen()
play()
En Raku
# Poetry
# Original version in BASIC:
# Unknown author.
# Modified and reworked by Jim Bailey, Peggy Ewing, and Dave Ahl at DEC.
# Published in "BASIC Computer Games", Creative Computing (Morristown, New Jersey, USA), 1978.
# https://archive.org/details/Basic_Computer_Games_Microcomputer_Edition_1978_Creative_Computing
# https://github.com/chaosotter/basic-games/tree/master/games/BASIC%20Computer%20Games/Poetry
# http://vintage-basic.net/games.html
# This improved remake in Raku:
# Copyright (c) 2024, Marcos Cruz (programandala.net)
# SPDX-License-Identifier: Fair
#
# Written in 2024-12-12/13.
#
# Last modified: 20241213T1544+0100.
# Terminal {{{1
# ==============================================================
constant $BLACK = 0;
constant $RED = 1;
constant $GREEN = 2;
constant $YELLOW = 3;
constant $BLUE = 4;
constant $MAGENTA = 5;
constant $CYAN = 6;
constant $WHITE = 7;
constant $DEFAULT = 9;
constant $STYLE_OFF = +20;
constant $FOREGROUND = +30;
constant $BACKGROUND = +40;
constant $BRIGHT = +60;
constant $NORMAL = 0;
constant $RESET_ALL = $NORMAL;
# Move the cursor to the home position.
sub move_cursor_home {
print "\e[H";
}
# Erase the screen.
sub erase_screen {
print "\e[2J";
}
# Set the color.
sub set_color(Int $color) {
print "\e[{$color}m";
}
# Reset the attributes.
sub reset_attributes {
set_color($RESET_ALL);
}
# Erase the screen, reset the attributes and move the cursor to the home position.
sub clear_screen {
erase_screen;
reset_attributes;
move_cursor_home;
}
# Globals {{{1
# =============================================================
constant $DEFAULT_INK = $FOREGROUND + $WHITE;
constant $INPUT_INK = $FOREGROUND + $BRIGHT + $GREEN;
constant $TITLE_INK = $FOREGROUND + $BRIGHT + $RED;
# Title and credits {{{1
# =============================================================
sub print_title {
set_color($TITLE_INK);
put 'Poetry';
set_color($DEFAULT_INK);
}
sub print_credits {
print_title;
put "\nOriginal version in BASIC:";
put ' Unknown author.';
put " Published in \"BASIC Computer Games\",";
put " Creative Computing (Morristown, New Jersey, USA), 1978.\n";
put 'This improved remake in Raku:';
put ' Copyright (c) 2024, Marcos Cruz (programandala.net)';
put ' SPDX-License-Identifier: Fair';
}
sub press_enter {
set_color($INPUT_INK);
prompt "\nPress the Enter key to start. ";
set_color($DEFAULT_INK);
}
# Main {{{1
# =============================================================
# Is the given integer even?
#
sub is_even(Int $n --> Bool ) {
return $n % 2 == 0;
}
sub play {
constant $MAX_PHRASES_AND_VERSES = 20;
my $action = 0;
my $phrase = 0;
my $phrases_and_verses = 0;
my $verse_chunks = 0;
VERSE: loop {
my $manage_the_verse_continuation = True;
my $maybe_add_comma = True;
given $action {
when 0 .. 1 {
given $phrase {
when 0 { print 'MIDNIGHT DREARY' }
when 1 { print 'FIERY EYES' }
when 2 { print 'BIRD OR FIEND' }
when 3 { print 'THING OF EVIL' }
when 4 { print 'PROPHET' }
}
}
when 2 {
given $phrase {
when 0 { print 'BEGUILING ME'; $verse_chunks = 2 }
when 1 { print 'THRILLED ME' }
when 2 { print 'STILL SITTING…'; $maybe_add_comma = False }
when 3 { print 'NEVER FLITTING'; $verse_chunks = 2 }
when 4 { print 'BURNED' }
}
}
when 3 {
given $phrase {
when 0 { print 'AND MY SOUL' }
when 1 { print 'DARKNESS THERE' }
when 2 { print 'SHALL BE LIFTED' }
when 3 { print 'QUOTH THE RAVEN' }
when 4 { if $verse_chunks != 0 { print 'SIGN OF PARTING' } }
}
}
when 4 {
given $phrase {
when 0 { print 'NOTHING MORE' }
when 1 { print 'YET AGAIN' }
when 2 { print 'SLOWLY CREEPING' }
when 3 { print '…EVERMORE' }
when 4 { print 'NEVERMORE' }
}
}
when 5 {
$action = 0;
put '';
if $phrases_and_verses > $MAX_PHRASES_AND_VERSES {
put '';
$verse_chunks = 0;
$phrases_and_verses = 0;
$action = 2;
next VERSE;
} else {
$manage_the_verse_continuation = False;
}
}
}
if $manage_the_verse_continuation {
sleep 0.250; # 250 ms
if $maybe_add_comma and not ($verse_chunks == 0 or rand > 0.19) {
print ',';
$verse_chunks = 2;
}
if rand > 0.65 {
put '';
$verse_chunks = 0;
} else {
print ' ';
$verse_chunks += 1;
}
}
$action += 1;
$phrase = (0 .. 4).pick;
$phrases_and_verses += 1;
if not ($verse_chunks > 0 or is_even($action)) {
print ' ';
}
} # verse loop
}
clear_screen;
print_credits;
press_enter;
clear_screen;
play;
En V
/*
Poetry
Original version in BASIC:
Unknown author.
Modified and reworked by Jim Bailey, Peggy Ewing, and Dave Ahl at DEC.
Published in "BASIC Computer Games", Creative Computing (Morristown, New Jersey, USA), 1978.
https://archive.org/details/Basic_Computer_Games_Microcomputer_Edition_1978_Creative_Computing
https://github.com/chaosotter/basic-games/tree/master/games/BASIC%20Computer%20Games/Poetry
http://vintage-basic.net/games.html
This improved remake in V:
Copyright (c) 2025, Marcos Cruz (programandala.net)
SPDX-License-Identifier: Fair
Written on 2025-01-04.
Last modified: 20250104T0103+0100.
*/
import os
import rand
import term
import time
// Globals {{{1
// =============================================================
const max_phrases_and_verses = 20
const input_ink = term.bright_green
const title_ink = term.bright_red
// User input {{{1
// =============================================================
// Print the given prompt and wait until the user enters a string.
//
fn input_string(prompt string) string {
return os.input(term.colorize(input_ink, prompt))
}
// Print the given prompt and wait until the user presses Enter.
//
fn press_enter(prompt string) {
input_string(prompt)
}
// Title and credits {{{1
// =============================================================
// Print the credits at the current cursor position.
//
fn print_credits() {
println(term.colorize(title_ink, 'Poetry'))
println('\nOriginal version in BASIC:')
println(' Unknown author.')
println(' Published in "BASIC Computer Games",')
println(' Creative Computing (Morristown, New Jersey, USA), 1978.\n')
println('This improved remake in V:')
println(' Copyright (c) 2025, Marcos Cruz (programandala.net)')
println(' SPDX-License-Identifier: Fair')
}
// Main {{{1
// =============================================================
// Is the given integer even?
//
fn is_even(n int) bool {
return n % 2 == 0
}
fn play() {
// counters:
mut action := 0
mut phrase := 0
mut phrases_and_verses := 0
mut verse_chunks := 0
verse: for {
mut manage_the_verse_continuation := true
mut maybe_add_comma := true
match action {
0, 1 {
match phrase {
0 { print('MIDNIGHT DREARY') }
1 { print('FIERY EYES') }
2 { print('BIRD OR FIEND') }
3 { print('THING OF EVIL') }
4 { print('PROPHET') }
else {}
}
}
2 {
match phrase {
0 {
print('BEGUILING ME')
verse_chunks = 2
}
1 {
print('THRILLED ME')
}
2 {
print('STILL SITTING…')
maybe_add_comma = false
}
3 {
print('NEVER FLITTING')
verse_chunks = 2
}
4 {
print('BURNED')
}
else {}
}
}
3 {
match phrase {
0 {
print('AND MY SOUL')
}
1 {
print('DARKNESS THERE')
}
2 {
print('SHALL BE LIFTED')
}
3 {
print('QUOTH THE RAVEN')
}
4 {
if verse_chunks != 0 {
print('SIGN OF PARTING')
}
}
else {}
}
}
4 {
match phrase {
0 { print('NOTHING MORE') }
1 { print('YET AGAIN') }
2 { print('SLOWLY CREEPING') }
3 { print('…EVERMORE') }
4 { print('NEVERMORE') }
else {}
}
}
5 {
action = 0
println('')
if phrases_and_verses > max_phrases_and_verses {
println('')
verse_chunks = 0
phrases_and_verses = 0
action = 2
continue verse
} else {
manage_the_verse_continuation = false
}
}
else {}
}
if manage_the_verse_continuation {
time.sleep(250_000_000) // 250 ms
if maybe_add_comma && !(verse_chunks == 0 || rand.f64() > 0.19) {
print(',')
verse_chunks = 2
}
if rand.f64() > 0.65 {
println('')
verse_chunks = 0
} else {
print(' ')
verse_chunks += 1
}
}
action += 1
phrase = rand.intn(5) or { 0 }
phrases_and_verses += 1
if !(verse_chunks > 0 || is_even(action)) {
print(' ')
}
} // verse loop
}
fn main() {
term.clear()
print_credits()
press_enter('\nPress the Enter key to start. ')
term.clear()
play()
}
