Bonkbly

Dig deeper into the bonkbly instruction set.

Bonkbly is a JavaScript simulated instruction set. The instruction set implements basic calculations on integers and flow control instruction. Bonkbly only supports 2-complement 32-bit integers and labels. The integers can be used to perform basic integer calculations. Labels are used to jump to specific locations in the code. The entry point for each Bonkbly programm is the label main. If this label is not defined, the programm starts executing the instruction at the top of the file.

Syntax

An instruction in Bonbkly starts with the instruction name, followed by a number of arguments. For most instructions, these arguments can be either a number or a register/variable Some instructions require specific arguments to be a register/variable.

The control instructions jmp, jz and jnz require a label as argument.

An example of the add and jmp instructions are given below:

add 12 12 $value
jmp main

Bonk supports line comments. Start a line comment by using double dashes:

-- This is a comment

The syntax for labels is as follows, note that the colon is required:

label main:

Bonk is case-insensitive, uses a newline as instruction terminator and every line can contain any number of trailing and/or leading whitespaces. The following example is, although horribly cursed, valid syntax:

label main:
	           MoV 0 $vAlEu
	AdD 12 $VaLuE $value
	LABEL LoOp:
					  mOV 12 $other_value
add $VALUE $OTHER_VALUE $24value
  Note that $vAlEu, $VALUE, $VaLuE and $value all point to the same register.
  $24value is a valid register name, just like $24.

Bonkbly does not require an instruction to follow a label definition, it also does not require an indent to take place:

-- Entry point to programm
label main:
label loop:
	mov 0 $i
	add 1 $i $i
	-- Do stuff

label end:
mov 12 $value
Coding style

This part will give an overview of the coding conventions used in Bonkbly. These will try to keep your code readable.

As stated in the introduction, the entry point for each program is where the main label is defined. It is advised to always define this label, because if this label is not defined, the program will start executing the first instruction in the file. Furthermore, it is advised to indent every instruction, as this greatly improves readability.

label for_loop:
	add 1 $i $i
	-- Do stuff
	cmp $i 12
	jnz for_loop

label main:
	mov 0 $i
	jmp for_loop

A short description of what a label implements can be given just above the label using a line comment, e.g.:

-- Return location for for loop
label for_loop:

Subfunctionalities in functions can be indented further. However, every label is a global label, so the same label cannot be used twice.

label for_loop:
	add 1 $i $i
	-- Do stuff
	mov 0 $j

	label for_loop_in_for_loop:
		add 1 $j $j
		-- Do stuff
		cmp $j 6
		jnz for_loop2
	
	cmp $i 12
	jnz for_loop

label main:
	mov 0 $i
	jmp for_loop

Since Bonk is case-insensitive, it is advised to always use snake_case for labels and registers, rather than CamelCase or pascalCase, to avoid confusion when switching between the two.

Instructions

Here you find an extended description of the bonkbly instructions.

Syscalls

Here you find an overview of the syscalls that were implemented. Syscalls are used to interact with the environment, in this case with Bonk.

Sens

All of the sens syscalls (fsens, lsens, rsens and nsens) are used to sense the environment. These syscalls will write values to specific registers based on the tiles around the players. Here we will give you an overview of the valid values, and the specific registers every sens syscall writes to.

All of the registers used for the sens syscalls are read-only, and can only be written to by the sens syscalls. Writing to these registers will result in an error and the program will be terminated.

fsens, lsens and rsens

For the fsens, lsens and rsens instruction, the possible values are:

Value Binary representation Description
1 0b00001 The observed tile is out of the field
2 0b00010 The observed tile is a wall
4 0b00100 The observed tile is a player
8 0b01000 The observed tile is empty
16 0b10000 The observed tile contains a powerup

All values are writting to the registers $br1 to $br8. The specific tiles that are observed are given in the figures below.

Tiles observed by the fsens instruction. The bot (represented in red) is looking to the top right, and will observe the orange tiles. Writing the corresponding values to registers $br1 to $br8.

Tiles observed by the lsens and rsens instruction. The bot (represented in red) is looking to the top right, the rsens instruction will observe the blue tiles, the lsens the green. Writing the corresponding values to registers $br1 to $br5.

Nsens (near sens)

The nsens (near sens) instruction observes the tiles around the player. All tiles less than 2 tiles away from the player are observed. It will check if a player, a wall, the edge of the field or a powerup is present. The values are written to specific registers.

Register Description
$player_nearby This register is set to 1 if a player is nearby (not including the bot itself).
$wall_nearby This register is set to 1 if a wall is nearby.
$edge_nearby This register is set to 1 if the edge of the field is nearby.
$powerup_nearby This register is set to 1 if a powerup is nearby.

Bonk specific variables

To help you code your bot, we added 2 extra variables: $health and $tick. These variables allow you to take a look at your current health, and keep track of the current tick.