Inspired by this, but also different. I need help phrasing things, putting them together coherently, etc.
Also, I can't decide on what the magic numbers (size, toggles per turn, etc.) should be.
Lastly, is this even winnable?
(oh, and if anyone wants to write a nice "backstory", that'd be much appreciated)
(also I have a couple of notes to myself in there so I remember what I was doing when I come back to this later)
Murderous Life
cops-and-robbers cellular-automata game-of-life king-of-the-hill
Overview
The game is played on a 100-cell-wide, 300-cell-long board. It's cylinder-shaped -- patterns will wrap around the long sides, but not the short ones. Attempts to toggle cells behind the short edges will fail, and all cells along the short edge are considered dead. The center 200x100 area (the "no man's land") is the focus of the game. The farthest left 50x100 area (next to the origin) is the Police Headquarters, and is where the police can send units from. The far right is the Robber Hideout, and is where they operate from.
Your program will communicate with the controller via standard input and output. Each message is terminated with a newline (\n
, ASCII code 10). The code your program must exit when it receives Control+C (ASCII code 3). It doesn't have to stop immediately -- for example, if you have to close IO handles -- but it should take less than a second. It also doesn't have to end cleanly -- throwing an error is fine. As long as you've tidied up after yourself.
Immediately, both programs print to STDOUT their name and their author's name, with a hyphen in between, followed by a newline. This signals that they are ready to begin receiving input. After that, the turns will start immediately. The turns work like this:
- Both players are sent a string containing the current map through their STDIN. The format is detailed below.
- The desired moves are collected from each program in no particular order.
-
Note: If the moves are invalid for any reason -- they attempt to change a blocked square, too long, fail to precisely match the format, anything like that -- then the program is immediately ejected from the game, and I'll drop a comment on your post letting you know what happened.
- All of the moves are applied at once to the board
- One iteration of Conway's Game of Life (standard rules) is run on the map.
- The number of living cells in the No Man's Land is tallied.
The game runs for 5000 turns, after which the average number of living squares in the No Man's Land is calculated. This is the score of both the cop and the robber. Once three answers of each type have been submitted -- aside from the example ones -- I'll begin playing the answers against each other. The scoreboard will be updated daily until at least a week after the first answers have been submitted, or if it's later, three days after the last one has. The full score of any given program is the average of all of its scores.
Each program will be played against every other exactly once. Any attempts to communicate or disrupt the other AI -- except through the board -- are banned. If your bot doesn't respond to CTRL+D or CTRL+C, it will be banned.
Note that, if you have to do some cleanup before exiting, that's fine -- the "kill switches" don't have to work instantly. They do, however, have to work quickly. They can throw an error or something like that if you like.
You can always assume you'll get valid input.
In Cops version:
The point of the game, for the cops, is to keep the board as dead as possible. You can toggle up to 30 cells in the Police Headquarters per turn, creating or removing whatever patterns you like. At the end of the game, the Cop program with the lowest score wins.
In Robbers version:
The point of the game, for the robbers, is to make as many cells in the No Man's Land alive as possible. You can toggle up to 20 cells in the Robber Hideout per turn, in whatever arrangement you want. At the end of the game, the Robber program with the highest score wins.
[link to the opposite side's version]
Message format
Aside from the initial name string, all messages passed between programs will be like this:
1,4 12,0 9,125 299,6
Each pair is a coordinate pair, with the X values first and Y values second. The origin is at the top left of the board -- on the Police side of the board. The indexes are zero-based.
To be explicitly clear, the format is a space-delimited string of pairs. Each pair consists of two base-ten numbers, between 1 and 3 digits long, separated by a comma. The first number must not have a value greater than 299 or less than 0, and the second number must not have a value greater than 99 or less than 0. In addition, the first number must be between 0 and 49 (inclusive) if the player is a Cop, or between 250 and 299 (inclusive) if the player is a Robber.
I've written a basic example bot. To change what side it's on, simple change the comments on the lines indicated.
# Uncomment the part marked with the team this one should be on
#Cops
place_at = (0..47).to_a.product (0..97).to_a
glider = [[1, 0], [2, 1], [0, 2], [1, 2], [2, 2]]
toggles = 30
#Robbers
place_at = (0..47).to_a.product (0..97).to_a
glider = [[1, 0], [0, 1], [2, 2], [1, 2], [0, 2]]
toggles = 20
puts 'GliderLover-QPaysTaxes'
while gets
# We don't care what the board is like in this dumb AI.
puts toggles.times.map {
loc = place_at.sample
glider.map { |offset| loc.zip(offset).map { |(a, b)| a+b }.join ',' }.join ' '
}.join ' '
end
Is there anything else I need to specify?