Half-Broken Car in Heavy Traffic
Half-Broken Car in Heavy Traffic is a 2D-grid language with operators also acting as direction signs, making programming very difficult. It was created by Niels Serup (User:Nqpz).
Language overview
(Source)
HBCHT is a 2D grid-based programming language. You are a car fighting to get to the exit of a very chaotic highway. You have to follow the signs, but whenever you do that, you also change your memory. The value of your current memory cell can be incremented or decremented and your memory cell index can change. You can also find signs that tell you to turn either right or not turn at all, depending on your memory.
The car can drive in four directions: up, right, down, and left. Because of the chaos, you never know which direction the car is headed when the program starts. This makes it easy to randomize the output.
To make things worse (actually, it's to make programming in HBCHT possible), you cannot turn left (relative to your current direction) because your car is half-broken. You can drive straight ahead, you can turn right, and you can reverse.
Command/marker | Description |
---|---|
>
|
go right, next memory cell |
<
|
go left, previous memory cell |
^
|
go up, increment memory cell value |
v
|
go down, decrement memory cell value |
/
|
turn right if the current memory cell has the same value as the previous cell, else continue |
o
|
the car |
#
|
the exit |
- There can be only one car and only one exit
- The car cannot turn left; any relative left turns will be ignored along with their memory effects
- The program always starts at memory cell #0
- All memory cells have the value 0 by default
- Input values cannot be negative, but values returned by a program can
- The car cannot go out of bound; if it exits to the right, it reenters to the left, etc.
- Values cannot be input to memory cells below memory cell #0, but the program can set values in these
- Values can be arbitrarily large. An interpreter or compiler without this feature is valid, but not perfect (note that hbcht's C translator uses 32-bit ints and is thereby not perfect).
A semicolon denotes a comment. Anything from the semicolon to the end of the line is ignored.
If a program file contains a line that starts with @intext
, it will see
input as text and convert the text to ordinals before running the core
function.
If a program file contains a line that starts with @outtext
, it will show
output as a text string instead of a list of numbers.
Examples
Increment
; Increment the first memory cell once without changing the other cells. > ^ < > v < # ^< > ^ ^ ^<> ^ > ^< ^ > v < o v v v < > v v v v v v v v v > ^ <
Decrement
; Decrement the first memory cell once without changing the other cells. v v v < <> ^ ^ >>^< >v<o>^< v v v > v< # > ^< ^
Hello, World!
; Prints "Hello, world!\n". @outtext v >v ^ > v < v >>^< v ^ v v ^ ^ < v ^ ^ v ^ > />^<v v ^ ^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^ ^ v v ^ ^ ^ < v ^ ^ >^< v ^ ^ ^ v ^ ^ v > ^< ^ ^ < ^ >>^< > ^<v ^ >v<< v >v< ^ >^< o>v v > ^< v ^
Move cell value
; Move the value of memory cell #0 to memory cell #1. ; Making sure the car ends up going in the same direction with the same ; variables. >v < ^ ^<> v < >v ^ ^<> ^ > ^< >v<o>^ < v > ^< ^ v > v < ^ v ; The actual moving. >v << #/ v ^ > >^< ^
Ignore the random direction
This is an extension to the increment program so that the input is unaffected and you start on the first cell like normal. The car will be at the hashtag moving downwards. From there you can write whatever program you want deterministically. If you use this, don't put code in columns 5, 9, or 16 (1-based) and don't do wraparounds in any of the rows or columns where this code appears.
v > ^ < >v< > v < v^ > ^ < ^< > ^ ^ ^<> ^ > ^< ^ > v < o v v v < > v v v v v v v v v > ^ < #
Random
; Returns either 1 in #0 or -1 in #1 > # ^ o>v