esolang

Rpg

A program is a small role-playing game, and its variables fight each other.

Jonas Everaert, 2022 · Turing complete: with unbounded memory · ●●○ moderate · esolangs.org

Tested with 10 known programs · Test method

Run it

Expected: 1

The idea

Jonas Everaert (Jomy10) wrote Rpg so that a program reads like a game. Variables are characters with health and attack. They buy potions and spellbooks from merchants, attack each other and cast spells. Health is the only number you can print. Subtraction is an attack, addition is a potion, and the only loop is the time_warp spell, which repeats its lines until the character offered to it has run out of health. A game holds at most ten living actors, so long programs kill characters off to make room for new ones.

The machine

StatementDoes
char a = (5,3)A character with health 5 and attack 3; zombie health may go below 0
potion p = (5) spellbook sb = () merchant m = ()Items and a seller
a buys p from mPut an item in a's inventory
a attacks bTake a's attack from b's health
a uses pDrink a potion: add its healing to the health
a shouts a whispersPrint the health, with or without a line feed
a uses sb casting spell()Cast a spell from a bought spellbook

The spells are god_speech() to read a number, speak() to print the health as a character, time_warp(c) ... end to loop, confuse(c) to show one less, create_potion(p) to set a potion to the caster's health, shift() to swap health and attack, and un_zombify(z).

Example

The second program is the adding.
Expected: 8

The second program is the adding. It reads 3 into r's health, makes the potion heal by 3, reads 5 and drinks the potion. The Hello world ends on a character with health 13, so it prints a carriage return before the line feed.

Further

Ideas it shows

Also in Jokes

Write your own in Run Convert a program from Rpg

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: rpg.

Command line

shib run rpg -e 'char a = (1,0)
a shouts
a shouts'
shib manual rpg

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/rpg.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org