11
3
Welcome to Code Bots 2!
You've learned your lesson since the last Code Bots. You've tried to figure out more ways to fit more actions in less lines, and now you finally have it. You're going to make an event-driven Code Bot.
Your bot must consist of 24 lines. Each line follows one of the two formats:
Condition:Action
or
Action
Your bot also have enough storage to store 5 integers named A through E. An integer can store values from 0 to 23.
Each turn, you will execute line C, unless one of the conditions is true. If so, then C will then contain the line number of the conditional that is true, and then that line will be executed. At the end of each turn, C will be incremented.
There are the available conditions:
Startis true only on the first turn. You must have this in your code exactly onceBotAt(N)is true if there is a bot at the location defined by NEquals(A,B)is true if A equals B. They can be different types, if so, they will not be equal.Modified(A)is true ifAwas copied to during the last turn.Amust be a variable name, a line, or a conditionAny(C1,C2,...)is true if any of the conditions are trueNone(C1,C2,...)is true if none of the conditions are trueAll(C1,C2,...)is true if all of the conditions are trueNot(C)is true if C is false.Cmust be a condition.
Variables can be in one of the following formats. The first 9 are numerical, and can be be used for whenever N is used in this page.
A,B,C,D,E- A number from 0 to 23
Thiswill return the line number it is currently onAdd(N1,N2,...)will return the sum of all valuesSub(N1,N2)will return N1 minus N2Mult(N1,N2,...)will return the product of all valuesDiv(N1,N2)will return N1 divided by N2Mod(N1,N2)will return N1 mod N2OVar(N)will accept a variable name, and will return the opponent's variableLine(N)will return the Nth line in your codeType(N)will return the Nth line type in your code (the types are the names of the actions)Cond(N)will return condition on the Nth lineCondType(N)will return the condition type on the Nth line (the types are the names of the conditions)OLine(N)will return the Nth line in your opponent's codeOType(N)will return the Nth line type in your opponent's codeOCond(N)will return the condition on the Nth lineOCondType(N)will return the condition type on the Nth line
A and B are for your personal use, C is used to determine which line to execute in your code, and D is used as a direction. Each value of D refer to a different square and direction pair.E produces a random value each time. D and E will be initialized to a random value, otherwise 0.
The direction used will be [North,East,South,West][D%4]. Your opponent is the bot in the immediate square in that direction.
There are 4 actions available to you:
Movewill move you 1 square forward in theDth direction. If there is a bot there, you will not move.Copy(A,B)will copy the variableAtoB.Bcannot be a numerical value, except for a variable name.AandBcannot be of different types. Copying a line does not copy the condition.Flagdoes nothing. The bot with the most flags in your code will get a point. The bot with the most points wins.If(C,L1,L2)will perform the line onL1ifCis true, else performsL2.Cis a condition, andL1andL2must be lines.
The Big Picture
50 copies of every bot will be placed in the world. Your goal is to get your flag into as many bots as possible. For each bot that has more of your flag type than any other flag type, you get a point.
The bots will be placed as follows:
B...B...B...B...
..B...B...B...B.
B...B...B...B...
There will be 10 games run, and points will be averaged across all of the games, determining who the winner is.
Side Notes
If multiple conditions apply, then the one that most immedately follows Start will be executed
The bots will be closely packed but you will not start neighboring another bot. (It techincally will be the same format as the last CodeBots)
As this challenge was not posted in the sandbox (to give nobody an advantage), I reserve the right to change small details for fairness, or additional capabilities. Also, if there is a bug in the CodeBots runner, I will change it, even if a bot depended on that bug for its success. I am trying to be as fair as possible.
Recursive If statements will not be executed
If your bot is shorter than 24 lines, the remaining lines will be filled with Flag
Remember when copying to your own C, that C is incremented at the end of your turn.
The CodeBots interpreter can be found here. It includes a .jar file for easy execution. Simply add your bot to the bots folder
Scores
- 893.9 Borg
- 1.3 LazyLioness
- 0.9 Defender
- 0.5 Flagger
- 0.4 CliqueBot
- 0.4 Insidious
- 0.3 Attacker
- 0.3 Gard
- 0.3 SingleTarget
- 0.2 FreezeBot
- 0.2 Sentinel
- 0.2 Driveby
- 0.0 AntiInsidious
- 0.0 MoveBot
- 0.0 CliqueBorg
- 0.0 Calculator
- 0.0 TestBot
- 0.0 Imitator
UPDATE
Lines of code are now rotated when you view your opponent's code. That means, your opponent's line 1 may be line 14 (or whatever line). A bot will have a fixed offset which will offset his lines by X amount when viewed by an opponent. The opponent's C variable will also be offset by the same X amount. X will not change within the same game, but it will change from game to game.
Nathan: Are you able to check out "Lazy Lioness" to see whether the bugs I've reported are legitimate (or if I'm just out to lunch)? No rush. Just making sure you're aware of the submission. – COTO – 2014-09-10T05:31:12.207
@COTO Sorry, schools been crazy. I'll try to get to it tonight. – Nathan Merrill – 2014-09-10T17:01:36.267
The 'All' condition could be made implicit for any comma separated list of conditions. It would make reading the entries a bit easier. – ccarton – 2014-09-11T11:27:58.357
I think I found your bug. The FuctionParser objects are being used as keys in a HashMap which means you need a proper equals method. This fixes the problem with CliqueBot and likely Lazy Lioness as well. I sent you a pull request. – ccarton – 2014-09-11T20:47:08.470
@ccarton the HashMap only memoizes the values, it isn't used for testing equality – Nathan Merrill – 2014-09-11T23:53:03.543
HashMaps don't work properly unless the keys have .equals() methods. See this. This is causing the memoizer to return different objects for the same line text.
– ccarton – 2014-09-12T08:00:01.723Here is a better explanation of reason for the hashcode and equals requirements. – ccarton – 2014-09-12T08:09:50.010
@ccarton I understand that that is a bug. However, it does not affect the actual program execution. It simply prevents additional parsing from being done. – Nathan Merrill – 2014-09-12T12:46:11.233
It does affect execution because your Action class also does not have a .equals() method which means it is relying on reference equality. So when the HashMap returns two different Action objects for the same line text those Actions won't evaluate as equal. – ccarton – 2014-09-12T13:06:46.813
Ah. Then that is the bug. I know how to fix it. Thank you. – Nathan Merrill – 2014-09-12T13:15:35.263
@ccarton: That does fix the problem of the spurious interrupts. Unfortunately, Lazy Lioness still does nothing. The conditions seem to be evaluating properly (i.e. green in the right places), and the instruction pointer seems to be at the right location (i.e. blue at the right place), but it's as if the controller is ignoring the instructions. I might have time on the weekend to look into it, but since you're already familiar with the code, maybe you could take another look. It sounds like Nathan is swamped with work. – COTO – 2014-09-12T13:19:18.207
Glad I could help. I couldn't tell if that was by design or not. It would theoretically work fine if the memoizer worked properly. Even if you change that, you should still fix the other bug as well. – ccarton – 2014-09-12T13:20:59.610
@COTO: If I get a chance I'll have a look. It's possible that the lack of an equals method on the Action class is causing some additional issues, as apparently that wasn't by design. Give it another try after Nathan fixes that. – ccarton – 2014-09-12T13:26:43.027
When will you refresh your scoreboard? – MegaTom – 2014-09-12T14:19:22.910
Ok. I fixed that bug (and another one dealing with
BotAt()). Scoreboard posted. – Nathan Merrill – 2014-09-12T15:13:40.453@COTO It looks like LazyLioness is working as expected. Realize that priority of conditions is based off of your
Startcondition, not the first line. – Nathan Merrill – 2014-09-12T15:20:03.003In my tests, his (LasyLioness') start action is not being executed on the first turn. It only executes if I move the start line to the first position. I think there is a bug in Bot.checkConditions(). Should it not be conditionIsTrue(lineNum)? – ccarton – 2014-09-12T15:25:10.460
"
Copy(A,B)will copy the variableNtoM" - Huh? – Eric – 2014-09-12T22:08:56.327@NathanMerrill: I placed the
Startcondition on the last line so that the instructions would have the highest priority on line 1 and descending priority below. I assumed the priority queue "wrapped around" the same way as execution order did. But maybe I'm missing something. I'll have more time to play around with the simulator this coming Sunday. – COTO – 2014-09-13T00:10:08.627What happens if I clone a
Startcondition into a non-Startcondition? – TwiNight – 2014-09-13T02:04:56.843@TwiNight the initial position of
Startis used throughout the simulation – Nathan Merrill – 2014-09-13T11:56:10.453Hey Nathan, did you see my last comment about a possible bug in Bot.checkConditions()? – ccarton – 2014-09-13T12:43:43.343
@ccarton sorry, I missed it. fixed and pushed – Nathan Merrill – 2014-09-13T13:03:36.247
I think there is a problem with the offset code.
OLine(OVar(C))doesn't reference the correct line. For example, ifCis 1 and the offset is 5, thenOVar(C)returns 6 and thenOLine(6)returns data from line 11. I think you need to be subtracting the offset in one of those cases to get them to line up. – ccarton – 2014-09-13T22:49:32.890I think
BotAtis still bugged. Look at Gard. TheBotAts are green at all the wrong places. – TwiNight – 2014-09-13T23:50:01.490I think the problem with
BotAtis in thegetShiftYfunction. It's ignoring it's parameter and calculating direction fromD. Looks like maybe it's old code that you meant to delete? – ccarton – 2014-09-14T11:02:00.437@ccarton thanks for the help with the bugs. It's tough to find them all. They are fixed. – Nathan Merrill – 2014-09-14T13:45:56.173
Unfortunately, the offset makes porting MindControl impossible (due to the victim unable to correctly reference my own lines), and Borg is doing so well that all my resistance attempts so far are indeed futile. – TwiNight – 2014-09-16T05:18:05.223
Bugs!!
TypeArgumentsplits spaces but lines no longer have spaces in CB2 – TwiNight – 2014-09-16T23:19:26.097@TwiNight Ah, good catch. – Nathan Merrill – 2014-09-17T14:47:35.250