Turnfunge

Turnfunge is a small fungeoid (designed by Keymaker in 2023) that is a minimalization of Nopfunge Solid (also by Keymaker in 2023), which in turn is a simplification of Nopfunge (designed by Hubert Lamontagne in 2015).

Language description

Like in Nopfunge Solid, the playfield is a two-dimensional area (of any positive non-zero integer width and height) that repeats infinitely to right and down. The cells are either empty (space character) or solid (any other character). The program, in its file representation, consists of space characters (empty) or other characters (solid), each row of characters is of equal length (determining the width of the program) and each row is separated by a new-line (the amount of rows is the height of the program).

There is the instruction pointer, which has a direction (right, down, left, up). Initially it has its direction as 'right' and begins the program at location 0,0 (the leftmost, topmost corner) in the 0,0-copy. Like in Nopfunge Solid, on every cycle the pointer moves to another cell.

Executing one cycle consists of first seeing what is behind the pointer. Behind the pointer means the cell that is one step from the pointer's location in the direction that is opposite of the pointer's current direction. If the pointer's direction is 'up', the cell behind it is the cell below the pointer. If the pointer's direction is 'left', behind it is the cell on its right. And so on. The cell behind the pointer can be in another copy if the pointer is on an edge row or column and its direction is enabling that. What is in the current cell has no effect on the pointer, only what is behind it. If the cell behind the pointer is solid, the pointer's direction is rotated 90 degrees right (meaning right -> down, down -> left, left -> up, up -> right). If the cell behind the pointer is empty, then the direction is unaffected. If the cell behind the pointer is out of bounds (as it is when the program starts), the cell behind is considered as empty. After possibly altering the direction, the pointer is moved one step into its direction. As in Nopfunge Solid, the pointer can move from one copy to another if it moves past the edge. The exceptions are the topmost edge and the leftmost edge. If the pointer's direction is 'up' in the topmost row of the topmost copies, its direction is reversed, and it will move one step into this newly set direction ('up' becomes 'down' and the pointer is moved one step down). Similarly, if moving left in the leftmost column in the leftmost copies, the pointer will be set to 'right' and moved one step right. (In Nopfunge Solid this behaviour is 'turn right and move right' and 'turn down and move down' in topmost and leftmost edges respectively.)

The program never halts.

Computational class

The language is Turing-complete. It is proven via Nopfunge Solid (which is Turing-complete) translation. Whereas I think Minsky Machine translation would have been easier to design, I wanted to try a different approach. My translation method translates the given Nopfunge Solid program into a Turnfunge program that is of width 8+(11*w) and height 8+(8*h), where w and h are the width and height (in cells) of the Nopfunge Solid program. Each Nopfunge Solid cell is translated into a 11*8 block and there will be a 8-cell wide border on left and 8-cell tall border on top. This border, of course, repeats in every copy of the playfield, and had to be designed so that it will only affect change when the simulated Nopfunge Solid program tries to move the pointer past top or left edge. The halting extension of Nopfunge Solid is translated into an endless loop.

Example translation

This is a simple Nopfunge Solid program where the pointer is first moved to 0,1-copy, then back to 0,0-copy, and when the pointer tries to move up on the topmost row in 0,0-copy, its direction is set to 'right' and it moves one step right, where it is sent down and eventually reaches a halting instruction (an instruction extension).

v   v
 > ^ 
    .
>v   

Translated using my translator, this Turnfunge program is created. One can trace the behaviour of the above program in the translation somewhat easily if one knows what to look for. The different letters were for my benefit in the design phase, they could be any other 'solid' characters.

y              n          n          n          n          n   
        a     oo   a     oo   a     oo   a     oo   a     oo   
           o  o       o  o       o  o       o  o       o  o    
         aa         aa         aa         aa         aa        
         a  ww      a  ww      a  ww      a  ww      a  ww     
             w          w          w          w          w     
             oo         oo         oo         oo         oo    
 y          o          o          o          o          o      
                 o                                           o 
           a o nn     a   nn     a   nn     a   nn     a o nn  
   aa           n          n          n          n          n  
 o  a            x          x          x          x          x 
 oo   o    a          a          a          a          a       
   x oo       o                                           o    
       o    a          a          a          a          a      
  o         a          a          a          a          a      
                                                  o            
           a   nn     a o nn     a   nn     a   nn     a   nn  
   aa           n          n          n          n          n  
 o  a            x          x          x          x          x 
 oo   o    a          a      o   a          a      o   a       
   x oo                  o                     o               
       o    a          a          a          a          a      
  o         a          a          a          a          a      
                                                             o 
           a   nn     a   nn     a   nn     a   nn     a o nn  
   aa           n          n          n          n          n  
 o  a            x          x          x          x          x 
 oo   o    a          a          a          a          a      o
   x oo                                                   o    
       o    a          a          a          a          a      
  o         a          a          a          a          a      
                            o                                  
           a o nn     a o nn     a   nn     a   nn     a   nn  
   aa           n          n          n          n          n  
 o  a            x          x          x          x          x 
 oo   o    a      o   a          a          a          a       
   x oo       o          o                                     
       o    a          a          a          a          a      
  o         a          a          a          a          a      

Interpreter and translator

nfsolidtotf.py - A Nopfunge Solid into Turnfunge translator.

visual.html - A visual Turnfunge interpreter written in Javascript. Shows only the current copy the pointer is in, but better that than no visuals at all. Also missing pretty much all checks about the program exceeding its memory space.

-- Keymaker, 30.3.2023