~ Based on VNA/VNA2/VNA3, but you don't need to know anything about those. This is entirely redesigned and simplified ~
Download the VNA.4 emulator, written in HTML/Javascript that runs fine on Firefox 2.0.0.14, Firefox 3.5.1, Safari 1.3 (v312), and Chrome 2.0.172.37 (and 2.0.172.39). It appears to not be working in Internet Explorer whatsoever.
For some reason I can't get the html file to upload... the solution I guess is to post the code verbatim:
<html>
<head>
<title>VNA.4 Emulator, by unreality</title>
<script LANGUAGE="JavaScript">
/* global declarations */
var vna = new Array();
var alphastring = "abcdefghijklmnopqrstuvwxyz";
var capalphastring = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var p1vararray = new Array(26);
var p2vararray = new Array(26);
/* functions */
function doSwitch()
{
getp1 = document.form1.p1.value;
getp2 = document.form1.p2.value;
document.form1.p1.value = getp2;
document.form1.p2.value = getp1;
}
function doClear()
{
document.form1.p1.value = null;
document.form1.p2.value = null;
}
function doRandomStart()
{
document.form1.startline.value = Math.floor(117*Math.random())+42
}
function loadArray()
{
var pr1 = new Array();
var pr2 = new Array();
pr1 = document.form1.p1.value.split("\n");
pr2 = document.form1.p2.value.split("\n");
var nStart = document.form1.startline.value;
var error1="";
var error2="";
var error3="";
if (pr1.length > 40) error1 = "Program 1 is too long! ";
if (pr2.length > 40) error2 = "Program 2 is too long! ";
if (nStart=="") error3 = "You must specify a starting node for P2!";
error3 = error1 + error2 + error3;
if (error3 != ""){alert(error3); return;}
var iString;
var cString = document.form1.fillwith.value;
for (i=0;i<200;i++)
{
iString = cString;
if (i<pr1.length) {iString = pr1[i];}
if (i>=nStart && i<nStart+pr2.length) {iString = pr2[i - nStart];}
if (iString == undefined) iString = cString;
vna[i] = iString;
}
document.form1.vnarray.value = vna.join("\n");
document.form1.point1.value = 0;
document.form1.point2.value = nStart;
document.form1.rnds.value = 0;
document.form1.dornd.disabled = false;
document.form1.doxrnd.disabled = false;
document.form1.xrd.value = 10;
// fill variable arrays
for(i=0;i<26;i++)
{
p1vararray[i] = 0;
p2vararray[i] = 0;
}
document.form1.seevars.disabled = false;
}
function doRound()
{
// increment round counter
document.form1.rnds.value++;
// pointer locations
var lineOne = document.form1.point1.value*1;
var lineTwo = document.form1.point2.value*1;
// P1 first
var zline = vna[lineOne].toLowerCase();
// count the number of spaces in zline
var chratloopy = 0;
var numspaces = 0;
while (chratloopy < zline.length)
{
if (zline.charAt(chratloopy) == " ") numspaces++;
chratloopy++;
}
var newline;
var paramz = zline.split(" ");
var valqa = doFunc(paramz[0]+"",lineOne,1)*1;
if (numspaces > 0) var valqb = doFunc(paramz[1]+"",lineOne,1)*1;
if (numspaces > 1) var valqc = doFunc(paramz[2]+"",lineOne,1)*1;
if (numspaces > 2) var valqd = doFunc(paramz[3]+"",lineOne,1);
if (numspaces > 3) var valqe = doFunc(paramz[4]+"",lineOne,1);
if (valqd != "!") valqd *= 1;
if (valqe != "!") valqe *= 1;
switch (numspaces)
{
case 0:
if (zline == "x")
{
document.form1.dornd.disabled = true;
document.form1.doxrnd.disabled = true;
alert("Program 2 wins!");
return;
}
else
{
newline = doMod(lineOne + valqa);
}
break;
case 1:
var firstchar = zline.charAt(0);
p1vararray[alphastring.indexOf(firstchar)] = valqb;
newline = doMod(lineOne + 1);
break;
case 2:
var replacestring = vna[doMod(lineOne+valqa)];
// check for capital variables
var zzingl;
var dropfwhenzero = 1;
while (dropfwhenzero == 1)
{
zzingl = replacestring.length;
dropfwhenzero = 0;
for (i=0;i<zzingl;i++)
{
if (capalphastring.indexOf(replacestring.charAt(i)) != -1)
{
replacestring = replacestring.substring(0,i) + p1vararray[capalphastring.indexOf(replacestring.charAt(i))] + replacestring.substring(i+1);
dropfwhenzero = 1;
}
}
}
vna[doMod(lineOne+valqb)] = replacestring;
newline = doMod(lineOne + valqc);
break;
case 3:
var temptemptemp = vna[doMod(valqa + lineOne)];
vna[doMod(valqa + lineOne)] = vna[doMod(valqb + lineOne)];
vna[doMod(valqb + lineOne)] = temptemptemp;
if (vna[doMod(valqa + lineOne)] == vna[doMod(valqb + lineOne)])
{
newline = doMod(lineOne + valqc);
}
else
{
if (valqd != "!") newline = doMod(lineOne + valqd);
if (valqd == "!") newline = doMod(lineOne + valqc);
}
break;
case 4:
if (valqa == valqb) {newline = doMod(lineOne + valqc);}
if (valqa > valqb) {newline = doMod(lineOne + valqd);}
if (valqa < valqb && valqe == "!") {newline = doMod(lineOne + valqd);}
if (valqa < valqb && valqe != "!") {newline = doMod(lineOne + valqe);}
break;
}
//
//
// P2 now
//
//
var zline = vna[lineTwo].toLowerCase();
// count the number of spaces in zline
var chratloopy = 0;
var numspaces = 0;
while (chratloopy < zline.length)
{
if (zline.charAt(chratloopy) == " ") numspaces++;
chratloopy++;
}
var newxline;
paramz = zline.split(" ");
valqa = doFunc(paramz[0]+"",lineTwo,2)*1;
if (numspaces > 0) var valqb = doFunc(paramz[1]+"",lineTwo,1)*1;
if (numspaces > 1) var valqc = doFunc(paramz[2]+"",lineTwo,1)*1;
if (numspaces > 2) var valqd = doFunc(paramz[3]+"",lineTwo,1);
if (numspaces > 3) var valqe = doFunc(paramz[4]+"",lineTwo,1);
if (valqd != "!") valqd *= 1;
if (valqe != "!") valqe *= 1;
switch (numspaces)
{
case 0:
if (zline == "x")
{
document.form1.dornd.disabled = true;
document.form1.doxrnd.disabled = true;
alert("Program 1 wins!");
return;
}
else
{
newxline = doMod(lineTwo + valqa);
}
break;
case 1:
firstchar = zline.charAt(0);
p2vararray[alphastring.indexOf(firstchar)] = valqb;
newxline = doMod(lineTwo + 1);
break;
case 2:
vna[doMod(lineTwo+valqb)] = vna[doMod(lineTwo+valqa)];
newxline = doMod(valqc+lineTwo);
break;
case 3:
var temptemptemp = vna[doMod(valqa + lineTwo)];
vna[doMod(valqa + lineTwo)] = vna[doMod(valqb + lineTwo)];
vna[doMod(valqb + lineTwo)] = temptemptemp;
if (vna[doMod(valqa + lineTwo)] == vna[doMod(valqb + lineTwo)])
{
newxline = doMod(lineTwo + valqc);
}
else
{
if (valqd != "!") newxline = doMod(lineTwo + valqd);
if (valqd == "!") newxline = doMod(lineTwo + valqc);
}
break;
case 4:
if (valqa == valqb) {newxline = doMod(lineTwo + valqc);}
if (valqa > valqb) {newxline = doMod(lineTwo + valqd);}
if (valqa < valqb && valqe == "!") {newxline = doMod(lineTwo + valqd);}
if (valqa < valqb && valqe != "!") {newxline = doMod(lineTwo + valqe);}
break;
}
// render the VNA
document.form1.vnarray.value = vna.join("\n");
document.form1.point1.value = newline;
document.form1.point2.value = newxline;
}
function doMod(zeinput)
{
while (zeinput < 0)
{
zeinput += 200;
}
zeinput = zeinput % 200;
return zeinput;
}
function doFunc(param, qline, zpp)
{
if (param == "") return "";
if (param == "!") return "!";
if (alphastring.indexOf(param) != -1)
{
return doSuperFunc(param, zpp);
}
var tempeval;
var closeparen;
var funcin;
var beforeparstring;
var commaloc;
var parenloc;
var rightloc;
var funcname;
var inputarray = new Array();
/*var xdata = new Array();*/
// loop until param is just a number
while (param*1 != param)
{
closeparen = param.indexOf(")");
openparen = (param.substring(0,closeparen+1)).lastIndexOf("(");
funcin = param.substring(openparen+1,closeparen);
beforeparstring = param.substring(0,openparen);
commaloc = beforeparstring.lastIndexOf(",");
parenloc = beforeparstring.lastIndexOf("(");
rightloc = Math.max(commaloc,parenloc);
funcname = param.substring(rightloc+1,openparen);
funcname = funcname.toLowerCase();
//
/*alert(closeparen+" -- "+openparen+" -- "+commaloc+" -- "+parenloc+" -- "+rightloc+" -- "+zpp+qline);
alert("Name: "+funcname+", Input: "+funcin);*/
//
inputarray = funcin.split(",");
for (i=0;i<inputarray.length;i++)
{
inputarray[i] = doSuperFunc(inputarray[i],zpp);
}
switch (funcname)
{
case "sum":
case "add":
tempeval = 0;
for (i=0;i<inputarray.length;i++)
{
tempeval += inputarray[i];
}
break;
case "prd":
case "mul":
case "mult":
tempeval = 1;
for (i=0;i<inputarray.length;i++)
{
tempeval *= inputarray[i];
}
break;
case "inc":
case "incr":
tempeval = (inputarray[0] + 1);
break;
case "dec":
case "decr":
tempeval = (inputarray[0] - 1);
break;
case "neg":
tempeval = (inputarray[0] * -1);
break;
case "inv":
if (inputarray[0] == 0) {tempeval = 0} else {tempeval = 1 / inputarray[0];}
break;
case "num":
var linetoterm = vna[doMod(qline + inputarray[0])]+"";
tempeval = 1;
for (i=0;i<linetoterm.length;i++)
{
if (linetoterm.charAt(i) == " ") tempeval++;
}
if (linetoterm == "x") tempeval = 0;
break;
case "mod":
tempeval = (inputarray[0]*1) % (inputarray[1]*1);
break;
case "pow":
tempeval = Math.pow(inputarray[0],inputarray[1]);
break;
case "div":
tempeval = (inputarray[0]*1) / (inputarray[1]*1);
break;
case "sub":
tempeval = (inputarray[0]*1) - (inputarray[1]*1);
break;
case "log":
tempeval = Math.log(inputarray[1]*1) / Math.log(inputarray[0]*1);
break;
case "abs":
tempeval = Math.abs(inputarray[0]);
break;
case "int":
tempeval = Math.floor(inputarray[0]);
break;
}
// replace part of param with tempeval... then loop again
param = param.substring(0,rightloc+1) + tempeval + param.substring(closeparen+1);
}
return param;
}
function doSuperFunc(qwerty, zppp)
{
var qwertest = alphastring.indexOf(qwerty);
if (qwertest != -1)
{
if (zppp == 1) qwerty = p1vararray[qwertest];
if (zppp == 2) qwerty = p2vararray[qwertest];
}
else qwerty *= 1;
return qwerty;
}
function doXRounds()
{
var getx = document.form1.xrd.value;
for (i=0;i<getx;i++)
{
doRound();
}
}
function seeVars()
{
var ystr = "P1:\n";
for (i=0;i<26;i++)
{
if (p1vararray[i] != 0) ystr += alphastring.charAt(i)+" = "+p1vararray[i]+"\n";
}
ystr += "\nP2:\n";
for (i=0;i<26;i++)
{
if (p2vararray[i] != 0) ystr += alphastring.charAt(i)+" = "+p2vararray[i]+"\n";
}
alert(ystr);
}
/* end of script */
</script>
</head>
<body>
<h1>VNA.4 Emulator, by unreality</h1>
<br><br><br>P1 ..........................................................................................................P2<br><form name="form1">
<textarea name="p1" rows=10 cols=50></textarea> <textarea name="p2" rows=10 cols=50></textarea>
<br>
<center><input type="button" value="Switch" onClick="doSwitch();"><input type="button" value="Clear" onClick="doClear();"></center>
<br><br><br><br>
P1 starts at line 0 and goes first<br>
P2 starts at line X and goes second<br>
X: <input type="text" name="startline" length="10"> <input type="button" value="Random" onClick="doRandomStart();">
<br>(range 42 to 158 please)
<br><br><br><br><center>Fill with: <input type="text" name="fillwith" length="10" value="x"></center><br><input type="button" value="Load the Virtual Node Array!" onClick="loadArray();"><br><hr><br>
VNA:<br><textarea name="vnarray" rows=30 cols=60></textarea><br>
P1 Pointer: <input type="text" name="point1" length="10"><br>
P2 Pointer: <input type="text" name="point2" length="10"><center>
<input type="button" value="Do 1 Round" name = "dornd" onClick="doRound();"> <input type="button" value="Do X Rounds" name="doxrnd" onClick="doXRounds();"> X:<input type="text" name="xrd" length="10"></center><br>
Rounds: <input type="text" name="rnds" length="10"><input type="button" value="See Nonzero Variables" name="seevars" onClick="seeVars();" disabled="true">
</form>
</body>
</html>
Just select all of the above code and copy it, pasting it into a simple text file. Then save the text file as "vna4.html". To run the emulator, just drag the text file onto your browser (for a Mac) or double-click the text file and it will open in your default browser (for Mac or PC) or right-click and select "Open with..." (for a Mac or PC) and then select the browser you want to open it in. Sorry for the inconvenience, I'll try to find out why I can't upload it...
Imagine a world where your senses fail you. There is no sound, no smells. There's nothing to taste and nothing to feel. All you can see is an indecipherable infinite hierarchy of data, echoless chambers of information, architectures of code. This cyberscape is constantly changing with iteration by iteration, programs and viruses and shells warring for memory space and processing power. This is the inside of your computer.
But now, an arena has been set aside... two programs, two warriors, shall duke it out in the Virtual Node Array... the VNA is a linear, circular memory core with 200 "nodes", or lines. You can keep going in any direction forever because of the VNA's circular disposition. Each node in the VNA has some code, mostly numbers with some letters and short words, written in terms and separated by spaces. Short, simple code. I will explain shortly how to design your program, but first, the setup system...
In the beginning,the VNA is empty, constituting either all x's (bombs) or 1's (the command to jump to the next line) or some other simple preset filler. Then, the two warring programs are placed into the VNA, spaced out enough to give each other room.
For example, say this is your program:
a sum(a,3)
1 a -1
Then the VNA, which previously looked like this:
x
x
x
x
x
x
x
x
...etc
will now look like this:
x
x
x
x
a sum(a,3)
1 a -1
x
x
...etc
and your program's "pointer" will be placed at the first line of your program, the ""a sum(a,3)"" line.
When the game begins, P1 (Program/Player 1) will go first, then P2, then P1, etc, in alteration. A single "round" is after both P1 and P2 have gone. The VNA updates after one program executes one line of code (so it updates twice each round).
When a program executes a line of code, it does something, and then "jumps" the pointer to a new line. Lines are always referred to relative to the current line of interest; there is no absolute line numbering. So line 1 is always the next line. Line 0 is always the current line. Line -3 is always the line three behind you. Line 200 is the same thing as line 0, line 201 = line 1 = line 401 = line 601, line 197 = line -3, etc, since the VNA wraps around in a circular pattern.
What the program does is determined by the line of code it executes. There are six "structures" which determine how the program evaluates a line of code.
(0) BOMB structure: x
*** the BOMB structure is always the single letter 'x'. If a program executes a BOMB structure, it will be terminated and the enemy will win. You can handle BOMB structures and move them around, copy them, etc, and as long as you don't execute one, you're fine...
(1) JUMP structure: a
*** this does nothing except jump the pointer to line 'a'
(2) SET structure: a b
*** this sets the variable 'a' to the value 'b', then jumps forward 1 line. You have 26 variables, a-z, and your opponent has 26 variables, a-z. Your variables and your opponent's variables never interact. More on variables in a second
(3) COPY structure: a b c
*** copy the contents of line 'a' into line 'b', overriding what was previously on line 'b'. Then jump the pointer to line 'c'
(4) SWITCH structure: a b c d
*** switch the two lines, 'a' and 'b', then jump to line 'c' if 'a' and 'b' were equal. If 'a' and 'b' are not the same, jump to line 'd'
(5) IF structure: a b c d e
*** compare two quantities, 'a' and 'b'. If a=b, jump to line 'c'. If a>b, jump to line 'd'. If a<b, jump to line 'e'
That's it. With this simple system, many good programs can be written concisely, without many lines. For example, I call this the Hopper:
0 137 137
it copies itself 137 nodes forward, then jumps to this copied line for the next round... so each iteration, it jumps 137 nodes forward in the VNA. However, the Hopper's main drawback (other than that it has no offensive capabilities) is that the enemy can get accidentally overwritten by the Hopper and become a hopper as well, hopping for eternity, neither program winning. This is made unlikely by adding one more term to the program:
0 137 137 137
this new-and-improved Hopper is now based on the SWITCH structure. It switches itself with the node 137 lines ahead and then jumps there (regardless of what the other line is). This means that it doesn't leave behind a "hopper trail" that the enemy can get caught up in.
But the Hopper is an offensively weak program; it takes no self-initiative to attack the enemy. It just jumps around, trying to avoid destruction and hoping the enemy destroys itself. So let's make a new program that rains BOMBs (the letter x) down over the VNA, attempting to hit the enemy's code We'll call this program 'Bomber'. If the enemy pointer executes a line of code that is a BOMB, the enemy's program will terminate, and the Bomber will win, so the goal is to spread bombs around the VNA...
3 sum(a,20) 1
a sum(a,3)
-2
x
what does it do? The first node copies line +3 (the BOMB) to the line denoted by the variable 'a' plus 20 [the function sum(1,2,3,4,...) adds everything inside] and then jumps forward 1 line.
The next line assigns, to the value a, the quantity a plus 3. In other words, it increments 'a' by 3. The next line jumps backwards 2, and the cycle starts all over again, bombing a spot three nodes later each time.
But wait! It is considered inefficient to have more "active lines" (lines that are actually being executed by the program) than you should, for two reasons: (1) The more lines the program is executing, the more susceptible it is to bombing. (2) It takes you longer to do the same task.
So how can we shorten it? By switching the order of the lines and using the COPY structure's built-in jump to go back to the start. This new-and-improved Bomber does exactly the same thing as the old one, but more efficiently:
a sum(a,3)
1 sum(a,16) -1
x
The only function you've seen is the sum() function, and you've only seen it operate on two parameters. But sum() can have any number of entries, and can be substituted with add(), which is the same [just preference which you use].
ie,
sum(a,b,c,d) = add(a,b,c,d)
What other functions are there?
* mul(), mult() and prd() are all the same, and they multiply everything inside. For example, mul(5,2,3) = 30.
* the inc(n) or incr(n) functions will output n+1
* the dec(n) or decr(n) functions will output n-1
* the neg(n) function will output n * -1, ie, negative n
* the inv(n) function will output 1/n, ie, the reciprocal of n
* the mod(n,m) function will output n%m, ie, n modulo m, ie, the remainder when n is divided by m
* the pow(n,m) function will output n^m, ie, n raised to the power of m
* the div(n,m) function will output n/m, ie, n divided by m
* the sub(n,m) function will output n-m, ie, n minus m
* the log(n,m) function will output the logarithm base-n of m
* the abs(n) function will output the absolute value of n
* the int(n) function will output the integer base of n, ie, it will truncate/floor n to the greatest integer less than or equal to n
* the num(n) function will output the number of terms in the line 'n' (relative to the current line of course). num(n) will return 0 if 'n' is a BOMB, 1 for JUMP, 2 for SET, 3 for COPY, 4 for SWITCH, and 5 for IF
You can nest functions within functions and pass variables as parameters to functions. For example:
sum(5,mul(3,mod(8,3)),inv(neg(-.2)),a,inc(inc( )
will output 5 + 3*(8%3) + 1/-(-.2) + a + (b+2) = 5 + 3*2 + 5 + a + b + 2 = a+b+18
ADDITIONAL THINGS
~~~~
What if you want to do a SWITCH structure but the line you jump to after that will be the same no matter what, regardless of whether the switched lines are equal? The answer is simple: in the setup 1 2 3 4, just make the 4th term the exact same as the 3rd term. But what if the term is long and complex or something? Just put a "!" exclamation point for the fourth term, ie:
1 2 3 !
This has no practical effect, it's just a preference thing. For SWITCH, it must be placed in the fourth term, and it just means that the 3rd term is the line that is jumped to, no matter what.
The exclamation point is also usable in the IF structure. If you're using the IF structure a b c d e as a=b or a≠b and thus your fourth term is the same as your fifth term, put an exclamation point for the fifth term:
1 2 3 4 !
This means that, if 1=2, jump to 3. Otherwise, jump to 4. Again, the exclamation point just a convenience thing.
~~~~
What if you want to jump to variable 'x'?
First of all, why use 'x' as a variable? There are plenty of others. But if you're using x for whatever reason, and you want to jump to the line denoted by the number 'x' is representing, you can't just do this:
x
since that's a bomb. However, you can just do:
0 0 x
which is the same thing.
~~~~
When a line is copied by a COPY structure, it is copied verbatim. ie:
1 2 100
7 9 add(a,2)
when run, that will copy the second line EXACTLY AS IT IS. Ie, after the first line is ran, the program will look like this:
1 2 100
7 9 add(a,2)
7 9 add(a,2)
But if you want to make it so that a variable is evaluated before being copied, use a CAPITAL letter. Take this program:
1 2 100
7 9 add(A,2)
say that the variable 'a' had a value of 3 at the time. Then after the first line runs, the program looks like this:
1 2 100
7 9 add(A,2)
7 9 add(3,2)
A capital letter variable has no difference from a lower-case variable when the line is being executed, the only difference from lowercaseness is when the line is being copied... when a line is copied, all of its variables stay variables, unless they are capitalized, in which case they are evaluated then and there for the new line.
By the way, a lone capital X is the same thing as a lower case 'x', ie, a bomb, except that if you copy this X, the result will be a number equal to whatever value your variable 'x' has. This makes 'x' a unique variable in that respect.
So... two programs. One array. 200 nodes... and only one victor. Post your ideas, your programs, declare duels... I've only written two more programs that I haven't posted here, called "Hopping Bomber" (or "Bombing Hopper", not sure which one sounds better ;D) and "Tracker", so you reading this can probably do better than what I've got so far The emulator is for download at the top of this post. Have at it, test your programs. If you have any questions, feel free to post here!
Question
unreality
VNA.4
~ Based on VNA/VNA2/VNA3, but you don't need to know anything about those. This is entirely redesigned and simplified ~
Download the VNA.4 emulator, written in HTML/Javascript that runs fine on Firefox 2.0.0.14, Firefox 3.5.1, Safari 1.3 (v312), and Chrome 2.0.172.37 (and 2.0.172.39). It appears to not be working in Internet Explorer whatsoever.
Just select all of the above code and copy it, pasting it into a simple text file. Then save the text file as "vna4.html". To run the emulator, just drag the text file onto your browser (for a Mac) or double-click the text file and it will open in your default browser (for Mac or PC) or right-click and select "Open with..." (for a Mac or PC) and then select the browser you want to open it in. Sorry for the inconvenience, I'll try to find out why I can't upload it...
Imagine a world where your senses fail you. There is no sound, no smells. There's nothing to taste and nothing to feel. All you can see is an indecipherable infinite hierarchy of data, echoless chambers of information, architectures of code. This cyberscape is constantly changing with iteration by iteration, programs and viruses and shells warring for memory space and processing power. This is the inside of your computer.
But now, an arena has been set aside... two programs, two warriors, shall duke it out in the Virtual Node Array... the VNA is a linear, circular memory core with 200 "nodes", or lines. You can keep going in any direction forever because of the VNA's circular disposition. Each node in the VNA has some code, mostly numbers with some letters and short words, written in terms and separated by spaces. Short, simple code. I will explain shortly how to design your program, but first, the setup system...
In the beginning,the VNA is empty, constituting either all x's (bombs) or 1's (the command to jump to the next line) or some other simple preset filler. Then, the two warring programs are placed into the VNA, spaced out enough to give each other room.
For example, say this is your program:
a sum(a,3)
1 a -1
Then the VNA, which previously looked like this:
x
x
x
x
x
x
x
x
...etc
will now look like this:
x
x
x
x
a sum(a,3)
1 a -1
x
x
...etc
and your program's "pointer" will be placed at the first line of your program, the ""a sum(a,3)"" line.
When the game begins, P1 (Program/Player 1) will go first, then P2, then P1, etc, in alteration. A single "round" is after both P1 and P2 have gone. The VNA updates after one program executes one line of code (so it updates twice each round).
When a program executes a line of code, it does something, and then "jumps" the pointer to a new line. Lines are always referred to relative to the current line of interest; there is no absolute line numbering. So line 1 is always the next line. Line 0 is always the current line. Line -3 is always the line three behind you. Line 200 is the same thing as line 0, line 201 = line 1 = line 401 = line 601, line 197 = line -3, etc, since the VNA wraps around in a circular pattern.
What the program does is determined by the line of code it executes. There are six "structures" which determine how the program evaluates a line of code.
(0) BOMB structure: x
*** the BOMB structure is always the single letter 'x'. If a program executes a BOMB structure, it will be terminated and the enemy will win. You can handle BOMB structures and move them around, copy them, etc, and as long as you don't execute one, you're fine...
(1) JUMP structure: a
*** this does nothing except jump the pointer to line 'a'
(2) SET structure: a b
*** this sets the variable 'a' to the value 'b', then jumps forward 1 line. You have 26 variables, a-z, and your opponent has 26 variables, a-z. Your variables and your opponent's variables never interact. More on variables in a second
(3) COPY structure: a b c
*** copy the contents of line 'a' into line 'b', overriding what was previously on line 'b'. Then jump the pointer to line 'c'
(4) SWITCH structure: a b c d
*** switch the two lines, 'a' and 'b', then jump to line 'c' if 'a' and 'b' were equal. If 'a' and 'b' are not the same, jump to line 'd'
(5) IF structure: a b c d e
*** compare two quantities, 'a' and 'b'. If a=b, jump to line 'c'. If a>b, jump to line 'd'. If a<b, jump to line 'e'
That's it. With this simple system, many good programs can be written concisely, without many lines. For example, I call this the Hopper:
0 137 137
it copies itself 137 nodes forward, then jumps to this copied line for the next round... so each iteration, it jumps 137 nodes forward in the VNA. However, the Hopper's main drawback (other than that it has no offensive capabilities) is that the enemy can get accidentally overwritten by the Hopper and become a hopper as well, hopping for eternity, neither program winning. This is made unlikely by adding one more term to the program:
0 137 137 137
this new-and-improved Hopper is now based on the SWITCH structure. It switches itself with the node 137 lines ahead and then jumps there (regardless of what the other line is). This means that it doesn't leave behind a "hopper trail" that the enemy can get caught up in.
But the Hopper is an offensively weak program; it takes no self-initiative to attack the enemy. It just jumps around, trying to avoid destruction and hoping the enemy destroys itself. So let's make a new program that rains BOMBs (the letter x) down over the VNA, attempting to hit the enemy's code We'll call this program 'Bomber'. If the enemy pointer executes a line of code that is a BOMB, the enemy's program will terminate, and the Bomber will win, so the goal is to spread bombs around the VNA...
3 sum(a,20) 1
a sum(a,3)
-2
x
what does it do? The first node copies line +3 (the BOMB) to the line denoted by the variable 'a' plus 20 [the function sum(1,2,3,4,...) adds everything inside] and then jumps forward 1 line.
The next line assigns, to the value a, the quantity a plus 3. In other words, it increments 'a' by 3. The next line jumps backwards 2, and the cycle starts all over again, bombing a spot three nodes later each time.
But wait! It is considered inefficient to have more "active lines" (lines that are actually being executed by the program) than you should, for two reasons: (1) The more lines the program is executing, the more susceptible it is to bombing. (2) It takes you longer to do the same task.
So how can we shorten it? By switching the order of the lines and using the COPY structure's built-in jump to go back to the start. This new-and-improved Bomber does exactly the same thing as the old one, but more efficiently:
a sum(a,3)
1 sum(a,16) -1
x
The only function you've seen is the sum() function, and you've only seen it operate on two parameters. But sum() can have any number of entries, and can be substituted with add(), which is the same [just preference which you use].
ie,
sum(a,b,c,d) = add(a,b,c,d)
What other functions are there?
* mul(), mult() and prd() are all the same, and they multiply everything inside. For example, mul(5,2,3) = 30.
* the inc(n) or incr(n) functions will output n+1
* the dec(n) or decr(n) functions will output n-1
* the neg(n) function will output n * -1, ie, negative n
* the inv(n) function will output 1/n, ie, the reciprocal of n
* the mod(n,m) function will output n%m, ie, n modulo m, ie, the remainder when n is divided by m
* the pow(n,m) function will output n^m, ie, n raised to the power of m
* the div(n,m) function will output n/m, ie, n divided by m
* the sub(n,m) function will output n-m, ie, n minus m
* the log(n,m) function will output the logarithm base-n of m
* the abs(n) function will output the absolute value of n
* the int(n) function will output the integer base of n, ie, it will truncate/floor n to the greatest integer less than or equal to n
* the num(n) function will output the number of terms in the line 'n' (relative to the current line of course). num(n) will return 0 if 'n' is a BOMB, 1 for JUMP, 2 for SET, 3 for COPY, 4 for SWITCH, and 5 for IF
You can nest functions within functions and pass variables as parameters to functions. For example:
sum(5,mul(3,mod(8,3)),inv(neg(-.2)),a,inc(inc( )
will output 5 + 3*(8%3) + 1/-(-.2) + a + (b+2) = 5 + 3*2 + 5 + a + b + 2 = a+b+18
ADDITIONAL THINGS
~~~~
What if you want to do a SWITCH structure but the line you jump to after that will be the same no matter what, regardless of whether the switched lines are equal? The answer is simple: in the setup 1 2 3 4, just make the 4th term the exact same as the 3rd term. But what if the term is long and complex or something? Just put a "!" exclamation point for the fourth term, ie:
1 2 3 !
This has no practical effect, it's just a preference thing. For SWITCH, it must be placed in the fourth term, and it just means that the 3rd term is the line that is jumped to, no matter what.
The exclamation point is also usable in the IF structure. If you're using the IF structure a b c d e as a=b or a≠b and thus your fourth term is the same as your fifth term, put an exclamation point for the fifth term:
1 2 3 4 !
This means that, if 1=2, jump to 3. Otherwise, jump to 4. Again, the exclamation point just a convenience thing.
~~~~
What if you want to jump to variable 'x'?
First of all, why use 'x' as a variable? There are plenty of others. But if you're using x for whatever reason, and you want to jump to the line denoted by the number 'x' is representing, you can't just do this:
x
since that's a bomb. However, you can just do:
0 0 x
which is the same thing.
~~~~
When a line is copied by a COPY structure, it is copied verbatim. ie:
1 2 100
7 9 add(a,2)
when run, that will copy the second line EXACTLY AS IT IS. Ie, after the first line is ran, the program will look like this:
1 2 100
7 9 add(a,2)
7 9 add(a,2)
But if you want to make it so that a variable is evaluated before being copied, use a CAPITAL letter. Take this program:
1 2 100
7 9 add(A,2)
say that the variable 'a' had a value of 3 at the time. Then after the first line runs, the program looks like this:
1 2 100
7 9 add(A,2)
7 9 add(3,2)
A capital letter variable has no difference from a lower-case variable when the line is being executed, the only difference from lowercaseness is when the line is being copied... when a line is copied, all of its variables stay variables, unless they are capitalized, in which case they are evaluated then and there for the new line.
By the way, a lone capital X is the same thing as a lower case 'x', ie, a bomb, except that if you copy this X, the result will be a number equal to whatever value your variable 'x' has. This makes 'x' a unique variable in that respect.
So... two programs. One array. 200 nodes... and only one victor. Post your ideas, your programs, declare duels... I've only written two more programs that I haven't posted here, called "Hopping Bomber" (or "Bombing Hopper", not sure which one sounds better ;D) and "Tracker", so you reading this can probably do better than what I've got so far The emulator is for download at the top of this post. Have at it, test your programs. If you have any questions, feel free to post here!
Link to comment
Share on other sites
Top Posters For This Question
43
10
10
Popular Days
Aug 5
10
Aug 10
6
Aug 3
6
Aug 2
5
Top Posters For This Question
unreality 43 posts
dms172 10 posts
plasmid 10 posts
Popular Days
Aug 5 2009
10 posts
Aug 10 2009
6 posts
Aug 3 2009
6 posts
Aug 2 2009
5 posts
70 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.