# 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:

1. Flag does nothing. Except it's how you win
2. Move moves your bot in the Dth direction. If a bot already occupies the space, no move will happen
3. Copy Var1 Var2 copies the contents of Var1 into Var2
4. If Condition Line1 Line2 If Condition is true, executes Line1, else Line2
5. Block 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:

1. If Var:
1. If Var is A through C, it will return true if Var is nonzero, else false.
2. If Var is D, it will return true if there is a bot in the Dth direction, else false
3. If Var is E, it will return true if E is odd, else false
4. If Var is a line, it will return true if it is a Flag line
2. If Var1=Var2:
1. Returns true if both are A-E, and equal the same number
2. Returns true if both are lines, and the line type is equal
3. If Var1==Var2:
1. Returns true if both are A-E, and equal the same number
2. Returns true if both are lines, and are identical (Flags from different bots will not be equal)

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

Blocking 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:

1. 6837 \$Copy
2. 3355 Lockheed
3. 1695 MindControl
4. 967 Byzantine
5. 959 AttackOrElse
7. 367 Influenza
8. 251 TheCommonCold
9. 226 Magus
10. 137 HideBlockAttack
11. 129 RowBot
12. 123 FastMoveCloneDodge
13. 112 FastForwardClone
14. 96 QuickFreeze
15. 71 RepairAndProtect
16. 96 SuperFreeze
17. 93 RovingVirus
18. 80 ForwardClone
19. 77 FreezeTag
20. 68 Palimpseste
21. 62 BlockFreezeAttack
22. 51 RushAttackDodge
23. 46 Blocker
24. 40 TurretMaker
25. 37 Copycat
26. 37 Kamikaze
27. 35 FlagInjector
28. 33 RandomCopier
29. 31 Insidious
30. 29 HappyAsAClam
31. 25 NanoVirus
32. 21 Nullifier
33. 19 Nanoviris
34. 17 BoringCopybot
35. 16 Movebot
36. 14 Flagbot
37. 13 Neutralizer
38. 12 Cancer
39. 9 DNAbot
40. 9 Parasite
41. 8 MetaInsidious
42. 8 Rebranding
44. 8 ReproducingBot
45. 8 KungFuBot
46. 5 QuickFreezerbot
47. 4 Attacker
• I'll be all about this once the Java is available for me to test. – Wasmoo Aug 28 '14 at 20:01
• I'm assuming you have never played Core war. en.wikipedia.org/wiki/Core_War – matt_black Aug 28 '14 at 20:27
• I haven't played it, but I read up quite a bit on it while writing this challenge. – Nathan Merrill Aug 28 '14 at 20:40
• 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 Aug 29 '14 at 2:03
• Any ETA on when the next battle round is going to be run? No rush at all. I'm just curious. Thanks. – COTO Aug 31 '14 at 20:56

# RandomCopier

Move
Copy #E *#*E
Copy E D
Copy 23 C

• Does this mean that on round 4, all of those bots instance get frozen? – plannapus Aug 29 '14 at 12:27
• What do you mean by frozen? I'll move once, copy a random line to his opponent once, change his direction randomly, then on the 4th turn, loop back to the first line. The 5th turn is when he will move again. – Nathan Merrill Aug 29 '14 at 12:33
• How do you get back to the first line? The way I understand it Copy 23 C copies 23 to C meaning next turn you're reading line 24 which is a flag since empty.... and then nothing. – plannapus Aug 29 '14 at 12:34
• The lines are 0-based, which means that line 23 is the last line. Also, all values wrap (so line 24 becomes line 0) – Nathan Merrill Aug 29 '14 at 13:48
• Your example bot in your question seem to use a 1-based line system (you refer to line 3 as being the "Move" line). It might be useful to state in the body of the question that the values wrap as well. As it stands it is not stated anywhere. – plannapus Aug 29 '14 at 13:51

# Rush, Attack, Dodge

Move
Move
If D #5 #1
Copy E D
Copy 1 C
Copy #E *#*C
Flag


This bot moves or attacks every three turns, changing direction at random.

# Forward Clone

Move
Move
If D #4 #1
Copy 1 C
Copy #E *#E
Flag


This bot moves or attacks every two turns, randomly cloning itself into any bot it bumps into.

# Fast Forward Clone

Move
If D #7 #0
If D #7 #0
If D #7 #0
If D #7 #0
If D #7 #0
Copy 1 C
Copy #E *#E
Flag


This bot moves or copies itself five out of six turns.

# Quick Freeze!

Quickly move to plant your flag in other bots, making sure that you completely stop them in their tracks.

Move
If D #2 #6
Copy #8 *#*C
Copy #7 *#*C+21
Block *#*C+20
Copy E D
Copy 23 C
Flag
Copy #C+23 #C+1
Flag
Flag
Flag
Move
If D #14 #18
Copy #20 *#*C
Copy #19 *#*C+21
Block *#*C+20
Copy E D
Copy 11 C
Flag
Copy #C+23 #C+1
Flag
Flag
Flag

• Minus is not allowed. – Nathan Merrill Aug 28 '14 at 19:46
• It is an easy fix. – PhiNotPi Aug 28 '14 at 19:57

# Boring copybot

I'm under the impression that having more lines of code makes my bot more robust. I'm also blocking my C variable often to prevent easy attacks. The idea is that other bots encounter me and I fill them with my flag and copy commands. I'm also hoping that considering the straightforward way my code works copying lines of my code into enemies will actually make them behave like my bot.

Block C
If D #C #C+1
Copy #E *#*E
Move
Flag
Copy #E *#*E
Block C
If D #C #C+1
Copy #E *#*E
Move
Flag
Copy #E *#*E
Block C
If D #C #C+1
Copy #E *#*E
Move
Flag
Copy #E *#*E
Block C
If D #C #C+1
Copy #E *#*E
Move
Flag
Copy #E *#*E


# Nanoviris

This is a really small virus.

Copy #A *#A
Copy A+1 A
If A=7 #5 #4
Copy 0 A
Copy 23 C
Copy 0 *C

• This only copies one flag as part of its virus. Even if it successfully infects another bot, it probably won't have the majority of flags. – Sparr Aug 29 '14 at 20:00

# Fast Move Clone Dodge

Move
If D #8 #0
If D #8 #0
If D #8 #0
If D #8 #0
If D #8 #0
Copy D+1 D
Copy 23 C
Copy #E *#E
Flag


This bot moves or copies its flags five out of seven turns, changing direction every seven turns.

# Cancer

This bot hits you hard at first by freezing you as quicky as possible, then replaces all of your flags by his (if possible) and then lets you go again with most of your code intact.

If D #4 #12
If D #4 #12
If D #4 #12
Copy 23 C
If *#*C==#23 #5 #6
Copy 6 C
Copy #23 *#*C
Copy 0 A
If *#A=#22 #14 #15
Copy A+1 A
If D #16 #11
Copy 7 C
Copy #22 *#A
Block #E
If A #15 #11
Copy 15 C
Copy #22 *#*C
Copy D+1 D
Copy 23 C
Flag
Flag
Flag
Flag
Copy C+23 C


# Flag Injector

Finds an opponent, then inserts its flag to stun the opponent until it looks like a FlagBot. Will move on after several attacks.

Attack redundancy included in an attempt to be more resistant to damage

Copy E D     //A: Turn Randomly
Move         //B: Move
If D #10 #3  //C: If [enemy exists] E else D
Copy 0 C     //D: Goto B
Flag
Copy #4 *#*C+1 //ATK1: Copy my flag
Flag
Copy #6 *#*C+1 //ATK2: Copy my flag
Flag
Copy #8 *#*C+1 //ATK3: Copy my flag
Copy 11 C    //E: Goto ATTACK
Copy 23 C    //F: Goto A
If *#*C==#4 #11 #5 //ATTACK: If [enemy executing my flag] E else ATK1
If *#*C==#4 #11 #7 //If [enemy executing my flag] E else ATK2
If *#*C==#4 #11 #9 //If [enemy executing my flag] E else ATK3
If *#*C==#4 #11 #5
If *#*C==#4 #11 #7
If *#*C==#4 #11 #9
If *#*C==#4 #11 #5
If *#*C==#4 #11 #7
If *#*C==#4 #11 #9
If *#*C==#4 #11 #5
If *#*C==#4 #11 #7
If *#*C==#4 #11 #9


# Kung Fu Bot

Copy 20 A
If D #5 #6
If D #11 #6
If D #10 #6
Copy 23 C
Move
If D=*D #7 #8
Copy #9 *#*C
Copy #A *#*C
Copy *#*A #C
If C=3 #5 #4
Copy D+1 D


Why give them flags when you could program them to take yours?

• language is (sadly) case sensitive. fix copy to Copy – Sparr Aug 29 '14 at 21:18

# TurretMaker

Move
If D #4 #0
If D #4 #0
Copy 0 C
Copy 4 C
If D #12 #11
If D #12 #11
If D #12 #11
If D #12 #11
If D #12 #11
Copy D+1 D
If D #4 #3
Copy #C+8 *#*C
Copy #C+23 *#E
Copy D+1 D
Flag
If D #C+21 #C+22
Copy C+22 C


When this bot bumps into another bot it turns that bot into a "turret". Turrets spin in place and copy a flag into any adjacent bots.

## Nullifier

In the hope that I finally understood the specs (and that no one did the same bot already):

Move
If D #2 #11
If *A #4 #3
Copy 0 *A
If *B #6 #5
Copy 0 *B
If *C #8 #7
Copy 23 *C
If *#0==#11 #12 #9
Copy #11 *#0
Copy 12 C
Copy 23 C
Copy #15 *#E
Copy 12 C
Flag


This bot, hopefully, move toward an opponent, then attempt to set this opponent's A, B and C to 0, then to copy Copy 23 C to its 0th line. Then write a flag in random lines in a loop.

I've noticed that quick, simple tactics seem to work well since bots are packed closely. If you spend too much time standing still, you're done. This bot starts out with a freeze and tag tactic but switches to making other bots freeze and tag bots after the first time a both his and the other bots E value are zero. He is rather fragile though, so we'll see how he does.

Edit: I've managed to decrease the lines needed and thus managed to throw in some line blocking for both the original as well as the clone, the advanced mode now also copies itself fully instead of just the simple part.

If D #C+10+B #C+8
Copy C+22 C
Flag
Copy C+23 C
Move
Copy D+3 D
Copy #C+3 *#*C
Copy #C+2 *#*E
If E #C+15 #C+16
If E #C+5 #C+7
If E=0 #C+11 #C+12
If *E=0 #C+13 #C+12
If *#*C==#C+3 #C+9 #C+6
Copy 7 B
Copy C+21 C
If E #C+4 #C+5
Block #E
If *#*C==#C+3 #C+15 #C+6
Copy C+15 C
Copy 23 A
Copy D *D
Copy #A *#*C+A
Copy A+23 A
If A=23 #C+6 #C+14

• The OP can correct me if I'm wrong, but I believe that Block E will block modifications to the E register rather than blocking writes to the Eth instruction. I suspect that isn't your intention. – COTO Aug 31 '14 at 6:53
• You're right, my mistake there. Thanks. – overactor Aug 31 '14 at 7:11

# Palimpseste

Move
If D #3 #2
Copy 23 C
Copy 3 C
If *#A=#23 #5 #6
If *#A==#23 #6 #9
Copy 6 C
Copy A+23 A
Copy 3 C
Copy 9 C
Copy #23 *#A
If A #8 #12
Copy 12 C
Copy D+1 D
Copy 23 C


Slowly rewrite the flags on the opponent as its own flag, do not touch the other lines, and then move on to another opponent. Very slow as it takes 3 turns for each controlled line whether it does rewrite or not.

# Kamikaze

If D #7 #6
If D #7 #6
If D #7 #6
If D #7 #6
If D #7 #6
Copy 23 C
Block #C+A
If *#0==#6 #8 #9
Copy #5 *#0
If *#21=#10 #11 #12
Flag
If *#21==#10 #15 #12
If *#22=#10 #13 #14
If *#22==#10 #16 #17
Copy #10 *#21
Copy #10 *#22
Copy #10 *#C


The only reason for this is to defeat 3 of the biggest competitors:AttackOrElse, Byzantine and SuperFreeze

• Alas, it didn't work. – Nathan Merrill Sep 2 '14 at 18:08
• @NathanMerrill Yes the code is flawed. I just saw that it says in the question "When you view another bot, it's code will be shifted". I will have to rewrite – MegaTom Sep 2 '14 at 18:35
• that actually isn't true anymore. – Nathan Merrill Sep 2 '14 at 19:31