13
Welcome back! I'm excited to present the 3rd CodeBots challenge. This one has been a long time in the making. This challenge will be split up in 3 sections: the short version, the long version, and additional details.
The Short Version
Each competitor will write a 24-command program. These bots will move around the world and copy their code into other bots, while trying to prevent other bots to do the same. One of the possible commands is the no-op Flag
. If a bot has more of your Flag
than any other bot's Flag
, you get a point. You win by having the most points.
All of the above was true for the past two challenges. This time around, bots will be able to run multiple lines of code at the same time.
The Long Version
The API
Every bot will have exactly 24 lines, where each line is in the following format:
$label command parameters //comments
Labels and comments are optional, and each command has a different number of parameters. Everything is case-insensitive.
Parameters
Parameters are typed, and can be in the following formats:
- A value from 0 to 23.
- A variable:
A
,B
,C
,D
- A value using addition:
A+3
or2+C
- A line of code, which is designated using the
#
sign (#4
would represent the 5th line, while#C+2
would represent the line calculated byC+2
). - You can use a
$label
instead of designating a line of code. - Your opponent's variable or line of code, designated by
*
. Your opponent is the bot in the square that you are facing. (*B
represents your opponent'sB
value, while*#9
represents your opponent's 10th line). If there is nobody in that square, the command is not executed.
Commands
Move V
Moves the bot North+(V*90 degrees clockwise)
. Movement does not change direction.
Turn V
Turns the bot V*90 degrees
clockwise.
Copy V W
Copies whatever is in V
into W
. If V
is a line number, then W
has to be a line number. If V
is a variable or value, then W
must be a variable.
Flag
Does nothing.
Start V
Starts a new thread attached to the variable V
. Immediately, and on each future turn, the thread will execute the command on line V
.
If V
is already attached to a thread, then this command is a no-op. If V
is an opponent's variable, then the opponent will start a thread attached to that variable.
Stop V
Stops the thread attached to the variable V
at the end of this turn.
Lock V
Prevent the line or variable V
from being used in any way except by the thread that called Lock
. A subsequent call to Lock
by the same thread unlocks V
. Locks cannot be called on opponent's variables or lines.
If Cond V W
This will test Cond
. If the condition is true, then it will move the thread pointer to the line number V
, otherwise to the line number W
. That line will then be immediately executed.
Conditionals can be X=Y
, X<Y
, !X
, or ?X
:
X=Y
tests whether two lines are of the same type and from the same bot, or you test whether two values equal the same amount.X<Y
tests whether the value ofX
is less thanY
.!X
tests whether the variable or lineX
is locked (returns true if locked)?X
tests whether a given variable has a thread attached to it
Additional Details
Multi-threaded interactions
Actions of the same type are executed at the same time. Actions are executed in the following order:
Lock. If several threads attempt to lock a variable, they will all fail. If a thread is unlocking a variable while another is attempting to lock it, the variable will remain unlocked.
Start. If several threads attempt to start a thread on a variable, it will count as a single start.
Copy. If two threads both copy to the same variable, the variable will end up as a random value. If they both copy to the same line, neither will work. If a thread copies to the same variable another thread is copying from, then the latter thread will copy a random value. If two threads are both copying from the same variable, they will both work fine.
If. All conditionals will be tested simultaneously, and then the thread variables will be updated after. Executing an
If
can cause an action with a higher priority to be added. Actions with higher priority will be executed before moving on past theIf
, while actions with a lower priority will execute after theIf
.Move. Multiple moves on the same bot will move the bot the sum of all of the moves. If multiple bots would end up in the same spot, they will be returned to their starting spot.
Turn. Multiple turns on the same bot will sum.
Stop. Multiple stop commands on the same variable will count as a single stop.
Other details
Your initial thread starts attached to the D
variable
Recursing with an If
(having an If
statement pointed to itself) will cause your bot to do nothing
If a thread is stopped after locking, those locks will be unlocked
Actions to use a locked variable or line will do nothing.
If a bot is shorter than 24 lines, remaining lines will be filled with Flag
Performing a write on a variable that is also attached to a starting thread will actually have the thread start its execution on the new value as the thread starts the following turn.
Bots are placed in a toroidal world in the following pattern:
B...B...B...
..B...B...B.
B...B...B...
I have added several sample bots that are commented as a language reference.
The controller is located here. I've worked a long time on it, but it probably still has bugs. When the spec and the controller contradict, the spec is correct.
Scoreboard
1. 771 LockedScannerBot
2. 297 CopyAndSelfFlag
3. 289 DoubleTapBot
4. 197 ThreadCutterBot
5. 191 TripleThread
6. 180 ThickShelled
7. 155 Attacker
8. 99 RandomMover
9. 90 BananaBot
10. 56 LockedStationaryDoubleTap
Wow, at least, DoubleTap seems much better than samples ! – Katenkyo – 2015-06-12T14:37:39.153
What should happen if I try to read a locked variable from another thread? Say I do LOCK A then in another thread there's a MOVE A. Does A evaluate to 0 or a random value or does the move fail or...? – Sparr – 2015-06-12T16:08:08.073
Ditto on what happens when a thread reaches a line locked by another thread. Is it a noop? Does it get skipped? – Sparr – 2015-06-12T16:23:26.557
Should "Copy $label A" work? It interprets as "Copy #11 A" which isn't valid and crashes the interpreter, instead of "Copy 11 A" as I'd hope for. – Sparr – 2015-06-12T17:26:22.253
possible bug... I seem to be able to read my own flag lines to copy from them, even when they are locked by another thread. – Sparr – 2015-06-12T17:49:38.937
Both reading the variable (as in Move A), and executing the line is a no-op. – Nathan Merrill – 2015-06-13T13:49:34.477
@sparr concerning your $label, I'll have to see what I can do, but right now, I'm doing a super dumb find/replace. – Nathan Merrill – 2015-06-13T13:50:48.170
What happens if you use * and no bot is in front of you? for example
If ?*A
,Copy 1 *A
– MegaTom – 2015-06-15T18:36:24.040@MegaTom it is a no-op. – Nathan Merrill – 2015-06-15T18:37:03.133