Sokolang

From Esolang
Jump to navigation Jump to search

Sokolang is a programming language created by FLeckami that use Sokoban gameplay to execute commands.

File structure

Here is an exemple file (it prints "Hello, world!"):

 ###
##*##
#@H*#
#####

---

h:10,13,72,101,108,108,111,44,32,119,111,114,108,100,33

---

rwu

The file has 3 distincts zones separated by ---

The first zone is the level map, the second one is the stack initialisation and the third one is the Player's actions

Level map

The table below show the elements you can place on:

symbol name
@ player (only one)
# wall
n crate where n is a letter
* mark (at least one)
. floor

empty spaces are considered as floor

A crate marked with a lowercase letter is a read-only crate. The stack cannot be modified, so a read-only crate cannot execute command and has no effect when it is on a mark

Stack initialisation

Every crate have their own stack which can be initialize like this:

n:123,45,6,... where n is a lowercase letter

a same letter, uppercase or lowercase, share the same stack

The player has also his stack. It is the same syntax as for crates. Just replace n by @

Player's actions

actions

After the stacks initialisation, the actions string is executed and loop infinitly. The program ends if all mark are covered by a crate or the player

The player can push multiple crates at the same time but he can pull only one crate at the time.

The player can perform the following actions:

action description
u, d, l, r move the player to the given direction (up, down, left, right)
p switch between push and pull (push at the beginning)
w wait a turn. Used to tranfert a value and execute commands
[...] actions group. Used to group and loop a list of actions

a number can be added to execute an action as many time as this number. For exemple, 3u move the player up 3 times

For [...], it execute the actions inside as many time as this number. 5[2rw3u] is the same as 2rw3u2rw3u2rw3u2rw3u2rw3u

prefixes

prefix description
+ the action is executed if the last test is true
- the action is executed if the last test is false
@ execute the action once

[...] has specials behaviors with prefixes:

  • +[...]: execute actions inside while the last test is true
  • -[...]: execute actions inside while the last test is false
  • @[...]: execute actions inside once. @[2rw3u] is the same as @2r@w@3u

value transfert

when the w action is executed, if the player has moved a crate in his last action, a value transfert has occured:

  • if the player has pushed the crate n times, the n-th value of the player's stack is popped and pushed into the pushed crate stack. Nothing happend if the pushed crate is a read-only crate
  • if the player has pulled the crate n times, the n-th value of the pulled crate stack is popped and pushed into the player's stack

command

When the value transfert is finished, every element (crate and player) on a mark execute a command, begin with the player then the crates in alphabetic order.

The first value pop and correspond to the command code

code name description exemple
0 nop no instruction
1 + pop the 2 first values a and b and push a+b [1,123,45,6] -> [168,6]
2 - pop the 2 first values a and b and push a-b [2,123,45,6] -> [78,6]
3 * pop the 2 first values a and b and push a*b [3,123,45,6] -> [5535,6]
4 / pop the 2 first values a and b and push the integer part ofa/b [4,123,45,6] -> [2,6]
5 % pop the 2 first values a and b and push the reminder of a/b [5,123,45,6] -> [33,6]
10 outstr pop the first value n of the stack correspond to the number of character to print,
then pop the n next value and print them as ASCII character
[10,2,72,105] -> [] and print "Hi"
11 outint pop the first value of the stack and print it [11,123,45,6] -> [45,6] and print "123"
12 instr ask the user to input a string and push the number of character then the ASCII value of each character if input is "hello", then [12] -> [5,104,101,108,108,111]
13 inint ask the user to input a number and push it if input is 56, then [13] -> [56]
20 copy push the first value on the stack [20,123,45,6] -> [123,123,45,6]
21 del pop the first value of the stack [21,123,45,6] -> [45,6]
22 reverse reverse the stack [22,123,45,6,78,9] -> [9,78,6,45,123]
30 test pop the first value. The test is false if this value is 0, otherwise it's true
31 not pop the first value and push 1 if this value is 0, otherwise 0

all unknown code are considered as nop

more commands can be added in the future

Exemples

Cat:

#######
#@*.C*#
#######

---

c:12
@:10

---

3rlwrplprw2l

Truth machine:

  ###
###d#
#@..##
###*.####
#p.*.*.t#
#########

---

@:13
t:30
p:11
d:20

---

2rdwupdwpu2d3rplwlp2l+[r2updwpu2dlprwpl]prw2u2dr