17
2
Easter Egg Hunt
Bot find egg before bunny find egg. Bot happy.
Overview
This is a king-of-the-hill challenge in honor of Easter and the Easter egg hunting tradition!
Your bot has a vision of two spaces in every direction, including diagonals, creating a 5x5 square around you that you can see. It is looking for eggs, and whoever finds the most eggs wins!
The Board
The board will consist of o
s, which are Easter eggs, #
s, which are walls, *
s, which are other players, and s, which are empty spaces.
- It will be a square with edge length
(number of entries) * 3
. - It will be surrounded by walls.
- Inside of the walls will be an assortment of randomly placed, straight line walls of
#
, which will have a random length between 2 and 10 inclusive. There will be(number of entries) * 3
of them. - The eggs will then be placed randomly. There will be
(number of entries) * 4
of them, and they will only be generated on blank () squares.
- There must be at least 7 entires for the board generating process to work properly.
Here is a JSFiddle that will generate a random board for you to test with. Here's an example, with (number of entries) = 7
:
#####################
# o ##
# # o ##
# #o ###### ##
###### # ##
## o # # ##
## o# #o# o o##
## #o # # o # #
## # o # # # #
## ## # # o # #
## # # o # # #
## # o # ## # # #
## # # # #
# o # ## # #
# o oo ##o #
#o ####### oo ## #
# # # #
# o o o# #
# o #### o o#
# #
#####################
After the board is generated, each player is placed on a random square (empty space).
Input
You will take six lines of input. The first five lines are your field of vision (spaces out of bounds of the board will be represented by X
, and the middle space will always be *
, you), and the sixth line will be empty (at first).
Output
You will output three lines. First, the direction that you want to move in:
1 2 3
8 YOU 4
7 6 5
(9 is a no-op if you don't want to move), second, one of A
ttack, C
ounter, or N
othing (this will be explained in depth soon), and the thrid line will be any string of length up to 1024. This will be your bot's memory. You may use it for whatever you would like, or you may leave it blank. This memory will then be the sixth line of input to your program on the next run.
All further lines of output are ignored, and if there is only one line, the second is assumed to be blank.
Moving
The following process is used to determine where you moved:
- If, when you move, you end up in an empty space (
), your player is placed into that space.
- If you end up in a wall (
#
), your move is ignored and you lose your turn. - If you end up in an egg (
o
) or on a player (*
), this information is stored and will be used after everybody has moved.
After everybody has moved, ambiguities are resolved.
If there are two players that have landed on the same space, a fight occurs! This is where the A
/C
/N
comes in to play. A
ttack beats N
othing (normal attack), N
othing beats C
ounter (you can't counter nothing), and C
ounter beats A
ttack (counterattack). The player who wins this fight stays on their square, and the player who loses goes back to the original square that they started on. In the event of a tie, both players go back to where they were.
If a losing or tied player goes back to where they were and there is another player there, there is no fight and the other player will also revert to its original space. If this space has another player, that player goes back, and this continues until all players are in different spaces.
If there are three or more players on one space, they all revert back to their original positions.
If any player is still standing on an egg...
- If the player chose
A
, the egg is destroyed. - If the player chose
C
, nothing happens and the player reverts to its original space. - If the player chose
N
, the player picks up the egg! The player's score is incremented by one and the egg is removed.
Languages
You may use any language that is freely available on Windows, OSX, and Linux, to ensure fairness among each contestant. If the code is not freely runnable but can be compiled or packaged into a format that is, please include this format in your answer as well. Ideally, if you can compile your code into a more common language (i.e. CoffeeScript -> JavaScript), please do so.
Scoring
Your score will be the average number of eggs you collect out of ten runs. A run ends when all eggs are collected or when (number of entries * 25)
turns have passed. I will manually make sure that it is possible to reach all eggs for each map (by continually generating maps until all eggs are reachable).
Scoreboard
A scoreboard will be added when all of the following conditions are met:
- At least seven valid entries with a positive or zero score (not downvoted) have been submitted
- At least 48 hours has passed since the creation of this challenge (UTC 14:23)
The rules will not change during this pre-contest period, except to add clarification where a rule was unclear. Once the scoreboard is put up, the testing program will also be posted here so that you can test your entries. The testing code for this is still work-in-progress, but it's playable and it works. Here's the GitHub repo.
4Can we get the testing program before 7 entries are posted? I like to test before posting, even if it's against "dumb" test-bots. It seems this gives a significant advantage to not posting until several others have. – Geobits – 2014-04-20T14:44:25.017
1Regarding players going back. So I could potentially be unlucky and win against an opponent but he steps back into another player and starts a cascade that loop around back to the site of our fight, such that the player who started there sends me back a step as well? (if that's not clear, I'll post a github gist with an example) – Martin Ender – 2014-04-20T15:01:22.540
@m.buettner Ok fixed that (sorry I'm in a hurry right now, will clarify more later) – Doorknob – 2014-04-20T15:04:23.633
Oh and we can see through walls? – Martin Ender – 2014-04-20T15:06:09.173
1A sample control program would be very useful here. – starbeamrainbowlabs – 2014-04-20T15:35:33.040
@Geobits Alright, I'll upload my testing program in a sec. There's still a few bugs that need to be ironed out, but it works. (That's why I didn't post it immediately in the first place.) – Doorknob – 2014-04-20T17:06:05.973
@m.buettner Yes, that could happen, but the board scales according to how many players there are so it's unlikely. – Doorknob – 2014-04-20T17:06:32.897
@m.buettner The "walls" are more like... unpassable obstacles, shall we say. ;) I'll add a cap on the amount of moves per game, but I still think this generation method produces better obstacles for this kind of game. – Doorknob – 2014-04-20T17:07:24.807
@m.buettner Yeah, that discarding method sounds better. Thanks for all the help you're putting in to this ;) I would assume that at least one bot would have the ability to scan the whole map, but a move cap would be good anyway in case of an infinite loop or it just taking way too long. – Doorknob – 2014-04-20T17:30:46.937
Why not just wrap the map in two layers of walls (
#
)? It seems simpler to me. – Justin – 2014-04-20T20:42:10.1671Will I be informed if I am pushed back (whether or not I win)? Also, what will I get for the tile that I'm on? Will I see a space, a
*
, or what? – Justin – 2014-04-20T21:06:23.897@Quincunx in the current implementation your own position is a space. – Martin Ender – 2014-04-21T00:30:26.937
What is the procedure in determining the order of which bot fights which bot in the event where more than one bots go to the same space? And what happen when bot reverts back to its own space after doing
C
on an egg? – justhalf – 2014-04-21T06:27:54.327How can I use the testing code to test a bot? I don't know ruby and am new here :) – starbeamrainbowlabs – 2014-04-21T09:15:30.490
@starbeamrainbowlabs at the end of the
tester.rb
there's a string with loads ofruby dumbbot.rb
lines. Add the command for your own bot to that string (and remove some of the dumb bots if you wish). Then do eitherruby tester.rb < map.txt
on Unix orcat map.txt | ruby tester.rb
on Windows. – Martin Ender – 2014-04-21T10:15:24.797@m.buettner Thanks! That worked, lthough I had to change
chat map.txt | ruby tester.rb
totype map.txt | ruby tester.rb
in order to pass the map totester.rb
. – starbeamrainbowlabs – 2014-04-21T10:31:59.2403I like the memory line idea – Einacio – 2014-04-21T15:31:30.340
@Einacio I was just about to post that, I think more KotH challenges should use that. However, due to the variable size of the problem (i.e. the map) a fixed size of memory could really be a problem. I'm still not sure if I like that or not (although I suppose it was a conscious decision). This allows me to build a bot that memorises the entire map (or what it has seen of it so far), but might break if there are suddenly more then, say 15 submissions, a fix for which would make the bot considerably more difficult. – Martin Ender – 2014-04-21T15:43:47.653
After doing a few tests on a new bot I have to agree with @Quincunx that some feedback about the result of a fight would be very useful. Otherwise keeping track of where you are will require some quite elaborate pattern matching (and won't even be possible if you're in a region like the bottom left of the example map where there are no walls at all). – Martin Ender – 2014-04-22T12:36:29.560
2Also are you aware of the implication of your rules: if a player (A) chooses
9
, he can never be meaningfully attacked. If another player (B) steps onto that players square and wins, A will be moved back to its original square (which is the same). But now there is a clash because both A and B are there, so B has to go back to his own square. So the result is independent of the actual fight, B always moves back to the initial square and A always stays put. That would allow me to write a both that could help another submission by blocking of a path for everyone else. – Martin Ender – 2014-04-22T12:40:46.060Yet another thing: if two walls touch on a corner can I move through them diagonally? i.e. if there is a wall in direction
2
and4
can I move to3
? – Martin Ender – 2014-04-23T14:06:09.530Okay I just answered the question myself be looking at the test script. Such a move is indeed possible. Is that intentional or a bug? – Martin Ender – 2014-04-23T14:30:51.027
Unfortunately, it doesn't currently look like we're going to get far beyond 7 entries (so this question probably doesn't really matter), but what's your rationale behind increasing the map size with the square of the submissions but the number of walls only linearly (and their size not at all). If you generate maps for like 20 participants, they look really sparse. – Martin Ender – 2014-04-24T20:42:26.393
I'm also not sure I'm happy with the "If there are three or more players on one space, they all revert back to their original positions." rule (which you did add after the challenge started). If two other bots are in deadlock over an egg that makes it impossible for any other bot to break up that deadlock. Basically the three (or more) positions of the egg and the two (or more) players around the egg are completely inaccessible for the rest of the round. – Martin Ender – 2014-04-28T00:57:58.610