Rpg

From Esolang
Jump to navigation Jump to search
Rpg
Designed by Jomy10
Appeared in 2022
Computational class Bounded-storage machine
Major implementations Original
File extension(s) .rpg

Rpg (also capitalised as RPG, or written as RPG-lang) is an esoteric programming language created by Jomy10 (Jonas Everaert). The language writes like an RPG (role-playing game), hence its name.

Language overview

The language consists of actors, items, merchants, actions and spells.

Actors

Actors are either a character or a zombie. They have 2 variable called health and attack. They also have an inventory to hold items.

There can only be 10 actors allowed per game (e.g. per program), though the original compiler allows you to set the maximum amount of characters at the expense of being called a cheater. Character get added to this limit when they are created and they are removed when they die (e.g. when their health reaches 0. Zombies on the other hand won't disappear when their health reaches zero or below, they need to be converted to a character first using the un_zombify spell.

Characters

A character's health and attack are non-negative, specifically, they are unsigned 32-bit integers.

 char ash = (5,3)

A character called ash with health of 5 and attack of 3.

Zombies

Zombies are a special kind of actor, since their health can be negative, specifically, signed 32-bit integers.

 zombie walker = (-4,6)

Items

Items can be used by actors, but they have to first be bought from a merchant.

Potions

Potions have one variable called healing and can be used to heal an actor. Actors can buy them from merchants and need to buy them at least as many times as they'll use them. The potion an actor buys will go in their inventory and disappear when they use it.

 potion p = (5)

A potion that will heal an actor with 5 health.

Spellbooks

Spellbooks are used for casting spells. When an actor buys a spell book, it will go to its inventory and it will keep it until the end of the game (e.g. the end of the program).

 spellbook eucharidion = ()

Merchants

Merchants sell items to actors.

 merchant cabbage_man = ()

Actions

Buys

An actor can buy an item from a merchant using the buys action.

 actor buys item from merchant

Attacks

Actors can attack each other, this subtracts the attack of the attacking actor from the health of the actor being attacked.

 char a = (10,3)
 char b = (2,5)
 b attacks a
 # a will now have 10 - 5 = 5 health

Uses (item)

Actors can use items in their inventory.

 potion p = (5)
 char a = (5,0)
 merchant m = ()
 a buys p from m
 
 a uses p
 # a will now have 5 + 5 = 10 health

Shouts

Shouts outputs the health of the actor using it to the screen with a new line.

 char a = (1,0)
 a shouts
 a shouts

Output:

 1
 1

Whispers

Characters can whisper their health. This is like shouts, but without adding a new line.

 char a = (1,0)
 a whispers
 a whispers

Output:

 11

Spells

Characters can use spell books to cast spells. They differ from actions in that they are casted using spell books and the spell's name is follow by a () or a (param).

God_speech()

This will read the number inputted to stdin.

 character uses spell book casting god_speech()

Speak()

This spell will print out the ASCII value of the health of the actor and is paired with shouts or whispers.

 har jeremy = (33,1)
 spellbook eucharidium = ()
 merchant cabbage_man = ()
 jeremy buys eucharidion from cabbage_man
 
 jeremy shouts eucharidion casting speak()

Output:

 !

Time_warp(char)

The time_warp spell performs the lines beneath it until it reaches the end keyword, at which point it will subtract 1 health from the character inputted and return back to where it started. The character given as a parameter is seen as an offer to perform the time warp. This loop will continue until the character provided as a parameter has no health left.

 # We have 2 characters: david (5 health)  and ella (5 health). David has a spellbook in its inventories
 david uses spellbook casting time_warp(ella)
   ella shouts
 end

Output:

 5
 4
 3
 2
 1

Un_zombify(zombie)

Converts a zombie to a character.

 james_brown uses spell_book casting un_zombify(zombie1)

Confuse(char)

When a character is confused, it will output its health minus one when shouting or whispering.

 steven uses spell_book casting confuse(other_char)
 other_char shouts # Will output the other_char's health - 1 e.g. other_char = (1,2), so the output will be: 0

Output:

 0

Create_potion(potion)

Characters can change the value of a potion to their own health.

 char sans = (6, 1)
 potion p = (5)
 sans buys p from merchant
 
 sans uses spellbook casting create_potion(p)
 sans uses p
 sans shouts

Output:

 12

(6 + 6)

Shift()

Shift swaps a character's health and attack.

 char Ness = (2,1)
 Ness uses spellbook casting shift()
 Ness shouts

Output:

 1

Computational class

Rpg as described, is in the class of bounded-storage machines. Rpg can perform conditional looping with time warp, with infinite loops achievable through the repeated use of a 1 HP potion. Time warp can also be used as an if statement which checks if a variable is true (1), if so it sets it to false (0) and executes the body, otherwise it does not execute the body, keeping it as false (0). Decrements can be performed using a character with 1 attack, and increments can be performed with potions healing 1 HP. It is feasible to create a Minsky machine using these constructions. Since the HP of characters is limited, only a bounded amount of storage is afforded to the machine.

If the official interpreter is used, a program can "cheat" to have access to some arbitrarily high quantity of characters. If the interpreter accepts no limit, then an unbounded amount of characters could potentially be created. If there were a way to dynamically create and reference characters at runtime then cheated games could be Turing complete, but since there is no way to do so, even cheated games are bounded.

Examples

Hello, World!

 spellbook sb = ()
 merchant m = ()
 # We can create a new char for each letter, because we need less than 10
 char h = (72, 0)
 char e = (101, 0)
 char l = (108, 0)
 char o = (111, 0)
 char w = (119, 0)
 char r = (114, 0)
 char d = (100, 0)
 char _ = (32, 0)
 char return = (13, 0)
 h buys sb from m
 e buys sb from m
 l buys sb from m
 o buys sb from m
 w buys sb from m
 r buys sb from m
 d buys sb from m
 _ buys sb from m
 return buys sb from m
 h whispers sb casting speak()
 e whispers sb casting speak()
 l whispers sb casting speak()
 l whispers sb casting speak()
 o whispers sb casting speak()
 _ whispers sb casting speak()
 w whispers sb casting speak()
 o whispers sb casting speak()
 r whispers sb casting speak()
 l whispers sb casting speak()
 d whispers sb casting speak()
 return shouts sb casting speak()

Output:

 Hello world

More specifically: Hello world\n

Adding

This program takes 2 inputs, adds them together and outputs the result.

 char r = (1,0)
 spellbook sb = ()
 merchant m = ()
 potion add = (1)
 r buys sb from m
 r buys add from m
 r uses sb casting god_speech()
 r uses sb casting create_potion(add)
 r uses sb casting god_speech()
 r uses add
 r shouts

Subtracting

This program takes 2 inputs, subtracts the second one from the first one and outputs the result. The first input can be negative, since it is used by a zombie.

 zombie base = (1,2)
 char sub = (1,1)
 spellbook sb = ()
 merchant m = ()
 base buys sb from m
 sub buys sb from m
 # Get two input values
 base uses sb casting god_speech()
 sub uses sb casting god_speech()
 sub uses sb casting shift()
 # subtract
 sub attacks base
 base shouts

Truth machine

This program takes in one number (0 or 1) and outputs 0 if it was 0, and 1 until infinity if 1 was inputted.

 char in = (1,0) # Will be consumed by the time warp
 char caster = (1,0) # Will cast the time warp
 spellbook sb = ()
 merchant m = ()
 potion p = (1)
 caster buys sb from m
 in buys sb from m
 in uses sb casting god_speech()
 caster uses sb casting time_warp(in)
     in shouts
     in buys p from m
     in uses p
 end
 # If in's health is 0, it means he is dead and the loop will not run
 char _0 = (1,0)
 caster uses sb casting confuse(_0)
 _0 shouts

Long word

 # This programs prints out the following sentence:
 #  e   s   o   t  e  r   i  c      p  r o  g  r a   m  m  i n  g    l  a n g u   a g e .
 # 101-115-111-116-_-114-105-99-32-112-_-_-103-_-97-109-_-_-110-_-_-108-_-_-_-117-_-_-_-46
 # duplicates: e, g, a, i, n,  , m, r, o
 
 spellbook sb = ()
 merchant me = ()
 # EsOteRic
 char e = (69, 200)
 char r = (114, 0)
 char o = (111, 0)
 char i = (105, 0)
 # Rest of esoteric
 char s = (115, 0)
 char t = (116, 0)
 char c = (99, 0)
 
 potion pe = (32)
 e buys pe from me
 
 e buys sb from me
 r buys sb from me
 o buys sb from me
 s buys sb from me
 t buys sb from me
 i buys sb from me
 c buys sb from me
 
 e whispers sb casting speak()
 e uses pe # First e is a capital, then drink the potion so all e's that follow will be lowercase
 s whispers sb casting speak()
 o whispers sb casting speak()
 t whispers sb casting speak()
 e whispers sb casting speak()
 r whispers sb casting speak()
 i whispers sb casting speak()
 c whispers sb casting speak()
 
 # Kill unnecessary characters
 e attacks s
 e attacks t
 e attacks c
 
 # Already defined pROgRammIng
 # Recurring chars proGrAMMiNG
 
 char n = (110, 0)
 # We give g attack of 3 => if g attacks m, then the value of m will be m instead of p
 char g = (103, 3)
 # We first define m as p
 char m = (112, 0)
 char a = (97, 0)
 char _ = (32, 0)
 
 n buys sb from me
 g buys sb from me
 m buys sb from me
 a buys sb from me
 _ buys sb from me
 
 _ whispers sb casting speak()
 m whispers sb casting speak()
 r whispers sb casting speak()
 o whispers sb casting speak()
 g whispers sb casting speak()
 r whispers sb casting speak()
 a whispers sb casting speak()
 g attacks m
 m whispers sb casting speak()
 m whispers sb casting speak()
 i whispers sb casting speak()
 n whispers sb casting speak()
 g whispers sb casting speak()
 _ whispers sb casting speak()
 
 e attacks _
 e attacks r
 e attacks m
 e attacks i
 
 # language
 # Still in use: e, a, g, n
 char l = (108, 0)
 l buys sb from me
 potion p = (9)
 l buys p from me
 
 l whispers sb casting speak()
 a whispers sb casting speak()
 n whispers sb casting speak()
 g whispers sb casting speak()
 l uses p
 l whispers sb casting speak()
 a whispers sb casting speak()
 g whispers sb casting speak()
 e whispers sb casting speak()
 
 char dot = (46, 0)
 dot buys sb from me
 dot shouts sb casting speak()

Output:

 Esoteric programming language.

Obfuscation

The rpg compiler doesn't care about indentation or new lines. This means that

 char george = (5,6)
 char steven = (4,4)
 steven attacks george
 george shouts

is equivalent to

 char george
 = (5,6) char                         steven = (4,
       4) steven attacks george george shouts

External resources

  1. Official compiler and cli (Available on Windows, MacOS and Linux. Also available on Homebrew).