# How to score Box-256 answers

Since asking what I believe is the first Box-256 based question on Code Golf (Box-256 Assembly - BIG SQUARE II) there has been some confusion with regards to scoring.

I'd like this question to be a place where people can put forward scoring ideas so we can choose one that suites best Box256 challenges. I'd like to post up one code golf question for each of the built initial Box256 levels so we need a scoring systems that suites them.

• You could ask this question on main with the challenge-writing tag. (Especially since the question of how one can score code golf in Box-256 could be interesting outside of this community as well.) Commented Apr 23, 2016 at 13:08

## Position of the last non-zero byte in the original program

Of course, trailing zeros can't be counted, otherwise all programs would be the same size. But empty lines within the program should be counted, because how wide the spacing between certain cells is is actually relevant information that needs to be encoded.

Hence, we simply count how many cells there are until the last non-zero cell, treating all four bytes in a nibble equally. Note that cells 2 to 4 in each nibble can contain * and @ modifiers beyond the byte their actually storing. However, Box-256 encodes this information into the first byte in addition to the OP code on that line, hence we don't need to count these separately. The - on the other hand is just syntactic sugar for 2's complement, i.e. -01 is completely equivalent to FF.

If we take the example solution for the first problem (and modify it slightly, which breaks it, but this is just an example):

MOV 022 @80 000
MOV 030 @C0 000
PIX @80 001 000
JGR 00B @81 -0C
MOV 000 @81 000
JMP @08 000 000
000 000 000 000
000 000 000 000
000 000 000 000
-01 -10 000 000


That would be 50 bytes of code (up to the -10).

• * and @ modifiers for bytes 1 to 3 on a line of code are all stored in byte 0 of the same line (which also stores the opcode) so there's no need to account for them separately. Commented Apr 24, 2016 at 6:26
• @impomatic Ohh, I didn't notice that, I'll update the answer. Commented Apr 24, 2016 at 9:58
• -1 from me, even just because it disallows this solution for the checkerboard.
– orlp
Commented Apr 24, 2016 at 14:22
• @orlp I don't understand why the zeros in that shouldn't be counted. This is no different from significant whitespace in a Befunge program. Commented Apr 24, 2016 at 14:24
• @MartinBüttner I'm envisioning the all-zero BOX-256 machine as a 'clean slate', where a programmer replaces bytes of his choice by other values, costing one unit per byte. Any byte that is left unchanged does not cost anything. Consider a fixed-size Hexagony challenge - you wouldn't count the size of the board in that either. In the end what matters is whether the fixed size nature of the BOX-256 is fundamental, and since everything about it is 8-bit, I'd argue that its size is fundamental, and not a 'cost' of the program.
– orlp
Commented Apr 24, 2016 at 14:30
• I think this is the best answer. If you think about how REDCODE is written, this is similar. For the purpose of placing the program in memory, the empty lines/bytes are required and should included in the score. Commented Apr 27, 2016 at 14:33
• @orlp I understand what you are staying, if you want to get really literal then imaging turning a computer on, all memory is blank to start with so we can’t count that as intended lines of code. However I agree with Martin Büttner. In the example answer you linked to for the checkerboard solution, those aren't just empty memory spaces they are NOPs. The NOP instruction in BOX-256 is opcode 0. And the "white-space" provide by all those zero's is actually an integral part of that code being able to provide a valid answer, it’s a NOP sled. Commented Apr 28, 2016 at 12:47
• ...In the case the NOPs aren’t actually required one can move the code up from the bottom and it would be 4 lines of code but those NOPs are required for this answer to work. Commented Apr 28, 2016 at 12:47

# Lines of Code as counted by BOX-256

BOX-256 automatically counts the lines of code. Why not score by the built in count? Lines containing instructions or non-zero data are counted.

For example the following counts as 2 lines of code:

    PIX @0C @0D
000 000 000 000
000 000 000 000
088 008 000 000


It's important to include data lines in the count otherwise the optimal solution to every BOX-256 problem is same tiny loop with different data.

• I'm not sure that not counting empty internal lines is a good idea. If those really aren't needed, then you can always move your data or code lines further up to close the gap. If they are needed they're important information that is encoded in the source and should be counted. Commented Apr 24, 2016 at 10:02

# Number of characters/bytes in the program

MOV A B C is 9 bytes.

MOV A B C
PIX A B


is 17 bytes.

This is fairly normal for most languages.

• -1 from me, the BOX-256 assembly language is just a programmer-friendly frontend for the actual code (shown directly to the right of the source). As an example, -FF is exactly the same as 01, and this just makes golfing more annoying. And THR 00 is the same 7E00.
– orlp
Commented Apr 24, 2016 at 14:36
• I agree with @orlp that these are just being turned into Opcodes so counting the bytes of the letters that make up the instruction name is not good. You can put the opcodes in directly so we can reduce the byte count for all programs in that way. Commented Apr 28, 2016 at 12:34

# Number of non-zero bytes in the initial state.

We ignore the assembly instructions, and only look at the state. We count the number of non-zero bytes in this initial state.

In the example below, there are 15 non-zero bytes.

• We count spaces in 2D languages and other forms of non-removable NO-OPs as well. I don't see why it should be different here. Commented Apr 24, 2016 at 14:29
• @MartinBüttner Because in my opinion the fixed size of the BOX-256 is fundamental to its nature, and it does not become smaller if the user doesn't use its full space.
– orlp
Commented Apr 24, 2016 at 14:32
• +1, if we're not going to use BOX-256's built in LOC this is the next best option. It still allows arbitrary code spacing and also takes away the advantage of misaligned code. However, minimizing non-zero bytes would mostly come down to making the best use of location 00, e.g.: ADD 001 @ 11 @11 MUL 088 @ 11 *00 DIV *00 080 *00 ADD 002 *00 *00 PIX 000 *00 000 Commented Apr 28, 2016 at 8:35

# Number of bytes in the instructions and arguments

The length of the program, minus spaces and padding.

MOV A B C is 6 bytes.

MOV A B C
PIX A B


is 12 or 11 bytes, depending if you count the newline.

• I don't know why people hate this answer much more than the whitespace-including version. Commented Apr 27, 2016 at 16:23
• @CatsAreFluffy yeah. Commented Apr 27, 2016 at 16:34
• You haven't said what to do about "white-space", refering to the answer @orlp has posted, how many bytes is that in your method? bare in mind that all the "white-space" of 0's in the middle is actually executed NOPs. Commented Apr 28, 2016 at 12:37