33
7
Code Bots
I hate private and protected variables. I just want to access anything and everything!
If you are like me, then this challenge is for you!
Write a bot that works together in harmony with other bots makes other bots do what you want. You are a programmer, and you know how things are supposed to work. Your job is to convert as many other bots to your ways as possible.
The Code
You will have 24 lines of code to write your bot. Each turn, every bot will execute 1 line sequentially.
Each bot stores 5 variables A
through E
. A
and B
are for personal use, C
stores the next line to execute, D
stores the current direction, and E
is a random number. The variables start at 0, except for D
, which will start at a random value. All variables have only store 0-23. Numbers larger or smaller will be modulated by 24.
In this post, I will use opponent to be the adjacent bot you are facing
Each line must contain one of the following 5 commands:
Flag
does nothing. Except it's how you winMove
moves your bot in theD
th direction. If a bot already occupies the space, no move will happenCopy Var1 Var2
copies the contents of Var1 into Var2If Condition Line1 Line2
If Condition is true, executes Line1, else Line2Block Var1
blocks the next write on a variable
A variable can be used as follows:
#Var
will use the variable as a line number. If A
is 17, Copy #8 #A
will copy the contents of line 8 onto line 17.
*Var
will use the variable of your opponent. Copy 5 *C
will set the opponent's C
variable to 5
Var+Var
will add the two variables. Copy D+1 D
will rotate the bot to the right
When D
is used as a direction, [North, East, South, West][D%4]
will be used
These modifiers can be chained: Copy *#*C #9
will copy the next line your opponent will execute into your own code on line 9. **D
refers to your opponent's opponent's D
variable.
A Condition will be evaluated as follows:
- If
Var
:- If Var is
A
throughC
, it will return true if Var is nonzero, else false. - If Var is
D
, it will return true if there is a bot in theD
th direction, else false - If Var is
E
, it will return true if E is odd, else false - If Var is a line, it will return true if it is a Flag line
- If Var is
- If
Var1=Var2
:- Returns true if both are
A-E
, and equal the same number - Returns true if both are lines, and the line type is equal
- Returns true if both are
- If
Var1==Var2
:- Returns true if both are
A-E
, and equal the same number - Returns true if both are lines, and are identical (Flags from different bots will not be equal)
- Returns true if both are
50 bots of each type will be placed in a toroidal world in the following pattern:
B...B...B...B...
..B...B...B...B.
B...B...B...B...
..B...B...B...B.
After each game of 5,000 turns, the flags on each bot will be counted. You get a point if a bot has more of your flag than any other type of flag. If the case of a tie between N
bots, no points are given.
There will be 10 games, and scores will be accumulated at the end.
Side Notes
End of line comments are allowed, and are denoted with //
Attempting to do something that doesn't make sense, such as adding to a line will do nothing
Attempting to do something on a non-existent bot will do nothing
Infinite recursion on an If
will end with no line being executed
If
does not change the value of C
A Block
doesn't expire until somebody attempts to write to it
Multiple variables and lines can be blocked at once
Block
ing a variable multiple times will block multiple times as long as the second block statement is on a different line of code than your first
Spaces are only allowed between arguments (and after the command)
If a bot is shorter than 24 lines, Flag will be the rest of the lines.
Sample Program
Copy 2 C //Skip to the If line
Flag //Where I'm storing my flag
Move //Move in the D'th direction
If D #5 #2 //If there's a bot, copy code, otherwise, move!
Copy #1 *#E //Copy my flag onto a random spot in my bot's code
Copy 2 C //Skip back to the If line
The program will be run by my Python controller here.
The Java controller is here It is fast and looks much better than the python one.
Scoreboard:
- 6837 $Copy
- 3355 Lockheed
- 1695 MindControl
- 967 Byzantine
- 959 AttackOrElse
- 743 Cadmyllion
- 367 Influenza
- 251 TheCommonCold
- 226 Magus
- 137 HideBlockAttack
- 129 RowBot
- 123 FastMoveCloneDodge
- 112 FastForwardClone
- 96 QuickFreeze
- 71 RepairAndProtect
- 96 SuperFreeze
- 93 RovingVirus
- 80 ForwardClone
- 77 FreezeTag
- 68 Palimpseste
- 62 BlockFreezeAttack
- 51 RushAttackDodge
- 46 Blocker
- 40 TurretMaker
- 37 Copycat
- 37 Kamikaze
- 35 FlagInjector
- 33 RandomCopier
- 31 Insidious
- 29 HappyAsAClam
- 25 NanoVirus
- 21 Nullifier
- 19 Nanoviris
- 17 BoringCopybot
- 16 Movebot
- 14 Flagbot
- 13 Neutralizer
- 12 Cancer
- 9 DNAbot
- 9 Parasite
- 8 MetaInsidious
- 8 Rebranding
- 8 AdaptiveBot
- 8 ReproducingBot
- 8 KungFuBot
- 5 QuickFreezerbot
- 4 Attacker
The variables start at 0, except for D, which will start at a random value.
wouldn't the random number be a random number too? Edit: wait this is a really old challenge I really need to check dates – Destructible Lemon – 2017-06-15T11:02:00.4471I'll be all about this once the Java is available for me to test. – Wasmoo – 2014-08-28T20:01:40.970
2
I'm assuming you have never played Core war. http://en.wikipedia.org/wiki/Core_War
– matt_black – 2014-08-28T20:27:29.683I haven't played it, but I read up quite a bit on it while writing this challenge. – Nathan Merrill – 2014-08-28T20:40:26.757
I have a patch for the Python controller and tried to push it back to you on github... but I don't have permissions / don't really know git. Patch replaces all "16"s with "num_lines" to allow write/jump access to last 8 instructions; also removes "max_flag_count = 0" from the tie condition in declare_flags(), which sometimes awarded a two-way tie to a third bot. – adipy – 2014-08-29T02:03:51.013
I literally just found the %16 before this comment. Thank you for the other fix. – Nathan Merrill – 2014-08-29T02:09:53.617
You say that
*Var
and**D
refer to the enemies variable. Which one is true? – CommonGuy – 2014-08-29T06:25:37.860Is
E
a new random number at every turn or is it generated only once? – plannapus – 2014-08-29T12:28:56.853Every turn @plannapus – Nathan Merrill – 2014-08-29T13:06:54.373
Shouldn't
If D #5 #3
beIf D #5 #2
in your example bot then? – plannapus – 2014-08-29T14:21:19.403Yes, thank you. – Nathan Merrill – 2014-08-29T16:27:05.823
I'm unable to run the Script. I tried it with both 2.7 (name '_' is not defined) and 3 (invalid syntax). – Sylwester – 2014-08-29T20:18:49.103
Sorry. I accidentally committed a version with a bad character. Should work on 2.7 – Nathan Merrill – 2014-08-29T20:43:28.317
@Manu, **D refers to the D value of your enemies enemy. – overactor – 2014-08-30T06:52:04.153
Did I miss it or is nowhere stated that
C
(the "instruction pointer") is increased by every instruction exceptIF
and aCOPY … C
? – Bergi – 2014-08-30T19:39:31.060@Bergi C is still incremented after an
IF
or aCOPY ... C
. – Sparr – 2014-08-31T15:53:46.4571Any ETA on when the next battle round is going to be run? No rush at all. I'm just curious. Thanks. – COTO – 2014-08-31T20:56:29.213
@COTO Next battle round has been run. – Nathan Merrill – 2014-09-02T12:58:11.070
Thanks, Nathan. A quick note: the bot .txt files in the github master are out of date. – COTO – 2014-09-02T13:21:59.900
Um... @NathanMerrill I'm having a hard time figuring the Java controller out. Where's the JAR you refer to in the commit? – Soham Chowdhury – 2014-09-16T10:10:11.447
Oh, I also tried doing it myself with
jar cvfm CB.jar META-INF/MANIFEST.MF codebots/*
. I ran the resulting JAR and got aNullPointerException at codebots.CodeBots.initBots(CodeBots.java:74) at codebots.CodeBotsGUI.StartGUI.<init> StartGUI.java:8) at codebots.CodeBots.main(CodeBots.java:67).
– Soham Chowdhury – 2014-09-16T10:11:43.347@SohamChowdhury I forgot to add the
.jar
, sorry (I removed the jar from the gitignore, but never actually added it). – Nathan Merrill – 2014-09-16T12:51:24.873