Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

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:

  1. Start is true only on the first turn. You must have this in your code exactly once
  2. BotAt(N) is true if there is a bot at the location defined by N
  3. Equals(A,B) is true if A equals B. They can be different types, if so, they will not be equal.
  4. Modified(A) is true if A was copied to during the last turn. A must be a variable name, a line, or a condition
  5. Any(C1,C2,...) is true if any of the conditions are true
  6. None(C1,C2,...) is true if none of the conditions are true
  7. All(C1,C2,...) is true if all of the conditions are true
  8. Not(C) is true if C is false. C must 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.

  1. A,B,C,D,E
  2. A number from 0 to 23
  3. This will return the line number it is currently on
  4. Add(N1,N2,...) will return the sum of all values
  5. Sub(N1,N2) will return N1 minus N2
  6. Mult(N1,N2,...) will return the product of all values
  7. Div(N1,N2) will return N1 divided by N2
  8. Mod(N1,N2) will return N1 mod N2
  9. OVar(N) will accept a variable name, and will return the opponent's variable
  10. Line(N) will return the Nth line in your code
  11. Type(N) will return the Nth line type in your code (the types are the names of the actions)
  12. Cond(N) will return condition on the Nth line
  13. CondType(N) will return the condition type on the Nth line (the types are the names of the conditions)
  14. OLine(N) will return the Nth line in your opponent's code
  15. OType(N) will return the Nth line type in your opponent's code
  16. OCond(N) will return the condition on the Nth line
  17. OCondType(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:

  1. Move will move you 1 square forward in the Dth direction. If there is a bot there, you will not move.
  2. Copy(A,B) will copy the variable N to M. B cannot be a numerical value, except for a variable name. A and B cannot be of different types. Copying a line does not copy the condition.
  3. Flag does nothing. The bot with the most flags in your code will get a point. The bot with the most points wins.
  4. If(C,L1,L2) will perform the line on L1 if C is true, else performs L2. C is a condition, and L1 and L2 must 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

  1. 931 SingleTarget
  2. 667 Gard
  3. 664 Attacker
  4. 532 Defender
  5. 307 Calculator
  6. 275 Flagger
  7. 68 MoveBot
share|improve this question
5  
Why not post on the sandbox instead of reserving the right to change small details for fairness? Isn't the sandbox made to prevent one from reserving the right to change small details for fairness? –  William Barbosa 21 hours ago
1  
@WilliamBarbosa Because last time, some people had a significant time advantage. I am trying to make things as fair as possible, but I may have missed something. You shouldn't expect anything to change though. –  Nathan Merrill 20 hours ago
1  
Is there any defense against the (classic) Copy(<Copy(C+23,C)>,Add(OVar(C),1)) instafreeze, or the new-age Copy(<Equals(0,0)>,OCond(0)) instafreeze? I don't see any Block instructions. O___O –  COTO 17 hours ago
3  
Where are the basic rules? Is there a "CodeBot?" (it implies there was) There seems to be a lot of implicit knowledge in these rules, I can't find reference to. What is the significance of "moving" and "position"? It says "bots are closely packed". How many can there be? If there is more than two, then what does "your opponent" mean? –  GreenAsJade 8 hours ago
2  
@GreenAsJade this is a follow-up on the OP previous challenge: codegolf.stackexchange.com/questions/36978/… You can find some of your questions answered there. NathanMerril: maybe you should indeed link your previous challenge in the question body, as its title was not directly "CodeBots" but "What's wrong with public variables" and it does contain information relevant to this challenge as well. –  plannapus 6 hours ago

8 Answers 8

Flagger

Shoot for the moon

Start:Flag

And the rest gets auto-filled with flag.

share|improve this answer

Defender

Start:Copy(0,A)
Copy(0,B)
Flag
Flag
All(Modified(Line(2)),Equals(A,0)):Copy(1,A)
Copy(Line(3),Line(2))
Copy(0,A)
Copy(10,C)
All(Modified(Line(3)),Equals(B,0)):Copy(1,B)
Copy(Line(2),Line(3))
Copy(0,B)
BotAt(D):Copy(Line(2),OLine(E))
share|improve this answer

MoveBot

Start:Move
Copy(E,D)
Copy(-1,C)
share|improve this answer
    
Shouldn't that be Copy(23,C)? –  ipi 20 hours ago
    
Negative values are now allowed. –  Nathan Merrill 20 hours ago

Attacker

Start:Move
BotAt(D):Copy(Line(Add(Mod(E,6),4)),OLine(E))
Any(BotAt(0),BotAt(1),BotAt(2),BotAt(3)):Move
None(BotAt(0),BotAt(1),BotAt(2),BotAt(3)):Copy(E,D)
share|improve this answer

Single Target

Start:Move
All(BotAt(D),Not(Equals(OVar(D),D))): Copy(D,OVar(D))
BotAt(D):Copy(Line(E),OLine(E))
Equals(A,A):Move

Will hunt you down and fill you with flags!

share|improve this answer
    
The All condition needs a ) –  Nathan Merrill 12 hours ago

Calculator

This bot doesn't understand the goal of this challenge, so he decided to calculate some numbers for the enemy.

Equals(Mod(OVar(E),5),0):Copy(Add(OVar(A),OVar(B)),OVar(D))
Equals(Mod(OVar(E),5),1):Copy(Sub(OVar(A),OVar(B)),OVar(D))
Equals(Mod(OVar(E),5),2):Copy(Mult(OVar(A),OVar(B)),OVar(D))
Equals(Mod(OVar(E),5),3):Copy(Div(OVar(A),OVar(B)),OVar(D))
Equals(Mod(OVar(E),5),4):Copy(Mod(OVar(A),OVar(B)),OVar(D))
Start:Move
share|improve this answer
    
you should put the results into OVar(D) not A! –  MegaTom 2 mins ago
    
@MegaTom Done ;) –  Manu 12 secs ago

Gard

Start: Move
BotAt(D):IF(Equals(Line(7),OLine(C)),Line(6),Line(5))
BotAt(Add(D,1)):Copy(Add(D,1),D)
BotAt(Add(D,2)):Copy(Add(D,2),D)
BotAt(Add(D,3)):Copy(Add(D,3),D)
Copy(Line(7),OLine(OVar(C)))
Copy(Cond(7),OCond(Sub(OVar(C),1)))

Attacks any robot next to it.

share|improve this answer
    
Your last line cannot copy from a condition to a line. –  Nathan Merrill 12 hours ago
    
@NathanMerrill I was just fixing that... –  MegaTom 12 hours ago
    
OCon needs to be OCond –  Nathan Merrill 12 hours ago

Freeze Bot

Start:Move
All(BotAt(D),Not(Equals(OCond(1),Cond(5)))):Copy(Cond(5),OCond(1))
All(BotAt(D),Not(Equals(OLine(1),Line(6)))):Copy(Line(6),OLine(1))
All(BotAt(D),Equals(Mod(OVar(A),24),0)):Copy(D+1,D)
BotAt(D):Copy(Line(20),OLine(OVar(A)))
Equals(A,A):Move
Copy(Add(A,1),A)

Traps you in a loop Incriminating your own A variable, then fills you with flags and moves on to the next victim.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.