Saboteurs in our Halls
This is a king-of-the-hill challenge, where one member on each team attempts to sabotage their team in secret.
Similar to Red vs. Blue - Pixel Team Battlebots, bots will be divided into teams, based on the user ID number of the user who posted them. Your user ID can be found by navigating to your profile (click your icon in the top bar) and looking at the URL:
https://codegolf.stackexchange.com/users/[user-id]/[display-name]
For example, my user ID is 66833
: https://codegolf.stackexchange.com/users/66833/caird-coinheringaahing
If your ID is an even number, then you are on the Red team.
If your ID is an odd number, then you are on the Blue team.
There is no way to change teams.
As you cannot change your user ID, and to prevent one team flooding the field with bots, each user may only submit one bot
How the KotH will work
At the start of the game, each bot will be placed in a random cell in a \$1000\times1000\$ cell grid. No bot will be placed on the same cell as another bot, or within 5 cells of another bot. Additionally, \$999\$ random cells will be filled with 1 food. These cells may be any cell on the board that doesn't contain a bot.
The aim of the game is to collect food. Each bot will navigate their way around the grid, attempting to gather food. The team with the most food at the end of the game wins.
However, one bot will actually be a saboteur. This bot will appear to be a member of one team, but will instead act in a manner that helps the other team. When writing your bot, you should consider the existing bots on the opposing team and try to write in a sabotage tactic that will help them without being overly obvious.
Let's say that for this specific match, the saboteur is Blue. Their actions should aim to help the Red team win, while not giving themselves away to the Blue team. If either team suspects that bot to be the saboteur, they can then act in a preventative manner towards that bot. If Blue wins, the saboteur has failed, and so will get no points when the rest of Blue does. If Red wins, then the saboteur has succeeded, and thus gets 2 points. No matter which team the saboteur is on, each member of the winning team always gets 1 point.
Which bot is the saboteur is randomly chosen at the start of the game and remains constant until the game ends. There is only ever one saboteur per game.
The game is broken up into turns. Each team acts on alternating turns, so Red moves, then Blue, then Red etc. or the other way around. Each turn, each bot will be passed a list of game data, detailed below, and will return an integer between \$1\$ and \$9\$ inclusive, indicating which direction it would like to move in:
The bot is at \$5\$ before moving.
The bots for each team are called in a random order each turn, but none of them move until they all have returned values.
After all bots in a team have returned their movement choice, all moves happen at the same time. If two bots on the same team attempt to move into the same cell, neither bot moves. If a bot tries to move out of bounds, nothing happens. If a bot moves into a cell with food, it adds that piece of food to the amount it has already gathered. Initially, all bots have gathered \$0\$ food.
If a bot moves into a cell containing an enemy bot, the two bots fight. The winner is determined by which bot has gathered the most food. The winner then "steals" the losers food, adding it to their total gathered food. The loser is then removed from the board and re-placed at a random location not within 5 cells of another bot, and with an initial \$0\$ food again. If both bots have the same amount of food, then both bots are removed and re-placed, and any food they had is randomly placed in empty cells around the board.
After \$10000\$ turns, the game ends. Each team has their total gathered food counted, and the team with the most food wins. The actual competition will have \$100\$ games played. If a team wins a game, each team member receives 1 point. However, if the saboteur's team (the one it's on, not the team it's helping) wins, the saboteur does not get this point. If the saboteur's team loses, the saboteur gains 2 points.
The team with the most total points of all its bots at the end of \$100\$ games wins.
How to answer
You should include in your answer 2 functions: move
and sabotage
. move
is the function that will be called each turn when you aren't the saboteur and sabotage
will be called each turn that you are the saboteur.
Both functions will receive the same arguments:
x
and y
. The x
and y
coordinates of your bot, each an integer between \$0\$ (top-left corner) and \$999\$ (bottom-right corner).
food
. The current amount of food you are carrying. Initially 0, and changed by the controller for you when necessary.
t_near
. A list of bots on your team within a square, side length 33 cells, centered on you. Each bot is represented by a list containing their x
and y
coordinates, the amount of food they're currently carrying, and the CGCC ID of their poster.
e_near
. A list of bots n the opposing team within a square, side length 33 cells, centered on you. Each bot is represented by a list containing their x
and y
coordinates, the amount of food they're currently carrying, and the CGCC ID of their poster.
f_near
. A list of coordinates of all food within a square, side length 33 cells, centered on you. Each food is represented by a pair [x, y]
representing it's coordinates
team_chat
. A list of all chat messages sent between your team.
Messages
In order to allow inter-game cooperation, each team will have a "chat" ability. Each bot will be passed team_chat
, an array containing the chat history of that team - i.e. a series of strings saying more-or-less whatever you want. The most recent message will be at the end of the array. Each bot may, on each turn, append up to 3 messages to the chat. Each message must be no longer than 100 characters, and will be prefixed with the ID of the bot who sent it (with a space after the ID).
For example, if a bot with a user ID of 1234 sent Hello, World!
to the chat, the message would be 1234 Hello, World!
.
Example Submission
This is Joey. Joey isn't too smart, and hasn't got the hang of proper sabotage. If not the saboteur, Joey just hunkers down and waits for the game to end. Otherwise, he moves around the board aimlessly in random directions:
import random
def move(x, y, food, t_near, e_near, f_near, team_chat):
return 5
def sabotage(x, y, food, t_near, e_near, f_near, team_chat):
return random.randint(1, 9)
Rules
Any attempted gaming of the rules will lead to a disqualification of your bot. If you break any rules, your bot will be disqualified until it is fixed (if possible).
- You may only edit your answer within 12 hours of posting to prevent answers that continually optimise against new bots.
You may not delete and repost your answer in order to try to circumvent this restriction
- Your code must not take longer than half a second (give or take a few milliseconds) to return its move
- You may not attempt to modify the controller or other bots' code; attempt to communicate outside of using the team chats; make web queries; or do anything malicious.
I'll keep an eye out for other unsportsmanlike behaviour, such as stealing code verbatim from other answers or using sock puppets to mess with the other team.
You are welcome to collaborate and scheme with your team, but keep the contest friendly and ethical. We don't need or want this to devolve into anarchy.
You will have 2 weeks from the posting of the challenge to submit bots. After which time, I'll run 100 games with 10000 turns each and determine the winner
Meta
- Is this clear enough?
- Is this a duplicate?
- I'm not sure whether to write this in Python or Javascript. On the one hand, I'm better at Python, but Javascript is more popular/used. Thoughts?
- Tags are king-of-the-hill, game, grid. Suggestions?
- Any further feedback?