Samples
Six programs written as free-form pseudocode, exactly as shipped with the project templates, and what they become. The C# is generated by a local language model; open the details to read it.
Tetris
Tetris with coloured pieces, next-piece preview, score and sound. Arrows move (hold to repeat), Up rotates, R restarts.
What you write
window 400 by 450
title "Tetris"
background black
tick every 400 milliseconds
board = new list
pieceCells = new list
tempCells = new list
nextCells = new list
score = 0
gameOver = false
currentShape = random number between 0 and 6
nextShape = random number between 0 and 6
currentRotation = 0
pieceX = 4
pieceY = 0
set pieceCells to the cells of shape currentShape at rotation currentRotation positioned at (pieceX, pieceY)
set nextCells to the cells of shape nextShape at rotation 0 positioned at (0, 0)
define move piece left returning bool {
newX = pieceX - 1
set tempCells to the cells of shape currentShape at rotation currentRotation positioned at (newX, pieceY)
ok = true
for each cell in tempCells {
if cell.x < 0 {
ok = false
}
if cell.x >= 10 {
ok = false
}
if cell.y >= 20 {
ok = false
}
if point (cell.x, cell.y) is in board {
ok = false
}
…
Show the full pseudocode (283 lines)
window 400 by 450
title "Tetris"
background black
tick every 400 milliseconds
board = new list
pieceCells = new list
tempCells = new list
nextCells = new list
score = 0
gameOver = false
currentShape = random number between 0 and 6
nextShape = random number between 0 and 6
currentRotation = 0
pieceX = 4
pieceY = 0
set pieceCells to the cells of shape currentShape at rotation currentRotation positioned at (pieceX, pieceY)
set nextCells to the cells of shape nextShape at rotation 0 positioned at (0, 0)
define move piece left returning bool {
newX = pieceX - 1
set tempCells to the cells of shape currentShape at rotation currentRotation positioned at (newX, pieceY)
ok = true
for each cell in tempCells {
if cell.x < 0 {
ok = false
}
if cell.x >= 10 {
ok = false
}
if cell.y >= 20 {
ok = false
}
if point (cell.x, cell.y) is in board {
ok = false
}
}
if ok {
pieceX = newX
set pieceCells to the cells of shape currentShape at rotation currentRotation positioned at (pieceX, pieceY)
}
return ok
}
define move piece right returning bool {
newX = pieceX + 1
set tempCells to the cells of shape currentShape at rotation currentRotation positioned at (newX, pieceY)
ok = true
for each cell in tempCells {
if cell.x < 0 {
ok = false
}
if cell.x >= 10 {
ok = false
}
if cell.y >= 20 {
ok = false
}
if point (cell.x, cell.y) is in board {
ok = false
}
}
if ok {
pieceX = newX
set pieceCells to the cells of shape currentShape at rotation currentRotation positioned at (pieceX, pieceY)
}
return ok
}
define move piece down returning bool {
newY = pieceY + 1
set tempCells to the cells of shape currentShape at rotation currentRotation positioned at (pieceX, newY)
ok = true
for each cell in tempCells {
if cell.x < 0 {
ok = false
}
if cell.x >= 10 {
ok = false
}
if cell.y >= 20 {
ok = false
}
if point (cell.x, cell.y) is in board {
ok = false
}
}
if ok {
pieceY = newY
set pieceCells to the cells of shape currentShape at rotation currentRotation positioned at (pieceX, pieceY)
}
return ok
}
define rotate piece returning bool {
newRotation = currentRotation + 1
set tempCells to the cells of shape currentShape at rotation newRotation positioned at (pieceX, pieceY)
ok = true
for each cell in tempCells {
if cell.x < 0 {
ok = false
}
if cell.x >= 10 {
ok = false
}
if cell.y >= 20 {
ok = false
}
if point (cell.x, cell.y) is in board {
ok = false
}
}
if ok {
currentRotation = newRotation
set pieceCells to the cells of shape currentShape at rotation currentRotation positioned at (pieceX, pieceY)
}
return ok
}
define lock piece {
for each cell in pieceCells {
add point (cell.x, cell.y) to board
}
}
define clear lines {
loop row from 0 to 19 {
countInRow = 0
for each cell in board {
if cell.y = row {
countInRow = countInRow + 1
}
}
if countInRow >= 10 {
newBoard = new list
for each cell in board {
if cell.y <> row {
if cell.y < row {
add point (cell.x, cell.y + 1) to newBoard
}
if cell.y > row {
add point (cell.x, cell.y) to newBoard
}
}
}
board = newBoard
score = score + 100
play a tone at 800 Hz for 100 ms
}
}
}
define spawn piece returning bool {
currentShape = nextShape
nextShape = random number between 0 and 6
currentRotation = 0
pieceX = 4
pieceY = 0
set pieceCells to the cells of shape currentShape at rotation currentRotation positioned at (pieceX, pieceY)
set nextCells to the cells of shape nextShape at rotation 0 positioned at (0, 0)
blocked = false
for each cell in pieceCells {
if point (cell.x, cell.y) is in board {
blocked = true
}
}
return blocked
}
define show game over {
clear
display text "Game Over" at (60, 180) color red size 28
display text "Score :" at (90, 230) color white size 18
display text score at (170, 230) color white size 18
display text "Press R to restart" at (60, 270) color gray size 14
play a tone at 150 Hz for 500 ms
}
define restart game {
board = new list
score = 0
gameOver = false
currentShape = random number between 0 and 6
nextShape = random number between 0 and 6
currentRotation = 0
pieceX = 4
pieceY = 0
set pieceCells to the cells of shape currentShape at rotation currentRotation positioned at (pieceX, pieceY)
set nextCells to the cells of shape nextShape at rotation 0 positioned at (0, 0)
play a tone at 440 Hz for 100 ms
play a tone at 660 Hz for 150 ms
}
define draw game {
clear
draw rectangle at (0, 0) size (200, 400) color gray
for each cell in board {
draw filled rectangle at (cell.x * 20, cell.y * 20) size (18, 18) color steelblue
}
if currentShape = 0 {
for each cell in pieceCells {
draw filled rectangle at (cell.x * 20, cell.y * 20) size (18, 18) color cyan
}
}
if currentShape = 1 {
for each cell in pieceCells {
draw filled rectangle at (cell.x * 20, cell.y * 20) size (18, 18) color yellow
}
}
if currentShape = 2 {
for each cell in pieceCells {
draw filled rectangle at (cell.x * 20, cell.y * 20) size (18, 18) color purple
}
}
if currentShape = 3 {
for each cell in pieceCells {
draw filled rectangle at (cell.x * 20, cell.y * 20) size (18, 18) color green
}
}
if currentShape = 4 {
for each cell in pieceCells {
draw filled rectangle at (cell.x * 20, cell.y * 20) size (18, 18) color red
}
}
if currentShape = 5 {
for each cell in pieceCells {
draw filled rectangle at (cell.x * 20, cell.y * 20) size (18, 18) color blue
}
}
if currentShape = 6 {
for each cell in pieceCells {
draw filled rectangle at (cell.x * 20, cell.y * 20) size (18, 18) color orange
}
}
display text "Score" at (230, 20) color white size 16
display text score at (230, 45) color yellow size 14
display text "Next" at (230, 90) color white size 16
for each cell in nextCells {
draw filled rectangle at (230 + cell.x * 16, 120 + cell.y * 16) size (14, 14) color yellow
}
}
on tick {
if key R tapped {
restart game
}
if not gameOver {
if key left pressed {
move piece left
}
if key right pressed {
move piece right
}
if key up tapped {
rotate piece
}
if key down pressed {
move piece down
}
fell = move piece down
if not fell {
lock piece
clear lines
blocked = spawn piece
if blocked {
gameOver = true
}
if gameOver {
show game over
}
}
if not gameOver {
draw game
}
}
}What you get

Arrows move and rotate the pieces, hold a key to repeat.
Show the generated C# (562 lines)
// pseudo-source-hash: ddf37f2e7cd11b25602c4fe7b86541af3e8e0e0b129dbb5e3add218ff9abc5e4
// Generated by Pseudo.NET — Pseudraw.NET backend
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
class Program : Form
{
// ── Runtime Pseudraw ───────────────────────────
private Bitmap _canvas;
private Graphics _g;
private Timer _timer;
private readonly HashSet<Keys> _keysHeld = new();
private readonly HashSet<Keys> _keysTapped = new();
private Color _background = Color.Black;
private string _fontName = "Consolas";
// ── Variables utilisateur ──────────────────────
private List<object> board;
private List<object> pieceCells;
private List<object> tempCells;
private List<object> nextCells;
private int score;
private bool gameOver;
private int currentShape;
private int nextShape;
private int currentRotation;
private int pieceX;
private int pieceY;
public Program()
{
Text = "Tetris";
ClientSize = new Size(400, 450);
FormBorderStyle = FormBorderStyle.FixedSingle;
MaximizeBox = false;
DoubleBuffered = true;
SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint, true);
StartPosition = FormStartPosition.CenterScreen;
_canvas = new Bitmap(400, 450);
_g = Graphics.FromImage(_canvas);
_g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
_background = Color.FromName("black");
_fontName = "Consolas";
_g.Clear(_background);
Paint += (s, e) => e.Graphics.DrawImage(_canvas, 0, 0);
KeyDown += OnKeyDown;
KeyUp += OnKeyUp;
KeyPreview = true;
// ── Setup utilisateur ────────────────────
board = new List<object>();
pieceCells = new List<object>();
tempCells = new List<object>();
nextCells = new List<object>();
score = 0;
gameOver = false;
currentShape = Random.Shared.Next(0, 6 + 1);
nextShape = Random.Shared.Next(0, 6 + 1);
currentRotation = 0;
pieceX = 4;
pieceY = 0;
pieceCells.Clear();
pieceCells.AddRange(TetrominoCells((int)(currentShape), (int)(currentRotation), (int)(4), (int)(0)));
nextCells.Clear();
nextCells.AddRange(TetrominoCells((int)(nextShape), (int)(0), (int)(0), (int)(0)));
_timer = new Timer();
_timer.Interval = 400;
_timer.Tick += (s, e) => OnTick();
_timer.Start();
}
private void OnTick()
{
bool fell = default;
bool blocked = default;
if (_keysTapped.Contains(Keys.R))
{
RestartGame();
}
if (!(gameOver))
{
if ((_keysHeld.Contains(Keys.Left) || _keysTapped.Contains(Keys.Left)))
{
MovePieceLeft();
}
if ((_keysHeld.Contains(Keys.Right) || _keysTapped.Contains(Keys.Right)))
{
MovePieceRight();
}
if (_keysTapped.Contains(Keys.Up))
{
RotatePiece();
}
if ((_keysHeld.Contains(Keys.Down) || _keysTapped.Contains(Keys.Down)))
{
MovePieceDown();
}
fell = MovePieceDown();
if (!(fell))
{
LockPiece();
ClearLines();
blocked = SpawnPiece();
if (blocked)
{
gameOver = true;
}
if (gameOver)
{
ShowGameOver();
}
}
if (!(gameOver))
{
DrawGame();
}
}
_keysTapped.Clear();
Invalidate();
}
private void OnKeyDown(object s, KeyEventArgs e)
{
if (!_keysHeld.Contains(e.KeyCode))
_keysTapped.Add(e.KeyCode);
_keysHeld.Add(e.KeyCode);
}
private void OnKeyUp(object s, KeyEventArgs e)
{
_keysHeld.Remove(e.KeyCode);
}
private static PointF PseudrawRandomPoint(int x1, int y1, int x2, int y2)
{
var rng = Random.Shared;
return new PointF(rng.Next(x1, x2 + 1), rng.Next(y1, y2 + 1));
}
private static double PseudrawDistance(PointF a, PointF b) =>
Math.Sqrt(Math.Pow(b.X - a.X, 2) + Math.Pow(b.Y - a.Y, 2));
// ── Son : file d'attente + thread dédié pour jouer les notes dans l'ordre
// sans bloquer l'UI (Console.Beep est synchrone sur l'appelant). ────────
private static readonly System.Collections.Concurrent.ConcurrentQueue<(int freq, int dur)> _audioQueue = new();
private static readonly object _audioLock = new object();
private static bool _audioThreadStarted = false;
private static void EnsureAudioThread()
{
lock (_audioLock)
{
if (_audioThreadStarted) return;
_audioThreadStarted = true;
var audioThread = new System.Threading.Thread(() =>
{
while (true)
{
if (_audioQueue.TryDequeue(out var note))
{
try { Console.Beep(note.freq, note.dur); } catch { }
}
else
{
System.Threading.Thread.Sleep(10);
}
}
});
audioThread.IsBackground = true;
audioThread.Start();
}
}
private static void PlayTone(int frequency, int durationMs)
{
EnsureAudioThread();
int f = Math.Clamp(frequency, 37, 32767);
int d = Math.Max(1, durationMs);
_audioQueue.Enqueue((f, d));
}
// ── Géométrie des 7 tétrominos (0=I,1=O,2=T,3=S,4=Z,5=J,6=L), 4 rotations —
// donnée fixe fournie par le compilateur, jamais laissée à la charge du
// pseudocode. ─────────────────────────────────────────────────────────
private static List<object> TetrominoCells(int shape, int rotation, int x, int y)
{
int r = ((rotation % 4) + 4) % 4;
(int dx, int dy)[] offsets;
switch (shape)
{
case 0:
offsets = (r == 1 || r == 3)
? new (int, int)[] { (2,0), (2,1), (2,2), (2,3) }
: new (int, int)[] { (0,1), (1,1), (2,1), (3,1) };
break;
case 1:
offsets = new (int, int)[] { (1,0), (2,0), (1,1), (2,1) };
break;
case 2:
switch (r)
{
case 1: offsets = new (int, int)[] { (1,0), (1,1), (2,1), (1,2) }; break;
case 2: offsets = new (int, int)[] { (0,1), (1,1), (2,1), (1,2) }; break;
case 3: offsets = new (int, int)[] { (1,0), (0,1), (1,1), (1,2) }; break;
default: offsets = new (int, int)[] { (1,0), (0,1), (1,1), (2,1) }; break;
}
break;
case 3:
offsets = (r == 1 || r == 3)
? new (int, int)[] { (1,0), (1,1), (2,1), (2,2) }
: new (int, int)[] { (1,0), (2,0), (0,1), (1,1) };
break;
case 4:
offsets = (r == 1 || r == 3)
? new (int, int)[] { (2,0), (1,1), (2,1), (1,2) }
: new (int, int)[] { (0,0), (1,0), (1,1), (2,1) };
break;
case 5:
switch (r)
{
case 1: offsets = new (int, int)[] { (1,0), (2,0), (1,1), (1,2) }; break;
case 2: offsets = new (int, int)[] { (0,1), (1,1), (2,1), (2,2) }; break;
case 3: offsets = new (int, int)[] { (1,0), (1,1), (0,2), (1,2) }; break;
default: offsets = new (int, int)[] { (0,0), (0,1), (1,1), (2,1) }; break;
}
break;
default:
switch (r)
{
case 1: offsets = new (int, int)[] { (1,0), (1,1), (1,2), (2,2) }; break;
case 2: offsets = new (int, int)[] { (0,1), (1,1), (2,1), (0,2) }; break;
case 3: offsets = new (int, int)[] { (0,0), (1,0), (1,1), (1,2) }; break;
default: offsets = new (int, int)[] { (2,0), (0,1), (1,1), (2,1) }; break;
}
break;
}
var result = new List<object>();
foreach (var (dx, dy) in offsets)
result.Add(new PointF(x + dx, y + dy));
return result;
}
private bool MovePieceLeft()
{
int newX = default;
bool ok = default;
newX = (pieceX - 1);
tempCells.Clear();
tempCells.AddRange(TetrominoCells((int)(currentShape), (int)(currentRotation), (int)(newX), (int)(pieceY)));
ok = true;
foreach (var cell in tempCells)
{
if ((((PointF)cell).X < 0))
{
ok = false;
}
if ((((PointF)cell).X >= 10))
{
ok = false;
}
if ((((PointF)cell).Y >= 20))
{
ok = false;
}
if (((board) as System.Collections.IList)?.Contains(new PointF((float)(((PointF)cell).X), (float)(((PointF)cell).Y))) == true)
{
ok = false;
}
}
if (ok)
{
pieceX = newX;
pieceCells.Clear();
pieceCells.AddRange(TetrominoCells((int)(currentShape), (int)(currentRotation), (int)(pieceX), (int)(pieceY)));
}
return ok;
}
private bool MovePieceRight()
{
int newX = default;
bool ok = default;
newX = (pieceX + 1);
tempCells.Clear();
tempCells.AddRange(TetrominoCells((int)(currentShape), (int)(currentRotation), (int)(newX), (int)(pieceY)));
ok = true;
foreach (var cell in tempCells)
{
if ((((PointF)cell).X < 0))
{
ok = false;
}
if ((((PointF)cell).X >= 10))
{
ok = false;
}
if ((((PointF)cell).Y >= 20))
{
ok = false;
}
if (((board) as System.Collections.IList)?.Contains(new PointF((float)(((PointF)cell).X), (float)(((PointF)cell).Y))) == true)
{
ok = false;
}
}
if (ok)
{
pieceX = newX;
pieceCells.Clear();
pieceCells.AddRange(TetrominoCells((int)(currentShape), (int)(currentRotation), (int)(pieceX), (int)(pieceY)));
}
return ok;
}
private bool MovePieceDown()
{
int newY = default;
bool ok = default;
newY = (pieceY + 1);
tempCells.Clear();
tempCells.AddRange(TetrominoCells((int)(currentShape), (int)(currentRotation), (int)(pieceX), (int)(newY)));
ok = true;
foreach (var cell in tempCells)
{
if ((((PointF)cell).X < 0))
{
ok = false;
}
if ((((PointF)cell).X >= 10))
{
ok = false;
}
if ((((PointF)cell).Y >= 20))
{
ok = false;
}
if (((board) as System.Collections.IList)?.Contains(new PointF((float)(((PointF)cell).X), (float)(((PointF)cell).Y))) == true)
{
ok = false;
}
}
if (ok)
{
pieceY = newY;
pieceCells.Clear();
pieceCells.AddRange(TetrominoCells((int)(currentShape), (int)(currentRotation), (int)(pieceX), (int)(pieceY)));
}
return ok;
}
private bool RotatePiece()
{
int newRotation = default;
bool ok = default;
newRotation = (currentRotation + 1);
tempCells.Clear();
tempCells.AddRange(TetrominoCells((int)(currentShape), (int)(newRotation), (int)(pieceX), (int)(pieceY)));
ok = true;
foreach (var cell in tempCells)
{
if ((((PointF)cell).X < 0))
{
ok = false;
}
if ((((PointF)cell).X >= 10))
{
ok = false;
}
if ((((PointF)cell).Y >= 20))
{
ok = false;
}
if (((board) as System.Collections.IList)?.Contains(new PointF((float)(((PointF)cell).X), (float)(((PointF)cell).Y))) == true)
{
ok = false;
}
}
if (ok)
{
currentRotation = newRotation;
pieceCells.Clear();
pieceCells.AddRange(TetrominoCells((int)(currentShape), (int)(currentRotation), (int)(pieceX), (int)(pieceY)));
}
return ok;
}
private void LockPiece()
{
foreach (var cell in pieceCells)
{
board.Add(new PointF((float)(((PointF)cell).X), (float)(((PointF)cell).Y)));
}
}
private void ClearLines()
{
int countInRow = default;
List<object> newBoard = default;
for (var row = 0; row <= 19; row++)
{
countInRow = 0;
foreach (var cell in board)
{
if ((((PointF)cell).Y == row))
{
countInRow = (countInRow + 1);
}
}
if ((countInRow >= 10))
{
newBoard = new List<object>();
foreach (var cell in board)
{
if ((((PointF)cell).Y != row))
{
if ((((PointF)cell).Y < row))
{
newBoard.Add(new PointF((float)(((PointF)cell).X), (float)((((PointF)cell).Y + 1))));
}
if ((((PointF)cell).Y > row))
{
newBoard.Add(new PointF((float)(((PointF)cell).X), (float)(((PointF)cell).Y)));
}
}
}
board = newBoard;
score = (score + 100);
PlayTone((int)(800), (int)(100));
}
}
}
private bool SpawnPiece()
{
bool blocked = default;
currentShape = nextShape;
nextShape = Random.Shared.Next(0, 6 + 1);
currentRotation = 0;
pieceX = 4;
pieceY = 0;
pieceCells.Clear();
pieceCells.AddRange(TetrominoCells((int)(currentShape), (int)(currentRotation), (int)(pieceX), (int)(pieceY)));
nextCells.Clear();
nextCells.AddRange(TetrominoCells((int)(nextShape), (int)(0), (int)(0), (int)(0)));
blocked = false;
foreach (var cell in pieceCells)
{
if (((board) as System.Collections.IList)?.Contains(new PointF((float)(((PointF)cell).X), (float)(((PointF)cell).Y))) == true)
{
blocked = true;
}
}
return blocked;
}
private void ShowGameOver()
{
_g.Clear(_background);
_g.DrawString(Convert.ToString("Game Over"), new Font(_fontName, (float)(28), FontStyle.Regular, GraphicsUnit.Pixel), new SolidBrush(Color.FromName("red")), (float)(60), (float)(180));
_g.DrawString(Convert.ToString("Score :"), new Font(_fontName, (float)(18), FontStyle.Regular, GraphicsUnit.Pixel), new SolidBrush(Color.FromName("white")), (float)(90), (float)(230));
_g.DrawString(Convert.ToString(score), new Font(_fontName, (float)(18), FontStyle.Regular, GraphicsUnit.Pixel), new SolidBrush(Color.FromName("white")), (float)(170), (float)(230));
_g.DrawString(Convert.ToString("Press R to restart"), new Font(_fontName, (float)(14), FontStyle.Regular, GraphicsUnit.Pixel), new SolidBrush(Color.FromName("gray")), (float)(60), (float)(270));
PlayTone((int)(150), (int)(500));
}
private void RestartGame()
{
board = new List<object>();
score = 0;
gameOver = false;
currentShape = Random.Shared.Next(0, 6 + 1);
nextShape = Random.Shared.Next(0, 6 + 1);
currentRotation = 0;
pieceX = 4;
pieceY = 0;
pieceCells.Clear();
pieceCells.AddRange(TetrominoCells((int)(currentShape), (int)(currentRotation), (int)(pieceX), (int)(pieceY)));
nextCells.Clear();
nextCells.AddRange(TetrominoCells((int)(nextShape), (int)(0), (int)(0), (int)(0)));
PlayTone((int)(440), (int)(100));
PlayTone((int)(660), (int)(150));
}
private void DrawGame()
{
_g.Clear(_background);
_g.FillRectangle(new SolidBrush(Color.FromName("gray")), (float)(0), (float)(0), (float)(200), (float)(400));
foreach (var cell in board)
{
_g.FillRectangle(new SolidBrush(Color.FromName("steelblue")), (float)((((PointF)cell).X * 20)), (float)((((PointF)cell).Y * 20)), (float)(18), (float)(18));
}
if ((currentShape == 0))
{
foreach (var cell in pieceCells)
{
_g.FillRectangle(new SolidBrush(Color.FromName("cyan")), (float)((((PointF)cell).X * 20)), (float)((((PointF)cell).Y * 20)), (float)(18), (float)(18));
}
}
if ((currentShape == 1))
{
foreach (var cell in pieceCells)
{
_g.FillRectangle(new SolidBrush(Color.FromName("yellow")), (float)((((PointF)cell).X * 20)), (float)((((PointF)cell).Y * 20)), (float)(18), (float)(18));
}
}
if ((currentShape == 2))
{
foreach (var cell in pieceCells)
{
_g.FillRectangle(new SolidBrush(Color.FromName("purple")), (float)((((PointF)cell).X * 20)), (float)((((PointF)cell).Y * 20)), (float)(18), (float)(18));
}
}
if ((currentShape == 3))
{
foreach (var cell in pieceCells)
{
_g.FillRectangle(new SolidBrush(Color.FromName("green")), (float)((((PointF)cell).X * 20)), (float)((((PointF)cell).Y * 20)), (float)(18), (float)(18));
}
}
if ((currentShape == 4))
{
foreach (var cell in pieceCells)
{
_g.FillRectangle(new SolidBrush(Color.FromName("red")), (float)((((PointF)cell).X * 20)), (float)((((PointF)cell).Y * 20)), (float)(18), (float)(18));
}
}
if ((currentShape == 5))
{
foreach (var cell in pieceCells)
{
_g.FillRectangle(new SolidBrush(Color.FromName("blue")), (float)((((PointF)cell).X * 20)), (float)((((PointF)cell).Y * 20)), (float)(18), (float)(18));
}
}
if ((currentShape == 6))
{
foreach (var cell in pieceCells)
{
_g.FillRectangle(new SolidBrush(Color.FromName("orange")), (float)((((PointF)cell).X * 20)), (float)((((PointF)cell).Y * 20)), (float)(18), (float)(18));
}
}
_g.DrawString(Convert.ToString("Score"), new Font(_fontName, (float)(16), FontStyle.Regular, GraphicsUnit.Pixel), new SolidBrush(Color.FromName("white")), (float)(230), (float)(20));
_g.DrawString(Convert.ToString(score), new Font(_fontName, (float)(14), FontStyle.Regular, GraphicsUnit.Pixel), new SolidBrush(Color.FromName("yellow")), (float)(230), (float)(45));
_g.DrawString(Convert.ToString("Next"), new Font(_fontName, (float)(16), FontStyle.Regular, GraphicsUnit.Pixel), new SolidBrush(Color.FromName("white")), (float)(230), (float)(90));
foreach (var cell in nextCells)
{
_g.FillRectangle(new SolidBrush(Color.FromName("yellow")), (float)((230 + (((PointF)cell).X * 16))), (float)((120 + (((PointF)cell).Y * 16))), (float)(14), (float)(14));
}
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Program());
}
}
Snake
Classic Snake: steer with the arrow keys, eat the apples, avoid the walls and your own tail. R restarts. Entirely free-form pseudocode.
What you write
window 400 by 400
title "Snake"
background black
tick every 150 milliseconds
snake = new list
add point (10, 10) to snake
add point (9, 10) to snake
add point (8, 10) to snake
headX = 10
headY = 10
direction = 0
score = 0
gameOver = false
appleX = random number between 0 and 19
appleY = random number between 0 and 19
define draw game {
clear
for each seg in snake {
draw filled rectangle at (seg.x * 20, seg.y * 20) size (18, 18) color green
}
draw filled rectangle at (appleX * 20, appleY * 20) size (18, 18) color red
display text "Score : " + score at (5, 5) color white size 14
}
define show game over {
clear
display text "Game Over" at (110, 160) color red size 32
display text "Score : " + score at (135, 210) color white size 18
display text "Press R to restart" at (95, 250) color gray size 14
}
define restart game {
snake = new list
…
Show the full pseudocode (131 lines)
window 400 by 400
title "Snake"
background black
tick every 150 milliseconds
snake = new list
add point (10, 10) to snake
add point (9, 10) to snake
add point (8, 10) to snake
headX = 10
headY = 10
direction = 0
score = 0
gameOver = false
appleX = random number between 0 and 19
appleY = random number between 0 and 19
define draw game {
clear
for each seg in snake {
draw filled rectangle at (seg.x * 20, seg.y * 20) size (18, 18) color green
}
draw filled rectangle at (appleX * 20, appleY * 20) size (18, 18) color red
display text "Score : " + score at (5, 5) color white size 14
}
define show game over {
clear
display text "Game Over" at (110, 160) color red size 32
display text "Score : " + score at (135, 210) color white size 18
display text "Press R to restart" at (95, 250) color gray size 14
}
define restart game {
snake = new list
add point (10, 10) to snake
add point (9, 10) to snake
add point (8, 10) to snake
headX = 10
headY = 10
direction = 0
score = 0
gameOver = false
appleX = random number between 0 and 19
appleY = random number between 0 and 19
}
on tick {
if key R tapped {
restart game
}
if not gameOver {
if key up pressed and direction <> 1 then direction = 3
if key down pressed and direction <> 3 then direction = 1
if key left pressed and direction <> 0 then direction = 2
if key right pressed and direction <> 2 then direction = 0
moveX = 0
moveY = 0
if direction = 0 {
moveX = 1
}
if direction = 1 {
moveY = 1
}
if direction = 2 {
moveX = -1
}
if direction = 3 {
moveY = -1
}
nx = headX + moveX
ny = headY + moveY
died = false
hitWall = false
if nx < 0 {
hitWall = true
}
if nx >= 20 {
hitWall = true
}
if ny < 0 {
hitWall = true
}
if ny >= 20 {
hitWall = true
}
if hitWall {
died = true
}
selfHit = false
if point (nx, ny) is in snake {
selfHit = true
}
if selfHit {
died = true
}
if died {
gameOver = true
show game over
}
if not died {
onApple = false
if nx = appleX {
if ny = appleY {
onApple = true
}
}
if onApple {
score = score + 1
appleX = random number between 0 and 19
appleY = random number between 0 and 19
}
if not onApple {
remove the first element from snake
}
add point (nx, ny) to snake
headX = nx
headY = ny
draw game
}
}
}What you get

Captured while playing: arrow keys steer, R restarts.
Show the generated C# (350 lines)
// pseudo-source-hash: 6365ec17ec38785b54b9156e28fbee8d9e28f2ad965a8290759e40bd855d273f
// Generated by Pseudo.NET — Pseudraw.NET backend
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
class Program : Form
{
// ── Runtime Pseudraw ───────────────────────────
private Bitmap _canvas;
private Graphics _g;
private Timer _timer;
private readonly HashSet<Keys> _keysHeld = new();
private readonly HashSet<Keys> _keysTapped = new();
private Color _background = Color.Black;
private string _fontName = "Consolas";
// ── Variables utilisateur ──────────────────────
private List<object> snake;
private int headX;
private int headY;
private int direction;
private int score;
private bool gameOver;
private int appleX;
private int appleY;
public Program()
{
Text = "Snake";
ClientSize = new Size(400, 400);
FormBorderStyle = FormBorderStyle.FixedSingle;
MaximizeBox = false;
DoubleBuffered = true;
SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint, true);
StartPosition = FormStartPosition.CenterScreen;
_canvas = new Bitmap(400, 400);
_g = Graphics.FromImage(_canvas);
_g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
_background = Color.FromName("black");
_fontName = "Consolas";
_g.Clear(_background);
Paint += (s, e) => e.Graphics.DrawImage(_canvas, 0, 0);
KeyDown += OnKeyDown;
KeyUp += OnKeyUp;
KeyPreview = true;
// ── Setup utilisateur ────────────────────
snake = new List<object>();
snake.Add(new PointF((float)(10), (float)(10)));
snake.Add(new PointF((float)(9), (float)(10)));
snake.Add(new PointF((float)(8), (float)(10)));
headX = 10;
headY = 10;
direction = 0;
score = 0;
gameOver = false;
appleX = Random.Shared.Next(0, 19 + 1);
appleY = Random.Shared.Next(0, 19 + 1);
_timer = new Timer();
_timer.Interval = 150;
_timer.Tick += (s, e) => OnTick();
_timer.Start();
}
private void OnTick()
{
int moveX = default;
int moveY = default;
int nx = default;
int ny = default;
bool died = default;
bool hitWall = default;
bool selfHit = default;
bool onApple = default;
if (_keysTapped.Contains(Keys.R))
{
RestartGame();
}
if (!(gameOver))
{
if (((_keysHeld.Contains(Keys.Up) || _keysTapped.Contains(Keys.Up)) && (direction != 1)))
{
direction = 3;
}
if (((_keysHeld.Contains(Keys.Down) || _keysTapped.Contains(Keys.Down)) && (direction != 3)))
{
direction = 1;
}
if (((_keysHeld.Contains(Keys.Left) || _keysTapped.Contains(Keys.Left)) && (direction != 0)))
{
direction = 2;
}
if (((_keysHeld.Contains(Keys.Right) || _keysTapped.Contains(Keys.Right)) && (direction != 2)))
{
direction = 0;
}
moveX = 0;
moveY = 0;
if ((direction == 0))
{
moveX = 1;
}
if ((direction == 1))
{
moveY = 1;
}
if ((direction == 2))
{
moveX = -1;
}
if ((direction == 3))
{
moveY = -1;
}
nx = (headX + moveX);
ny = (headY + moveY);
died = false;
hitWall = false;
if ((nx < 0))
{
hitWall = true;
}
if ((nx >= 20))
{
hitWall = true;
}
if ((ny < 0))
{
hitWall = true;
}
if ((ny >= 20))
{
hitWall = true;
}
if (hitWall)
{
died = true;
}
selfHit = false;
if (((snake) as System.Collections.IList)?.Contains(new PointF((float)(nx), (float)(ny))) == true)
{
selfHit = true;
}
if (selfHit)
{
died = true;
}
if (died)
{
gameOver = true;
ShowGameOver();
}
if (!(died))
{
onApple = false;
if ((nx == appleX))
{
if ((ny == appleY))
{
onApple = true;
}
}
if (onApple)
{
score = (score + 1);
appleX = Random.Shared.Next(0, 19 + 1);
appleY = Random.Shared.Next(0, 19 + 1);
}
else
{
if (snake.Count > 0) snake.RemoveAt(0);
}
snake.Add(new PointF((float)(nx), (float)(ny)));
headX = nx;
headY = ny;
DrawGame();
}
}
_keysTapped.Clear();
Invalidate();
}
private void OnKeyDown(object s, KeyEventArgs e)
{
if (!_keysHeld.Contains(e.KeyCode))
_keysTapped.Add(e.KeyCode);
_keysHeld.Add(e.KeyCode);
}
private void OnKeyUp(object s, KeyEventArgs e)
{
_keysHeld.Remove(e.KeyCode);
}
private static PointF PseudrawRandomPoint(int x1, int y1, int x2, int y2)
{
var rng = Random.Shared;
return new PointF(rng.Next(x1, x2 + 1), rng.Next(y1, y2 + 1));
}
private static double PseudrawDistance(PointF a, PointF b) =>
Math.Sqrt(Math.Pow(b.X - a.X, 2) + Math.Pow(b.Y - a.Y, 2));
// ── Son : file d'attente + thread dédié pour jouer les notes dans l'ordre
// sans bloquer l'UI (Console.Beep est synchrone sur l'appelant). ────────
private static readonly System.Collections.Concurrent.ConcurrentQueue<(int freq, int dur)> _audioQueue = new();
private static readonly object _audioLock = new object();
private static bool _audioThreadStarted = false;
private static void EnsureAudioThread()
{
lock (_audioLock)
{
if (_audioThreadStarted) return;
_audioThreadStarted = true;
var audioThread = new System.Threading.Thread(() =>
{
while (true)
{
if (_audioQueue.TryDequeue(out var note))
{
try { Console.Beep(note.freq, note.dur); } catch { }
}
else
{
System.Threading.Thread.Sleep(10);
}
}
});
audioThread.IsBackground = true;
audioThread.Start();
}
}
private static void PlayTone(int frequency, int durationMs)
{
EnsureAudioThread();
int f = Math.Clamp(frequency, 37, 32767);
int d = Math.Max(1, durationMs);
_audioQueue.Enqueue((f, d));
}
// ── Géométrie des 7 tétrominos (0=I,1=O,2=T,3=S,4=Z,5=J,6=L), 4 rotations —
// donnée fixe fournie par le compilateur, jamais laissée à la charge du
// pseudocode. ─────────────────────────────────────────────────────────
private static List<object> TetrominoCells(int shape, int rotation, int x, int y)
{
int r = ((rotation % 4) + 4) % 4;
(int dx, int dy)[] offsets;
switch (shape)
{
case 0:
offsets = (r == 1 || r == 3)
? new (int, int)[] { (2,0), (2,1), (2,2), (2,3) }
: new (int, int)[] { (0,1), (1,1), (2,1), (3,1) };
break;
case 1:
offsets = new (int, int)[] { (1,0), (2,0), (1,1), (2,1) };
break;
case 2:
switch (r)
{
case 1: offsets = new (int, int)[] { (1,0), (1,1), (2,1), (1,2) }; break;
case 2: offsets = new (int, int)[] { (0,1), (1,1), (2,1), (1,2) }; break;
case 3: offsets = new (int, int)[] { (1,0), (0,1), (1,1), (1,2) }; break;
default: offsets = new (int, int)[] { (1,0), (0,1), (1,1), (2,1) }; break;
}
break;
case 3:
offsets = (r == 1 || r == 3)
? new (int, int)[] { (1,0), (1,1), (2,1), (2,2) }
: new (int, int)[] { (1,0), (2,0), (0,1), (1,1) };
break;
case 4:
offsets = (r == 1 || r == 3)
? new (int, int)[] { (2,0), (1,1), (2,1), (1,2) }
: new (int, int)[] { (0,0), (1,0), (1,1), (2,1) };
break;
case 5:
switch (r)
{
case 1: offsets = new (int, int)[] { (1,0), (2,0), (1,1), (1,2) }; break;
case 2: offsets = new (int, int)[] { (0,1), (1,1), (2,1), (2,2) }; break;
case 3: offsets = new (int, int)[] { (1,0), (1,1), (0,2), (1,2) }; break;
default: offsets = new (int, int)[] { (0,0), (0,1), (1,1), (2,1) }; break;
}
break;
default:
switch (r)
{
case 1: offsets = new (int, int)[] { (1,0), (1,1), (1,2), (2,2) }; break;
case 2: offsets = new (int, int)[] { (0,1), (1,1), (2,1), (0,2) }; break;
case 3: offsets = new (int, int)[] { (0,0), (1,0), (1,1), (1,2) }; break;
default: offsets = new (int, int)[] { (2,0), (0,1), (1,1), (2,1) }; break;
}
break;
}
var result = new List<object>();
foreach (var (dx, dy) in offsets)
result.Add(new PointF(x + dx, y + dy));
return result;
}
private void DrawGame()
{
_g.Clear(_background);
foreach (var seg in snake)
{
_g.FillRectangle(new SolidBrush(Color.FromName("green")), (float)((((PointF)seg).X * 20)), (float)((((PointF)seg).Y * 20)), (float)(18), (float)(18));
}
_g.FillRectangle(new SolidBrush(Color.FromName("red")), (float)((appleX * 20)), (float)((appleY * 20)), (float)(18), (float)(18));
_g.DrawString(Convert.ToString(("Score : " + score)), new Font(_fontName, (float)(14), FontStyle.Regular, GraphicsUnit.Pixel), new SolidBrush(Color.FromName("white")), (float)(5), (float)(5));
}
private void ShowGameOver()
{
_g.Clear(_background);
_g.DrawString(Convert.ToString("Game Over"), new Font(_fontName, (float)(32), FontStyle.Regular, GraphicsUnit.Pixel), new SolidBrush(Color.FromName("red")), (float)(110), (float)(160));
_g.DrawString(Convert.ToString(("Score : " + score)), new Font(_fontName, (float)(18), FontStyle.Regular, GraphicsUnit.Pixel), new SolidBrush(Color.FromName("white")), (float)(135), (float)(210));
_g.DrawString(Convert.ToString("Press R to restart"), new Font(_fontName, (float)(14), FontStyle.Regular, GraphicsUnit.Pixel), new SolidBrush(Color.FromName("gray")), (float)(95), (float)(250));
}
private void RestartGame()
{
snake = new List<object>();
snake.Add(new PointF((float)(10), (float)(10)));
snake.Add(new PointF((float)(9), (float)(10)));
snake.Add(new PointF((float)(8), (float)(10)));
headX = 10;
headY = 10;
direction = 0;
score = 0;
gameOver = false;
appleX = Random.Shared.Next(0, 19 + 1);
appleY = Random.Shared.Next(0, 19 + 1);
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Program());
}
}
Bouncing ball
A ball bouncing off the four walls of a window.
What you write
window 400 by 300
title "Bounce"
background black
ballX = 200
ballY = 150
speedX = 3
speedY = 2
ballRadius = 15
every 30 milliseconds {
ballX = ballX + speedX
ballY = ballY + speedY
if ballX - ballRadius < 0 or ballX + ballRadius > width then speedX = -speedX
if ballY - ballRadius < 0 or ballY + ballRadius > height then speedY = -speedY
clear
draw filled circle at (ballX, ballY) radius ballRadius color red
}
What you get
Show the generated C# (207 lines)
// pseudo-source-hash: 696640a5b34836dd8a3639d5b9aae980132ca33fc7dd2a292b1393ba854cb7d6
// Generated by Pseudo.NET — Pseudraw.NET backend
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
class Program : Form
{
// ── Runtime Pseudraw ───────────────────────────
private Bitmap _canvas;
private Graphics _g;
private Timer _timer;
private readonly HashSet<Keys> _keysHeld = new();
private readonly HashSet<Keys> _keysTapped = new();
private Color _background = Color.Black;
private string _fontName = "Consolas";
// ── Variables utilisateur ──────────────────────
private int ballX;
private int ballY;
private int speedX;
private int speedY;
private int ballRadius;
public Program()
{
Text = "Bounce";
ClientSize = new Size(400, 300);
FormBorderStyle = FormBorderStyle.FixedSingle;
MaximizeBox = false;
DoubleBuffered = true;
SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint, true);
StartPosition = FormStartPosition.CenterScreen;
_canvas = new Bitmap(400, 300);
_g = Graphics.FromImage(_canvas);
_g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
_background = Color.FromName("black");
_fontName = "Consolas";
_g.Clear(_background);
Paint += (s, e) => e.Graphics.DrawImage(_canvas, 0, 0);
KeyDown += OnKeyDown;
KeyUp += OnKeyUp;
KeyPreview = true;
// ── Setup utilisateur ────────────────────
ballX = 200;
ballY = 150;
speedX = 3;
speedY = 2;
ballRadius = 15;
_timer = new Timer();
_timer.Interval = 30;
_timer.Tick += (s, e) => OnTick();
_timer.Start();
}
private void OnTick()
{
ballX = (ballX + speedX);
ballY = (ballY + speedY);
if ((((ballX - ballRadius) < 0) || ((ballX + ballRadius) > ClientSize.Width)))
{
speedX = (speedX * -1);
}
if ((((ballY - ballRadius) < 0) || ((ballY + ballRadius) > ClientSize.Height)))
{
speedY = (speedY * -1);
}
_g.Clear(_background);
_g.FillEllipse(new SolidBrush(Color.FromName("red")), (float)((ballX) - (ballRadius)), (float)((ballY) - (ballRadius)), (float)((ballRadius) * 2), (float)((ballRadius) * 2));
_keysTapped.Clear();
Invalidate();
}
private void OnKeyDown(object s, KeyEventArgs e)
{
if (!_keysHeld.Contains(e.KeyCode))
_keysTapped.Add(e.KeyCode);
_keysHeld.Add(e.KeyCode);
}
private void OnKeyUp(object s, KeyEventArgs e)
{
_keysHeld.Remove(e.KeyCode);
}
private static PointF PseudrawRandomPoint(int x1, int y1, int x2, int y2)
{
var rng = Random.Shared;
return new PointF(rng.Next(x1, x2 + 1), rng.Next(y1, y2 + 1));
}
private static double PseudrawDistance(PointF a, PointF b) =>
Math.Sqrt(Math.Pow(b.X - a.X, 2) + Math.Pow(b.Y - a.Y, 2));
// ── Son : file d'attente + thread dédié pour jouer les notes dans l'ordre
// sans bloquer l'UI (Console.Beep est synchrone sur l'appelant). ────────
private static readonly System.Collections.Concurrent.ConcurrentQueue<(int freq, int dur)> _audioQueue = new();
private static readonly object _audioLock = new object();
private static bool _audioThreadStarted = false;
private static void EnsureAudioThread()
{
lock (_audioLock)
{
if (_audioThreadStarted) return;
_audioThreadStarted = true;
var audioThread = new System.Threading.Thread(() =>
{
while (true)
{
if (_audioQueue.TryDequeue(out var note))
{
try { Console.Beep(note.freq, note.dur); } catch { }
}
else
{
System.Threading.Thread.Sleep(10);
}
}
});
audioThread.IsBackground = true;
audioThread.Start();
}
}
private static void PlayTone(int frequency, int durationMs)
{
EnsureAudioThread();
int f = Math.Clamp(frequency, 37, 32767);
int d = Math.Max(1, durationMs);
_audioQueue.Enqueue((f, d));
}
// ── Géométrie des 7 tétrominos (0=I,1=O,2=T,3=S,4=Z,5=J,6=L), 4 rotations —
// donnée fixe fournie par le compilateur, jamais laissée à la charge du
// pseudocode. ─────────────────────────────────────────────────────────
private static List<object> TetrominoCells(int shape, int rotation, int x, int y)
{
int r = ((rotation % 4) + 4) % 4;
(int dx, int dy)[] offsets;
switch (shape)
{
case 0:
offsets = (r == 1 || r == 3)
? new (int, int)[] { (2,0), (2,1), (2,2), (2,3) }
: new (int, int)[] { (0,1), (1,1), (2,1), (3,1) };
break;
case 1:
offsets = new (int, int)[] { (1,0), (2,0), (1,1), (2,1) };
break;
case 2:
switch (r)
{
case 1: offsets = new (int, int)[] { (1,0), (1,1), (2,1), (1,2) }; break;
case 2: offsets = new (int, int)[] { (0,1), (1,1), (2,1), (1,2) }; break;
case 3: offsets = new (int, int)[] { (1,0), (0,1), (1,1), (1,2) }; break;
default: offsets = new (int, int)[] { (1,0), (0,1), (1,1), (2,1) }; break;
}
break;
case 3:
offsets = (r == 1 || r == 3)
? new (int, int)[] { (1,0), (1,1), (2,1), (2,2) }
: new (int, int)[] { (1,0), (2,0), (0,1), (1,1) };
break;
case 4:
offsets = (r == 1 || r == 3)
? new (int, int)[] { (2,0), (1,1), (2,1), (1,2) }
: new (int, int)[] { (0,0), (1,0), (1,1), (2,1) };
break;
case 5:
switch (r)
{
case 1: offsets = new (int, int)[] { (1,0), (2,0), (1,1), (1,2) }; break;
case 2: offsets = new (int, int)[] { (0,1), (1,1), (2,1), (2,2) }; break;
case 3: offsets = new (int, int)[] { (1,0), (1,1), (0,2), (1,2) }; break;
default: offsets = new (int, int)[] { (0,0), (0,1), (1,1), (2,1) }; break;
}
break;
default:
switch (r)
{
case 1: offsets = new (int, int)[] { (1,0), (1,1), (1,2), (2,2) }; break;
case 2: offsets = new (int, int)[] { (0,1), (1,1), (2,1), (0,2) }; break;
case 3: offsets = new (int, int)[] { (0,0), (1,0), (1,1), (1,2) }; break;
default: offsets = new (int, int)[] { (2,0), (0,1), (1,1), (2,1) }; break;
}
break;
}
var result = new List<object>();
foreach (var (dx, dy) in offsets)
result.Add(new PointF(x + dx, y + dy));
return result;
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Program());
}
}
Prime numbers
Finds the prime numbers up to 50 with a function, loops and a list. Indentation only: no braces, no end keywords.
What you write
We want to find all the prime numbers up to 50. primes = a new list define whether counter is prime, which returns a boolean isPrime = true if counter is less than 2 then isPrime = false repeat divisor from 2 to 50 if divisor is less than counter then remainder = counter modulo divisor if remainder is equal to 0 then isPrime = false return isPrime repeat counter from 2 to 50 candidate = whether counter is prime if candidate then add counter to primes print the text "Prime numbers up to 50:" for each number in primes print number
What you get
Prime numbers up to 50: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
Output of a real run.
Show the generated C# (49 lines)
// pseudo-source-hash: 560befffc5f8e8a2bd497435570b3a9dc731019cbd49e8561e81d6eef8761e16
// Generated by Pseudo.NET
using System;
using System.Collections.Generic;
class Program
{
private static List<object> primes;
private static int counter;
private static bool candidate;
static bool IsPrime(double counter)
{
var isPrime = true;
if ((counter < 2))
{
isPrime = false;
}
for (var divisor = 2; divisor <= 50; divisor++)
{
if ((divisor < counter))
{
var remainder = (counter % divisor);
if ((remainder == 0))
{
isPrime = false;
}
}
}
return isPrime;
}
static void Main(string[] args)
{
primes = new List<object>();
for (counter = 2; counter <= 50; counter++)
{
candidate = IsPrime(counter);
if (candidate)
{
primes.Add(counter);
}
}
Console.WriteLine("Prime numbers up to 50:");
foreach (var number in primes)
{
Console.WriteLine(number);
}
}
}
Bubble sort
Sorts a list of numbers with the bubble sort algorithm, printing the list before and after.
What you write
numbers = a new list add 5 to numbers add 2 to numbers add 9 to numbers add 1 to numbers add 7 to numbers add 3 to numbers print the text "Before sorting:" for each n in numbers print n repeat pass from 1 to 5 repeat i from 0 to 4 if numbers[i] is greater than numbers[i + 1] then temp = numbers[i] numbers[i] = numbers[i + 1] numbers[i + 1] = temp print the text "After sorting:" for each n in numbers print n
What you get
Before sorting: 5 2 9 1 7 3 After sorting: 1 2 3 5 7 9
Output of a real run.
Show the generated C# (45 lines)
// pseudo-source-hash: 2c49f0b779dd1b6390574944e43c15438160a262fc5e6ae00dd8070a1fd294b5
// Generated by Pseudo.NET
using System;
using System.Collections.Generic;
class Program
{
private static List<object> numbers;
private static int pass;
private static int i;
private static object temp;
static void Main(string[] args)
{
numbers = new List<object>();
numbers.Add(5);
numbers.Add(2);
numbers.Add(9);
numbers.Add(1);
numbers.Add(7);
numbers.Add(3);
Console.WriteLine("Before sorting:");
foreach (var n in numbers)
{
Console.WriteLine(n);
}
for (pass = 1; pass <= 5; pass++)
{
for (i = 0; i <= 4; i++)
{
if (((dynamic)numbers[i] > (dynamic)numbers[(i + 1)]))
{
temp = numbers[i];
numbers[i] = numbers[(i + 1)];
numbers[(i + 1)] = temp;
}
}
}
Console.WriteLine("After sorting:");
foreach (var n in numbers)
{
Console.WriteLine(n);
}
}
}
Guess the number
Guess the secret number between 1 and 100; the program tells you whether you are too low or too high.
What you write
secret = a random number between 1 and 100 print the text "I am thinking of a number between 1 and 100." guess = 0 while guess is different from secret read guess, asking "Your guess? " if guess is less than secret then print the text "Too low." if guess is greater than secret then print the text "Too high." print the text "You found it!"
What you get
I am thinking of a number between 1 and 100. Your guess? Too low. Your guess? Too low. Your guess? Too low. Your guess? Too low. Your guess? Too low. Your guess? Too low. Your guess? Too low. … Your guess? Too low. Your guess? You found it!
A real run, guesses 1, 2, 3… typed in order (the secret number is random each time).
Show the generated C# (31 lines)
// pseudo-source-hash: 137e8ad8e6ced7da1a2830a9c94915513f3d397be5889d1c9604a9be58568309
// Generated by Pseudo.NET
using System;
using System.Collections.Generic;
class Program
{
private static int secret;
private static int guess;
static void Main(string[] args)
{
secret = Random.Shared.Next(1, 100 + 1);
Console.WriteLine("I am thinking of a number between 1 and 100.");
guess = 0;
while ((guess != secret))
{
Console.Write("Your guess? ");
guess = int.Parse(Console.ReadLine());
if ((guess < secret))
{
Console.WriteLine("Too low.");
}
if ((guess > secret))
{
Console.WriteLine("Too high.");
}
}
Console.WriteLine("You found it!");
}
}
Try them
All six ship as project templates and run without the language model (their answer is included). From the command line:
dotnet new install PseudoNet.Templates dotnet new pseudo-tetris -n MyTetris cd MyTetris dotnet run
Template names: pseudo-tetris, pseudo-snake, pseudo-bounce, pseudo-primes, pseudo-bubble-sort, pseudo-guess-number. Or install the Visual Studio extension.