14
3
Asymmetrical KOTH: Catch the Cat
UPDATE: The gist-files are updated (including new submisisons) as the Controller.java did not catch Exceptions (only errors). It does now catch errors and exceptions and also prints them.
This challenge consists of two threads, this is the cat thread, the catcher thread can be found here.
The controller can be downloaded here.
This is an asymmetrical KOTH: Each submission is either a cat or a catcher. There are games between each pair of each a cat and a catcher. The cats and the catchers have seperate rankings.
Catcher
There is a cat on a hexagonal grid. Your task is to catch it as fast as possible. Every turn, you can place a water bucket on one grid cell in order to prevent the cat from being able to go there. But the cat is not (perhaps) that dumb, and whenever you place a bucket, the cat will move to another grid cell. Since the grid is hexagonal, the cat can go in 6 different directions. Your goal is to surround the cat with water buckets, the faster the better.
Cat
You know the catcher wants to catch you by placing water buckets around you. Of course you try to evade, but as you are a lazy cat (as cats are) you exactly take one step at the time. This means you cannot stay on the same place you, but you have to move to one of the six surrounding spots. Whenever you see that the catcher placed a new water bucket you go to another cell. Of course you try to evade as long as possible.
Grid
The grid is hexagonal, but as we do not have hexagonal data structures, we take a 11 x 11
square 2d array and mimic the hexagonal 'behavior' that the cat can only move in 6 directions:
The topology is toroidal, that means if you step on a cell 'outside' of the array, you will just be transferred to the corresponding cell on the other side of the array.
Game
The cat starts out at given position in the grid. The catcher can do the first move, then the cat and its catcher alternate moves until the cat is caught. The number of steps is the score for that game. The cat tries to get a score as great as possible, the catcher tries to get a score as low as possible. The average sum over all the games you participated in will be the score of your submission. There are two separate rankings, one for the cat, one for the catchers.
Controller
The given controller is written in Java. As a catcher or a cat you each have to each complete implement a Java class (there are already some primitive examples) and place it in the players
package (and update the list of cats/catchers in the Controller class), but you also may write additional functions within that class. The controller comes with each two working examples of simple cats/catcher classes.
The field is a 11 x 11
2D- int
array that stores the values of the current states of the cells. If a cell is empty, it has value 0
, if there is a cat it has value -1
and if there is a bucket there is a 1
.
There are a few given functions you can use: isValidMove()
/isValidPosition()
are for checking whether your move (cat) / position (catcher) is valid.
Each time it is your turn, your function takeTurn()
is called. The argument contains the a copy of the current grid an has methods like read(i,j)
for reading the cell at (i,j)
, as well as isValidMove()/ isValidPosition()
that checks the validity of your answer. This also manages the wrapping over of the toroidal topology, that means even if the grid is only 11 x 11, you still can access the cell (-5,13).
The method should return a int
array of two elements, which represent possible moves. For the cats these are {-1,1},{0,1},{-1,0},{1,0},{0,-1},{1,-1}
which represent the relative position of where the cat wants to go, and the catchers return the absolute coordinates of where they want to place a bucket {i,j}
.
If your method produces an invalid move, your submission will be disqualified. The move is considered as invalid, if at your destination is already a bucket or the move is not allowed / destination already occupied (as a cat), or if there is already a bucket/cat (as a catcher). You can check that before hand with the given functions.
Your submission should work reasonably fast. If your method takes longer than 200ms for each step it will also be disqualified. (Preferably much less...)
The programs are allowed to store information between the steps.
Submissions
- You can make as many submissions as you want.
- Please do not significantly alter submissions you've already submitted.
- Please each submissions in a new answer.
- Each submission should preferably have it's unique name.
- The submission should consist of the code of your class as well as a description that tells us how your submission works.
- You can write the line
<!-- language: lang-java -->
befor your sourcecode in order to get automatic syntax highlighting.
Scoring
All cats will compete against all catchers the same number of times. I'll try to update the current scores frequently, the winners will be determined when the activity has decreased.
This challenge is inspired by this old flash game
Thanks @PhiNotPi for testing and giving some constructive feedback.
Current Scores (100 Games per pairing)
Name Score Rank Author
RandCatcher 191962 8 flawr
StupidFill 212688 9 flawr
Achilles 77214 6 The E
Agamemnon 74896 5 The E
CloseCatcher 54776 4 randomra
ForwordCatcher 93814 7 MegaTom
Dijkstra 47558 2 TheNumberOne
HexCatcher 48644 3 randomra
ChoiceCatcher 43834 1 randomra
RandCat 77490 9 flawr
StupidRightCat 81566 6 flawr
SpiralCat 93384 5 CoolGuy
StraightCat 80930 7 CoolGuy
FreeCat 106294 3 randomra
RabidCat 78616 8 cain
Dijkstra's Cat 115094 1 TheNumberOne
MaxCat 98400 4 Manu
ChoiceCat 113612 2 randomra
1I think this kind of challenge is what the cops-and-robbers tag is for. – SuperJedi224 – 2015-05-30T13:24:06.133
@SuperJedi224 No, in cops-and-robbers the cops constantly have to try and invalidate the robbers and once a robber is 'invalidated' it has 'lost' see http://codegolf.stackexchange.com/tags/cops-and-robbers/info
– flawr – 2015-05-30T13:33:33.9234@flawr I'd be in favour of extending the CnR tag to all challenges that involve two adversary sub-challenges (and using both that and KotH as tags on this). The CnR tag wiki is very much influenced by the first couple of challenges we had in that genre. (Also, you've got the cops and robbers the wrong way round. ;)) – Martin Ender – 2015-05-30T14:53:12.967
1What prevents cats from importing
main.Controller
, callinggetCatchers()
, and simulating / sabotaging the catchers' responses via theirtakeTurn
methods? – LegionMammal978 – 2015-05-30T14:54:28.23012@LegionMammal978 Sportsmanship. – Martin Ender – 2015-05-30T14:54:49.540
@LegionMammal978 This challenges are obviously open source the idea is obviously coming up with creative ideas, and I am sure the community here would not accept an answer like this. MartinBüttner already said that very concisely. – flawr – 2015-05-30T15:06:21.383
When trying to compile your controller I get
MyFrame cannot be resolved to a type
- what is aMyFrame
? Thanks – euanjt – 2015-05-30T15:58:37.787@TheE Oh sorry, I forgot to add this class in the latest update. The gist is updated now! Thank you for pointing this out! I just tested the gist and it works now. I am looking forward to your submission! – flawr – 2015-05-30T16:13:09.923
Love the visual representation of the games :) – euanjt – 2015-05-30T19:11:49.853
1Could you add a diagram showing the coordinate system and where the edges wrap around? – feersum – 2015-05-31T02:39:58.400
Can I use a global variable? Or a
static
variable intakeTurn
– Spikatrix – 2015-05-31T10:21:52.540@CoolGuy Yes of course, I explicitly allowed storing Information between the steps. It would be nice if you could fit all still within the one class (just for convenience). – flawr – 2015-05-31T11:36:31.437
2
@feersum does this help? (The black (resp. blue) dots represent the same cell.)
– flawr – 2015-05-31T11:56:01.367@flawr Yes exactly. – feersum – 2015-05-31T12:24:40.173
You can't catch me; I'm The Gingerbread Man.
– cat – 2016-04-24T00:42:55.597