33
\$\begingroup\$

Since programs may be created in vanilla (un-modded) Minecraft using redstone to create logic gates (and more), someone could create such a program for a challenge on this site.

How would such an entry be scored?

Some possible scoring methods:

  • Blocks used (placed redstone counts as a block)

  • Redstone used (redstone is also used in crafting redstone torches, repeaters, and other similarly useful components)

  • Volume of the minimal bounding rectangular prism (same as blocks, but includes air blocks)

Note on testing:

Buying Minecraft is not required to test a program!

  • Play the demo version:

    1. Start a LAN world
    2. Turn cheats on
    3. Use /gamemode 1, (or 2 or 3) in the chat/console to use Creative Mode, Adventure Mode and/or Spectator Mode, respectively. Creative mode will allow you to place any blocks you want. The demo starts in Survival Mode. Note that the demo ends after 5 in-game days (1 hr 40 min), and the world will have to be reset (wiped/restarted) to play more.
    4. If the program is posted with a .schematic file (useful for complex programs), you can install a mod for your demo (or purchased) version of Minecraft that can import it. MCEdit and WorldEdit are two popular mods that can do this.
  • Use a redstone simulator. These are separate programs with partial functionality from Minecraft, useful for circuit creation, simulation, and exportation. You will probably want to try a few before choosing one to stick with.

    1. Baezon's Redstone Simulator (download)
      • Has the ability to export as a .gif
      • Copy/Paste functionality
      • Has the ability to simulate North/South lever functionality like Minecraft has
    2. Mordritch's JavaScript Redstone Simulator (web)
      • No download required
    3. ... and many others. Just search on Google.
\$\endgroup\$
15
  • 5
    \$\begingroup\$ I'm not necessarily against the use of Minecraft redstone in submissions, but note that such submissions will be extraordinarily tedious to test for those who always test others' submissions. It also requires a copy of Minecraft to test, which isn't free. I'll be interested to see how such a submission is received by the community. \$\endgroup\$
    – Alex A.
    Nov 4, 2015 at 16:54
  • \$\begingroup\$ @AlexA. If you read the comments on the answers below, you'll see there are ways to test that don't require purchasing Minecraft, such as playing the demo version, or using a redstone simulator. I'll edit the info into the question, though. \$\endgroup\$
    – mbomb007
    Nov 4, 2015 at 17:02
  • \$\begingroup\$ See this answer I put up recently using my improved method. Would you agree that this method of scoring works, or does something need to be improved? \$\endgroup\$ Nov 6, 2015 at 9:02
  • \$\begingroup\$ I wonder how one might grade mods... \$\endgroup\$ Nov 9, 2015 at 15:32
  • \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ I kinda think mods can't be graded. Either that, or they have to be separate from vanilla MC programs. I guess if you wanted, look up how many bytes the mods add, then add that offset to your score. \$\endgroup\$
    – mbomb007
    Nov 9, 2015 at 17:46
  • \$\begingroup\$ Also, from your recent answer in MC, I was reminded of something: What is stdout in MC? Stdin is usually levers, buttons, etc for bits/bytes... \$\endgroup\$
    – mbomb007
    Nov 9, 2015 at 17:53
  • \$\begingroup\$ @mbomb007 point 1) that is a logical point. point 2) Oh, yeah! STDOUT could be redstone lamps; this is the best way of doing it. Graphical output could be, of course, blocks, esp. coloured wool. \$\endgroup\$ Nov 9, 2015 at 18:15
  • \$\begingroup\$ Also, when I think of programming in MC, I pretend command blocks don't exist. It feels kind of like cheating (since there's commands). Graphical output should be done either with lamps, or if using blocks for colors, you need to move them with pistons, like having an in-game printer (rather than using /setblock). It's more impressive. \$\endgroup\$
    – mbomb007
    Nov 9, 2015 at 18:53
  • 1
    \$\begingroup\$ Yeah, so distinction between input/output can be "iffy" in some cases. Also, is there a "quine" in Minecraft? I'd guess not... \$\endgroup\$
    – mbomb007
    Nov 10, 2015 at 2:03
  • \$\begingroup\$ I think it's fine to make up an arbitrary scoring system for graphical languages as long as it's fair, but don't call it "bytes" because it isn't. Using "Bytes" means there is an actual representation of the program being stored. Could we call it "Equivalent bytes"? \$\endgroup\$ Nov 30, 2015 at 20:12
  • \$\begingroup\$ @intrepidcoder I saw someone using blytes, but I don't really like it. I think people should list how many blocks, and how many bytes. The score is the sum, but I want to see both in the post. \$\endgroup\$
    – mbomb007
    Nov 30, 2015 at 22:45
  • \$\begingroup\$ @mbomb007 There is a quine in Minecraft, if you use command blocks. Putting a block of redstone above a command block with the command clone ~ ~ ~ ~ ~1 ~ ~1 ~ ~ would create an identical structure 1 block away. \$\endgroup\$
    – clapp
    Dec 3, 2015 at 3:34
  • \$\begingroup\$ @VoteToSpam But that doesn't distinguish between input and output. It's more like self-modifying code. Also, wouldn't the generated command block then have the same code and run? \$\endgroup\$
    – mbomb007
    Dec 3, 2015 at 15:49
  • \$\begingroup\$ No, its "powered" flag is set \$\endgroup\$
    – clapp
    Dec 4, 2015 at 16:24
  • 1
    \$\begingroup\$ @mbomb007 blytes are a blight on Redstone golfing. (Geddit? blight, blyte...) \$\endgroup\$
    – wizzwizz4
    Sep 18, 2016 at 21:51

8 Answers 8

28
\$\begingroup\$

There is now an MC Standard for bytecount.

With the 1.10 update, they introduced a block called the "structure block", which creates a .nbt file representing a structure in its entirety that can be measured in bytes. As this is a Minecraft standard for converting builds into bytes, this should be our standard as well.

\$\endgroup\$
10
  • \$\begingroup\$ @mbomb007 Linked. I can't think of anything that would work in past versions that wouldn't work in 1.10. \$\endgroup\$ Jul 8, 2016 at 4:55
  • \$\begingroup\$ Maybe if a program made use of "bugs" that were later fixed? I can't think of any specific ones. The South-east rule was changed from SW in 1.9. That might affect things somehow. Levers perhaps. \$\endgroup\$
    – mbomb007
    Jul 8, 2016 at 16:08
  • \$\begingroup\$ Also, seems like users will want to use "void" instead of air now, to save bytes. \$\endgroup\$
    – mbomb007
    Jul 8, 2016 at 22:00
  • \$\begingroup\$ And what's ".nbt" stand for? \$\endgroup\$
    – mbomb007
    Jul 8, 2016 at 22:01
  • 1
    \$\begingroup\$ @mbomb007 NBT Tags. \$\endgroup\$ Jul 9, 2016 at 2:02
  • \$\begingroup\$ Oh, right. I even have NBTEdit. Silly me. \$\endgroup\$
    – mbomb007
    Jul 11, 2016 at 15:55
  • 1
    \$\begingroup\$ Structure blocks have a size limit. This means that not every Minecraft submission can be measured with this method. I don't think that this method is sufficient. \$\endgroup\$
    – Wheat Wizard Mod
    Jan 10, 2017 at 5:15
  • 1
    \$\begingroup\$ @WheatWizard Structure blocks are limited to 32 x 32 x 32 in size, but for larger constructions you could just make multiple structure blocks, and add up the file sizes. \$\endgroup\$
    – BradC
    Jun 5, 2017 at 2:11
  • 4
    \$\begingroup\$ 1.12 introduces Functions. We should probably allow submissions to use these, and their location in the file hierarchy is meaningful. How would you score? \$\endgroup\$
    – CAD97
    Jul 7, 2017 at 17:04
  • \$\begingroup\$ This answer only applies now to Java edition. Anybody using Bedrock or Education edition cannot easily export .nbt files for structures from the world files. \$\endgroup\$ Dec 12, 2019 at 16:45
19
\$\begingroup\$

Bytes ≡ Functionality

I love Minecraft! Here's my two cents:

  • Redstone-related items (i.e. items that interact with redstone) should be each 1 byte, except for:
    • Command blocks, whose byte count should be 1 + length of inner code (Or 2 + length of inner code, if you are using version 1.9 or above, as this version adds an orientation to command blocks. I would add another byte for conditional/unconditional mode, but methinks that's a bit too much.. Ideally, a command block would consume more bytes, since it can have the attributes of Impulse/Chain/Repeat; Conditional/Unconditional; and Always Active/Needs Redstone. I am thus tempted to say that a command block indeed consume 4 bytes per default; however, since these features are as of yet unreleased).
    • Air blocks, which should be 0 bytes.
  • Blocks should count as 1 byte, keeping in mind:
    • If they compose the mandatory floor of the "program". This can be thought of as a construction on an infinite plane; the base does not count towards the byte count. (I.e., flatlands.)
    • Buttons, levers, methods should be counted 1 byte, as this is similar to collecting input.
    • The placing of blocks in a certain place (e.g. placing sand atop a command block which waits for the sand to be placed there) is 0 bytes, as this is user-action.
    • Barriers should count as 1 byte, since they have physical interaction with the world.
  • Entities should be 2 bytes: one for the position, and one for the spawning of the mob.

This still doesn't address the new command blocks added in the snapshot and future updates; I would say these still count as 1 byte, but I don't know enough about them. I also hesitate to say anything special about pistons and sand, because they seem like they should be 1 byte, but they do move; that is, I don't know how to score movement. If asked, I would lean towards the 1 byte option.

\$\endgroup\$
19
  • \$\begingroup\$ I think I like this scoring approach the best. Though when entities would be useful, I have no idea. I guess people have used them for "Snake" or "Pacman"... \$\endgroup\$
    – mbomb007
    Nov 6, 2015 at 4:33
  • 1
    \$\begingroup\$ I agree with everything here except for the entities part - using scoreboard, you can have entities act as ArrayLists. You can also hold data in non-entity dummy players, which should also be considered. This is superior to my answer because it considers command blocks, which mine did not. \$\endgroup\$ Nov 6, 2015 at 7:50
  • \$\begingroup\$ @VoteToClose Excellent point. I'll adjust slightly \$\endgroup\$ Nov 6, 2015 at 12:18
  • \$\begingroup\$ For defining the "floor": we could require the programs to be on a superflat world, with structure generation turned off. That makes it trivial to distinguish floor from program: anything below y=4 is floor and not counted. \$\endgroup\$
    – user45941
    Nov 6, 2015 at 17:35
  • 3
    \$\begingroup\$ Personally, I think air should still be counted - whitespace is counted in programs, and white codels are still counted in Piet. \$\endgroup\$
    – Sp3000
    Nov 7, 2015 at 2:15
  • 1
    \$\begingroup\$ @Sp3000 Well, air is just there by default. It's like being counted for the whitespace hanging after every line. IMO, a block "destruction" would cost a byte (replacing with air), but an air block would be just... there. Perhaps I can see a plausible argument for significant air? \$\endgroup\$ Nov 7, 2015 at 2:17
  • 3
    \$\begingroup\$ -1; this counting method can often be less than entropy. Consider an arrangement of 2 dirt blocks, n meters apart in a straight line. There are an infinite number, but they would all be counted as 2 bytes. There should never be more than 65536 two-byte programs. \$\endgroup\$
    – lirtosiast
    Nov 9, 2015 at 19:06
  • 3
    \$\begingroup\$ There are an infinite number of arrangements of two non-air blocks, so we cannot count them all as 2 bytes. \$\endgroup\$
    – lirtosiast
    Nov 9, 2015 at 20:22
  • \$\begingroup\$ Your scoring scheme becomes floor-agnostic if you think of redstone wire and the block it's on counting as 1 point total. Then, the score for a (block-only) schematic is (# of ALL blocks) - (# of blocks that require support) \$\endgroup\$
    – aebabis
    Nov 10, 2015 at 4:55
  • \$\begingroup\$ @ThomasKwa Please, talk to me in chat at some point, as I don't quite follow you. (I am unavailable reliably for ~10 is hours, from about now to around 4, EST.) \$\endgroup\$ Nov 10, 2015 at 12:10
  • 2
    \$\begingroup\$ To give an example of what @ThomasKwa is talking about, a self-propelling slime machine can travel indefinitely. By varying the distance to a flying machine's destination, you could encode an arbitrarily-long delay "for free." Though in practice, it seems unlikely that someone could efficiently abuse this. \$\endgroup\$
    – aebabis
    Nov 10, 2015 at 15:59
  • \$\begingroup\$ How would entities spawned in at runtime be counted? (Where a different number of entities can be spawned in each time) \$\endgroup\$
    – GamrCorps
    Nov 26, 2015 at 14:20
  • 1
    \$\begingroup\$ @acbabis The floor is like the hardware that a program is built on. A blank program in MC would still have a floor. Just start a "flat" world. \$\endgroup\$
    – mbomb007
    Apr 28, 2016 at 17:03
  • 1
    \$\begingroup\$ Minecraft stores blocks as shorts, so, each block should be 2 bytes IMO \$\endgroup\$
    – Bálint
    May 17, 2016 at 20:46
  • 2
    \$\begingroup\$ @Bálint Citation needed? If you feel like that, you should post it as an answer. \$\endgroup\$ May 17, 2016 at 20:47
8
\$\begingroup\$

Byte size of a corresponding valid .schematic file

Easy to score and has no major issues with entropy. The only problem is, of course, that the byte counts are going to be a lot higher than one would desire, but I thought I'd just post this as one possible option.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Don't .schematic files use GZIP'd NBT files? Wouldn't that have an issue with entropy? I don't quite remember (it might use one of the non-compressed varieties). \$\endgroup\$
    – Pokechu22
    Nov 30, 2015 at 17:38
7
\$\begingroup\$

Minimal Bounding Cuboid Volume

Only for things without Command Blocks!

The volume includes any air blocks, non-solid blocks, and blocks that are supporting redstone dust or other components.

This is the simplest and most natural way to score Minecraft submissions. It's a direct measure of space taken up, just like a byte count is the amount of memory taken up.

I don't have scoring method for builds that include Command Blocks, but I think this is the obvious choice when Command Blocks are not present (if we even allow such submissions...).


Perhaps for things with Command Blocks the cumulative byte count could be counted and reported alongside the block volume count (since it's kind of an apples and oranges thing). So the title of a Minecraft submission might look like #Minecraft - 20 blocks, 17 bytes.

\$\endgroup\$
4
  • \$\begingroup\$ Golfing the size (volume) and golfing the logic (bytes?) do seem to be two different optimizations to be made. If there are ever challenges specific to Minecraft, the scoring method should be stated in the question. \$\endgroup\$
    – mbomb007
    Nov 16, 2015 at 17:33
  • \$\begingroup\$ Also, what do you mean if we even allow such submissions...? Does this refer to challenges including or not including command blocks? \$\endgroup\$
    – mbomb007
    Nov 16, 2015 at 17:34
  • \$\begingroup\$ @mbomb007 Answers with no command blocks. Plain redstone has no natural i/o streams so I just wasn't sure if we officially accepted such answers yet. \$\endgroup\$ Nov 16, 2015 at 17:36
  • 1
    \$\begingroup\$ Levers/buttons make easy bitwise input. I'd say redstone lamps are good bitwise output. \$\endgroup\$
    – mbomb007
    Nov 16, 2015 at 17:37
1
\$\begingroup\$

Byte size based on per block diskspace

In an earlier version (1.2), minecraft began getting a lot more blocks than before. This made the developers rewrite the code and use a short instead of a byte (I say this from experience), thus increasing a block's size to 2 bytes in memory. The disk space however is different from this. Minecraft blocks can only have 4096 different ids, thus making them take up 12 bit (1.5 bytes) each.

This format is the so called anvil file format.

Reference: http://minecraft.gamepedia.com/Anvil_file_format

The text in the command blocks remained the same, a character can take up a byte, as in "normal" languages.

\$\endgroup\$
3
  • \$\begingroup\$ Only the programming-related blocks are important for most programs, so we can score differently. \$\endgroup\$
    – mbomb007
    May 17, 2016 at 21:28
  • \$\begingroup\$ @mbomb007 redstone timers are built of blocks for example \$\endgroup\$
    – Bálint
    May 18, 2016 at 9:02
  • \$\begingroup\$ But you usually only need a single type of non-functional block. Like only using dirt for necessary blocks. Even so, according to the wiki, the added 4 bits are not even used yet. The maximum Block ID has been increased to 4096 (was 256) by adding a 4 bit data layer (similar to how meta data is stored). The rest of Minecraft's code is not currently prepared to take advantage of this, however. \$\endgroup\$
    – mbomb007
    May 18, 2016 at 16:27
1
\$\begingroup\$

In light of new updates, I figured sizing of MC programs could be reconsidered.

These only apply to the new features and the other answers that address command blocks, entities, etc should be included in the total byte total. However, most code golf may just be solved using just these new features and no blocks (the use of the player is arguably irrelevant)

1.12

1.12 introduced function files that hold commands like a text file. Commands are listed line by line. Unlike command blocks and redstone, these require no in game blocks and only mcfunction files.

These function files are stored in the data directory.

.minecraft
|- saves
   |- 'worldname'
      |- data
         |- functions
            |- 'namespace'
                |- func-name.mcfunction

These files can be run with the following command in game:

/function [func-file]

Ex: With function file, test in namespace test

/function test:test will run the function

(there is an alternative method: /gamerule gameLoopFunction [func-file] but this is obviously longer. This will, however, loop the code if it is necessary. More on this later.)

There are two things to keep note of:

  • Functions can call other functions inside of them and therefore should be counted as multiple files are.

  • Functions can call themselves. This is recursion and is the only way to execute commands in a loop in one tick in game.

At this point, we can use the normal method of calculating bytes through the function file's byte count.

Then we should add the bytes of the line to call the function in game.

Total Bytes = Bytes of files + Bytes of ingame function call

Extra:

It should be noted that in Minecraft, the namespace minecraft is automatically added if not defined. Therefore, you can save the maximum amount of bytes by using a single letter function name stored in a minecraft namespace.

i.e. `/function a` for `a.mcfunction` in the `minecraft` namespace

Looping in mc can be done via: gameLoopFunction and recursion

  • gameLoopFunction is done via the gamerule command (/gamerule gameLoopFunction.). This will loop the function every tick (minecraft divides ingame stuff in ticks. 20 ticks = 1 seconds (mostly))
  • recursion is done when a function calls itself (as you would). This happens within a tick.

Do keep this in mind when designing your solutions for the lowest amount of bytes.

1.13 (currently in snapshots)

In 1.13 (the dev. versions of Minecraft reveal what 1.13 will be), datapacks have replaced the system for functions. Datapacks can be zipped and still function within the game.

A new addition to 1.13 removes the gameLoopFunction gamerule in favor of function tags. A JSON file can be included at `worldname/datapacks/[datapack-name]/data/[namespace]/tags/functions/[file-name].

If the JSON file is named tick.json and is located under the minecraft namespace, all functions listed as a value will be called every tick (like the old gamerule).

These bytes should be included in the total calculation. NOTE: it should be known that calling the function w/o adding the function to the #minecraft:tick tag is completely fine.

The bytes of a valid, zipped datapack should be added with the following lines:

/datapack enable [file-name] and /function [file-name] if function is not added to the tick tag.

** Total Bytes = Bytes of zipped datapack + bytes of following ingame commands **

Answer will be updated in light of new changes

\$\endgroup\$
-2
\$\begingroup\$

Relevant blocks. These are

  • Any Redstone component
  • Any component relevant to the structure (blocks holding up redstone, doesn't include the floor)
  • Any block that would remove functionality if changed (air blocks that remove functonality when filled, "normal" blocks that remove functionality when removed)

Command blocks are 1+inner code size

Filled blocks (chest, dropper) are 1+amount of stacks inside (where a filled slot is 1, size of stack irrelevant)

Exception to the above rule: items that need nbt data (a pick that MUST be damaged for the structure to work): 2 bytes

But: Redstone can't be compared to other (textual) languages

\$\endgroup\$
-4
\$\begingroup\$

Redstone-Related Items Placed (bytes)

Typical Redstone Items Placed (found in the Redstone section of the Creative Menu)

I would count these as 1 byte each.

Comparator-Responsive Items Placed

I would count these as two bytes. Hoppers can output with a comparator from 0 to 15 redstone length in output. Similarly, the use of item frames to hold information or any other storage item should be counted as two bytes.

Filler Blocks Placed

Dirt or the like, as long as it isn't used for redstone transmission, should not be counted. If they are used for redstone transmission (passing power through a block with a torch/repeater/comparator), it should count as a byte.

Command Blocks

Command blocks should be counted as three bytes in version 1.9 but one byte in all other versions, as command blocks have 12 "states" in version 1.9. The text inside should count byte-for-byte there as well.

Entities

Entities would be tricky to count. If there were a definite restriction from the several hundred variations of several hundred entities one could have in the game, this would be easy to score. However, since that would be improbable, I would consider @Cᴏɴᴏʀ O'Bʀɪᴇɴ's solution to this with two bytes.

Dummy Players

These should remain uncounted, except for the command block source that generates them.

\$\endgroup\$
8
  • 2
    \$\begingroup\$ @mbomb007 Couldn't you just use the MC demo? \$\endgroup\$ Nov 3, 2015 at 18:22
  • \$\begingroup\$ @mbomb007 You could use MCEdit to change it to creative or load a .schematic into the demo world. \$\endgroup\$ Nov 3, 2015 at 21:18
  • \$\begingroup\$ @mbomb007 You can start a LAN world in the Demo? Huh. \$\endgroup\$ Nov 3, 2015 at 22:53
  • \$\begingroup\$ I would have suggested the LAN trick but I assumed that wouldn't let you. \$\endgroup\$ Nov 3, 2015 at 22:53
  • 1
    \$\begingroup\$ I think this is leaving out an important factor in redstone circuits. Sometimes there are air blocks that have to be air blocks and not solid blocks or else the circuit won't run correctly. I propose also counting those required air blocks along with the other blocks. \$\endgroup\$
    – DanTheMan
    Nov 4, 2015 at 22:44
  • \$\begingroup\$ Bytes are not a subjective measure. You should make an actual encoding and decoder program, that when given a string, outputs in some form the exact placement of blocks needed. You might propose to score the answers on something other than bytes, but then they should not be called "bytes". \$\endgroup\$
    – feersum
    Nov 6, 2015 at 9:05
  • \$\begingroup\$ @feersum I disagree that an encoding/decoding program should be used. Think of the list of items and blocks similar to a code page. \$\endgroup\$
    – mbomb007
    Apr 28, 2016 at 17:06
  • \$\begingroup\$ if you're gong to re-code it call it min instead of minecraft, like pyth is a limited vrsion of python \$\endgroup\$
    – Jasen
    Jan 7, 2017 at 12:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .