User:Eagleon

From Space Station 13 Wiki
Revision as of 04:20, 26 February 2015 by Eagleon (talk | contribs) (prototype of chemcompiler tutorial with shittastic formatting)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Working, here, on a guide for the chemcompiler that's better than just dumping terms from two seperate programming language into a list and expecting people to know what the hell you're talking about.


Guide to Making Chemcompiler Programs/Reactions

The Chemcompiler seems arcane, and almost useless at first glance. But imagine a cocktail like this:


25 Fluorosulfuric acid, 24 Phlogiston, 24 Dark Matter, 12 Smoke Powder, 12 Fluorosurfactant, 3 Plasma


It's a bomb, it's a face-eater, it's a fireball. It's everything, and it will kill you dead in seconds with a drop - I know, I've tested it on myself after testing it on monkeys.

Using the chemcompiler, I will show you how to systematically create the beginnings of this mixture (or blow you to hell, if you didn't load the beakers right), and hopefully give you some idea what the hell it's about. If you use this guide, a fair payment would be giving me all your programs/plans so that I can murder myself more effectively.

Initial steps and planning

In order to make a coherent ChemCompiler program, you first need to have a plan for every step of your reaction. A lot can go wrong. But if you follow things through systematically, you might be ok.

Let's do something simple: Sulfuric acid into Fluorosulphuric Acid. It's sulfuric acid, fluorine, hydrogen, and potassium in equal quantities. It also needs to be heated up to 374 degrees. Sulfuric needs sulfur, oxygen, and hydrogen. Obviously we need to make that first. Also, when working with the chemcompiler, you need to respect the amount available to you in each beaker as well as (and this is my approach, not necessarily the best one) the amount of room left in the final output beaker. So we document all of that to ensure a clean reaction and help with testing later.

I start it like this:


Sulfur 50/50 Oxygen 50/50 Hydrogen 50/50 (2x) Fluorine 50/50 Potassium 50/50 Mixdown 0/100


Note that I marked what is used twice in the reaction - you should do this so that you know, later, which ones are best to double up a beaker with, because you only have 10 slots, and for complicated reaction chains you run dry fast.

Let's say we want that final mixdown beaker to be full of fluorosulphuric acid in the end. We know that we need four components to make it, so we'll need 1/4 of it full of sulfuric. But sulfuric has 3 components! That's 8.33 repeating. No good. What we can do instead is make more than what we need, and put it into a buffer mix. That's not a great solution for more complex reactions, but it's worth remembering as a fix, because residual chemicals suck. The buffer can be emptied at any time in the ChemCompiler using a few simple operations.

Our new setup looks like this


Sulfur 50/50 Oxygen 50/50 Hydrogen 50/50 (2x) Fluorine 50/50 Potassium 50/50 Buffer 0/50 Mixdown 0/100


So now we know we need: 9 sulfur 9 oxygen 9 hydrogen Into buffer works out to 27, so 25 into mixdown


We want to keep track of these changes, because running out of something is potentially dangerous


Sulfur 41/50 Oxygen 41/50 Hydrogen 41/50 (2x) Fluorine 50/50 Potassium 50/50 Buffer 2/50 (sulfuric acid) Mixdown 25/100 (sulfuric acid)


Now we move on to the final mix. We already have the sulfuric acid ready, so we need


25 fluorine 25 hydrogen 25 potassium


Sulfur 41/50 Oxygen 41/50 Hydrogen 16/50 (2x) Fluorine 25/50 Potassium 25/50 Buffer 2/50 (sulfuric acid) Mixdown 100/100 (25 sulfuric acid, 25 fluorine, 25 hydrogen, 25 potassium)


Now we need to document the heating needed to change the precursors into our final form.


Heat Mixdown to 374


Sulfur 41/50 Oxygen 41/50 Hydrogen 16/50 (2x) Fluorine 25/50 Potassium 25/50 Buffer 2/50 (sulfuric acid) Mixdown 100/100 (100 Fluorosulphuric acid!)


Success! It may seem overly redundant to lay it out like this, but we can use it to make our ChemFuck program quickly and easily now, and the real fun begins.

Introduction to ChemFuck

Everything in Brainfuck/the ChemCompiler is about manipulating the Pointer. Think about the Pointer like a mouse that can go left or right. It's always hovering over a number (it begins at the very first one available), and those numbers have their own locations in memory (references) So initially it looks like this


 v

00x000 01x000 02x000 03x000 ... FFx000


The first two numbers are the Reference. The last three, after the x, are the Value. We can do two things with the pointer - we can shift the Reference left (<) or right (>). We can add 1 to the value (+) or subtract (-).

Already we know how to do something useful. Say we wanted the numbers 1 through 10 stored in memory. This would be the program to write it


+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++


So stepping through, it first adds 1 to the first (always 00) reference


+

 v

00x001 01x000 02x000 03x000 04x000 05x000 06x000 07x000 08x000 09x000


Then it moves the pointer over 1 (>)


+>

 ------>v

00x001 01x000 02x000 03x000 04x000 05x000 06x000 07x000 08x000 09x000


Then it adds 1 to that reference twice


+>++

        v

00x001 01x002 02x000 03x000 04x000 05x000 06x000 07x000 08x000 09x000


And so forth, ending on reference 09 incrementing its value to 10


+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++

                                                                v

00x001 01x002 02x003 03x004 04x005 05x006 06x007 07x008 08x009 09x010


Because there is no multiplication or direct entry of numbers in Brainfuck, it's helpful to copy/paste +/- signs in known quantities if you need to reach larger numbers. And yes, chemfuck programs really are just long strings of symbols.

Here's all of them at once to confuse you!

Commands

Basic pointer manipulation and arithmetic

  *  > Increment the reference position
  *  < Decrement the reference position
  *  + Increment the value of the reference under the pointer
  *  - Decrement the value of the reference under the pointer

While loops

  *  [ Start a While loop (returns to this spot when it hits ], and goes off to ] if the reference value under the pointer at that time is 0
  *  ] Same as above, but exactly backwards. Yes, backwards. As in the program reverses itself, until it hits a [, and then it returns and does its check. What. (if you think about it carefully, this doesn't infinite-loop either type of while loop, so why not?)

Register operations:

  *  { Set the Source register (number) to the value of the current reference under the pointer. The Source register (sx on the chemcompiler screen) is typically whatever beaker you're taking chemicals from next.
  *  } Set the Source register (number) to the current reference position
  *  ( Same as {, but for the Target register. The Target register (tx) you might have guessed is where a chemical will go if it's moved during the current step of the program, for instance.
  *  ) Same as }, but for the Target register
  *  ^ Same as ( or {, but for the Amount register. Amount (ax) is used for both the amount of chemicals to be moved, and Temperature values.
  *  ' } or ), but for Amount.

You get the idea, hopefully. There's two for each of these.

Other operations:

  *  $ Heat or cool reagent in sx to ((273 - tx) + ax) Kelvin. According to the original wiki entry at least. TODO more testing needed.
  *  @ Transfer ax units of reagent from reservoir sx to target tx.
  *  ~ "Compile" the code, so it cannot be retrieved again via the load button.


Getting Started

So now that I've thoroughly confused you, we can move on to making our first reaction in the chemcompiler. Isn't that exciting? Are you bored yet? Fuck you. This took a long time to write, you better stick with me you brat.

We'll start with the setup


1 Sulfur 50/50 2 Oxygen 50/50 3 Hydrogen 50/50 (2x) 4 Fluorine 50/50 5 Potassium 50/50 9 Buffer 0/50 10 Mixdown 0/100


Notice the numbers before each. These are the registers we're using. They're the numbered buttons in the chemcompiler menu. You load the beakers into the compiler by putting one into your hand and clicking the corresponding button - tne beaker should disappear and the button should light up. Click the button again to retrieve into an empty hand.

You should start by loading this mix into the compiler. Every single one, yes. Don't leave any out.

To begin with, it's really useful to load a bunch of values into the program that represent our registers, and just common numbers that we'll use constantly, so let's do that.


+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++>+++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++++


That last two is 25 and 50. They're there so that we can handle the buffer step smoothly.

We'll take the section of our plan and add to it directly. In your plan you can just edit it rather than make a giant wiki page to show your work like I did.


9 sulfur(R1 9 oxygen(R2 9 hydrogen(R3 Into buffer works out to 27, so 25 into mixdown


Right now we're at reference 12. We can visualize it as something like this


11x050


There's two things we want to do now. We want to set tx to 9, or Buffer. We want to set sx to 1, or Sulfur. And we want to set ax to 9. Since we're there already, we can do ax and tx simultaneously. So we move the pointer


<<<


And set both ax and tx


(^


I like to annotate the plan directly with these short sections of code as they fall out naturally


+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++>+++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++++

               9         1

9 sulfur(R1 <<<(^<<<<<<<<{ sx 1, tx 9, ax 9 9 oxygen(R2 9 hydrogen(R3 Into buffer works out to 27, so 25 into mixdown


So now we can finally do something! We move 9 units of sulfur to register 9, or the buffer beaker you put into place. You did put it into place, right? Compositing all of the code so far together, you get


+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++>+++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++++<<<(^<<<<<<<<{@


You can drop this into the compiler and test it out if you like. Hit Save, click 1 (in 1-6), and click 1 again. The compiler should beep a few times, and the sulfur should be moved. It pays off long-run to test these steps as you go, since things may not mix exactly as you expect, you may make typos, you can count wrong, etc. Science! Face melting!

By now, it should be pretty obvious what to do next, but I'll walk through it just in case.


+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++>+++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++++

               9         1

9 sulfur(R1 <<<(^<<<<<<<<{@ sx 1, tx 9, ax 9 9 oxygen(R2 >{@ sx 2 9 hydrogen(R3 >{@ sx 3 Into buffer(R9 works out to 27, so 25 into mixdown(R10 >>>>>>{>(>^@ sx 9, tx 10, ax 25


And just like that:


+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++>+++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++++<<<(^<<<<<<<<{@>{@>{@


You now have a program to mix sulfuric acid. Only with this setup, granted (sulfur in 1, oxygen in 2, hydrogen in 3, and empty in 9 and 10) but it'll work. Hopefully. I didn't test it. This is a WIP.

Taking the rest of the plan:


+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++>+++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++++<<<(^<<<<<<<<{@>{@>{@ sx = 9, tx = 10, ax = 25


25 potassium <<<<<<{@ sx 5 25 fluorine <{@ sx 4 25 hydrogen <{@ sx 3 (I rearranged these so that there would be fewer back and forth movements of the pointer.)


+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++>+++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++++<<<(^<<<<<<<<{@>{@>{@<<<<<<{@<{@<{@ sx = 3, tx = 10, ax = 25


So now comes heating. It's a little strange, because it's based off of 274k to keep you from having to use too many hundreds of +'s or -'s to get the right value. It also, counterintuitively, heats the Source register sx. It also subtracts tx from 273 (for reasons?) and then adds ax. So first, we're setting sx to 10 (the mixdown), setting tx to 0 (we already have this, we just need to go to the next uninitialized reference) and setting ax to 101! Then we use the heat operation, $


>>>>>>>{>>>(>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++^$ sx = 10, tx = 0, ax = 374


Our glorious finished program, giving 100 fluorosulphuric acid from raw reagents, with only a modest amount of clicking.


+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++>+++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++++<<<(^<<<<<<<<{@>{@>{@<<<<<<{@<{@<{@>>>>>>>{>>>(>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++^$


For fun reference purposes, the final memory footprint of our program looks like this:


00x001 01x002 02x003 03x004 04x005 05x006 06x007 07x008 08x009 09x010 10x025 11x050 12x000 13x374


We didn't end up using 50 anywhere in our program, but it doesn't hurt to include a bit of redundancy.

Homework/Addendum

Setting tx to 11, 12, and 13 makes pills, vials, and disposes of reagents accordingly, when using the transfer (@) operation. If you're still not comfortable with the idea of making a plan like this of your own, try making an addition to the program to get rid of the remnant sulfuric acid in register 9, or make the compiler spit out acid pills, etc.

The while operators can create looping patterns in your program to do repetitive things without so much typing. But it's brainfuck. Most programs are like two lines long anyway. It's something to keep in the back of your mind while making your own programs/plans.

Nothing here has been tested yet. Use at your own risk. If anyone has some corrections or modifications to make, we can talk. For now, signing off.