> The contest is now over. [Coward][1] is the winner.
> You can watch the last match [here][2].

Suddenly zombies appear! OH NOES!

In this king-of-the-hill challenge, you must create a bot to survive the zombie apocalypse. Or at least, hold out for as long as possible.

At the start of the game, 50 instances of each entry will be placed randomly in a large [toroidal][3] play area - that is, it appears to be square, but wraps around. The size of the play area will vary depending on the number of entries, but initially 6% of squares will be occupied. Each competitor starts with 3 bullets.

At the beginning of each turn, a zombie will rise from the ground at a random location, destroying whatever was above it. Any player who is next to a zombie at the start of their turn will become a zombie.

For each living player, their code will then be called. It will receive a [PlayerContext][4] object, containing information on their current status, and their surroundings. Each player can see for 8 squares in any direction.

The player must choose to either move (staying still is a valid movement), by returning a `Move`, or shoot a nearby person or zombie, by returning a `Shoot`. Your gun has a maximum range of 5 squares. Since you are within your gun's range you *can* shoot yourself, provided you have bullets left. If two players shoot each other, they both die.

If two players attempt to move onto the same square, they will fail, and will both return to the square they started from. If there are still conflicts, this will be repeated until there are no conflicts, which may mean everyone is back where they started.

If a player dies from a gunshot, their dead body will remain, and forms a permanent barrier. Any bullets they were carrying remain on their person, and can be scavenged by players in adjacent squares. If there are multiple players occupying the squares adjacent to a dead body, then the bullets will be shared between them, but any remainder will be lost.

If a player becomes a zombie, then their bullets are lost. Zombies will mindlessly walk towards the nearest living player.

Entries are scored on how long their longest-surviving player survives.

##Entries##

A control program is available at https://github.com/jamespic/zombies. Simply clone it, and run `mvn compile exec:java`.

To be eligible, entries must be written in a JVM language, must be portable, and must be possible to build from Maven with no special set-up. This is to ensure that competitors do not need to install multiple run-time environments to test their bots against competitors.

Sample entries are currently available in the following languages:

- [Java 7][5] - see also [a more complex example][6], and [the code for zombies][7]
- [Scala 2.11.1][8]
- [Javascript (via Rhino)][9]
- [Python (via Jython 2.7 beta 2)][10]
- [Ruby (via JRuby 1.7.13)][11]
- [Clojure 1.5.1][12]
- [Frege][13] (a bit like Haskell - [here's another example][14])

If you would like to compete in a language that is not listed, you can post a comment requesting it, and I will investigate the possibility of integrating your chosen language into the control program. Or, if you are impatient, you can submit a pull request to the control program.

Only one instance (in the Java sense of the word) will be created for each entry. This Java instance will be called multiple times per turn - once for each surviving player.

##API##

<!-- language: lang-java -->

    package zombie

    // You implement this. Your entry should be in package `player`
    interface Player {
        Action doTurn(PlayerContext context)
    }

    // These already exist
    class PlayerContext {
        // A square array, showing the area around you, with you at the centre
        // playFields is indexed by x from West to East, then y from North to South
        PlayerId[][] getPlayField()
        int getBullets() // Current bullets available
        int getGameClock() // Current turn number
        PlayerId getId() // Id of the current player instance
        int getX() // Your current x co-ordinate
        int getY() // Your current y co-ordinate
        int getBoardSize() // The size of the current playing field
        Set<PlayerId> shootablePlayers() // A helper function that identifies players in range.
    }

    class PlayerId {
        String getName() // The name of the entrant that owns this player
        int getNumber() // A unique number, assigned to this player
    }

    // Don't implement this. Use either `Move` or `Shoot`
    interface Action {}

    enum Move implements Action {
        NORTHWEST, NORTH, NORTHEAST,
        EAST, STAY, WEST,
        SOUTHEAST, SOUTH, SOUTHWEST;
        static move randomMove();
    }

    class Shoot implements Action {
        Shoot(PlayerId target);
    }

##Additional Rules##

Each entry must have a unique name, in order to work correctly with the control program.

Entries should not attempt to tamper with other entrants, or with the control program, or otherwise take advantage of the run-time environment to "break the fourth wall", and gain an advantage that would not be available in a "real" zombie apocalypse.

Communication between players is allowed.

The winner is the entrant whose bot has the highest score in a test I will run on the 3rd of August 2014.

##Final Results##

The final results are in! Coward is the winner!

On 2nd August, I ran 19 rounds of the control program, and ranked each player according to their median score. The results were as follows:

    Coward: 4298
    Fox: 3214
    Shotguneer: 2471
    Cocoon: 1834
    JohnNash: 1240
    HuddleWolf: 1112
    Sokie: 1090
    SOS: 859
    GordonFreeman: 657
    Jack: 657
    Waller: 366
    SuperCoward: 269
    MoveRandomly: 259
    StandStill: 230
    Vortigaunt: 226
    ThePriest: 223
    Bee: 61
    HideyTwitchy: 52
    ZombieHater: 31
    Gunner: 20
    ZombieRightsActivist: 16
    SunTzu: 11
    EmoWolfWithAGun: 0

The last round is available to watch [here][15].

##Run-by-run results##

The individual results of each of the 19 runs were:

    #Run at 03-Aug-2014 14:45:35#
    Bee: 21
    Cocoon: 899
    Coward: 4608
    EmoWolfWithAGun: 0
    Fox: 3993
    GordonFreeman: 582
    Gunner: 18
    HideyTwitchy: 37
    HuddleWolf: 2836
    Jack: 839
    JohnNash: 956
    MoveRandomly: 310
    SOS: 842
    Shotguneer: 2943
    Sokie: 937
    StandStill: 250
    SunTzu: 3
    SuperCoward: 318
    ThePriest: 224
    Vortigaunt: 226
    Waller: 258
    ZombieHater: 41
    ZombieRightsActivist: 10

    #Run at 03-Aug-2014 14:56:48#
    Bee: 97
    Cocoon: 3073
    Coward: 5699
    EmoWolfWithAGun: 0
    Fox: 4305
    GordonFreeman: 1252
    Gunner: 24
    HideyTwitchy: 25
    HuddleWolf: 3192
    Jack: 83
    JohnNash: 1195
    MoveRandomly: 219
    SOS: 884
    Shotguneer: 3751
    Sokie: 1234
    StandStill: 194
    SunTzu: 69
    SuperCoward: 277
    ThePriest: 884
    Vortigaunt: 564
    Waller: 1281
    ZombieHater: 10
    ZombieRightsActivist: 2

    #Run at 03-Aug-2014 15:01:37#
    Bee: 39
    Cocoon: 2512
    Coward: 2526
    EmoWolfWithAGun: 0
    Fox: 2687
    GordonFreeman: 852
    Gunner: 21
    HideyTwitchy: 91
    HuddleWolf: 1112
    Jack: 1657
    JohnNash: 944
    MoveRandomly: 312
    SOS: 660
    Shotguneer: 1067
    Sokie: 1356
    StandStill: 169
    SunTzu: 8
    SuperCoward: 351
    ThePriest: 223
    Vortigaunt: 341
    Waller: 166
    ZombieHater: 25
    ZombieRightsActivist: 47

    #Run at 03-Aug-2014 15:08:27#
    Bee: 27
    Cocoon: 2026
    Coward: 3278
    EmoWolfWithAGun: 0
    Fox: 2677
    GordonFreeman: 611
    Gunner: 16
    HideyTwitchy: 11
    HuddleWolf: 1694
    Jack: 600
    JohnNash: 1194
    MoveRandomly: 48
    SOS: 751
    Shotguneer: 5907
    Sokie: 1233
    StandStill: 62
    SunTzu: 9
    SuperCoward: 252
    ThePriest: 173
    Vortigaunt: 107
    Waller: 276
    ZombieHater: 53
    ZombieRightsActivist: 38

    #Run at 03-Aug-2014 15:14:01#
    Bee: 26
    Cocoon: 1371
    Coward: 5121
    EmoWolfWithAGun: 0
    Fox: 3878
    GordonFreeman: 464
    Gunner: 29
    HideyTwitchy: 130
    HuddleWolf: 955
    Jack: 101
    JohnNash: 698
    MoveRandomly: 269
    SOS: 1314
    Shotguneer: 2444
    Sokie: 3217
    StandStill: 233
    SunTzu: 10
    SuperCoward: 269
    ThePriest: 318
    Vortigaunt: 266
    Waller: 494
    ZombieHater: 49
    ZombieRightsActivist: 9

    #Run at 03-Aug-2014 15:19:43#
    Bee: 25
    Cocoon: 2098
    Coward: 4855
    EmoWolfWithAGun: 0
    Fox: 4081
    GordonFreeman: 227
    Gunner: 43
    HideyTwitchy: 28
    HuddleWolf: 2149
    Jack: 1887
    JohnNash: 1457
    MoveRandomly: 117
    SOS: 1068
    Shotguneer: 4272
    Sokie: 636
    StandStill: 53
    SunTzu: 9
    SuperCoward: 209
    ThePriest: 220
    Vortigaunt: 227
    Waller: 366
    ZombieHater: 19
    ZombieRightsActivist: 49

    #Run at 03-Aug-2014 15:24:03#
    Bee: 46
    Cocoon: 682
    Coward: 3588
    EmoWolfWithAGun: 0
    Fox: 4169
    GordonFreeman: 764
    Gunner: 13
    HideyTwitchy: 21
    HuddleWolf: 842
    Jack: 1720
    JohnNash: 1260
    MoveRandomly: 259
    SOS: 636
    Shotguneer: 777
    Sokie: 586
    StandStill: 75
    SunTzu: 6
    SuperCoward: 390
    ThePriest: 189
    Vortigaunt: 208
    Waller: 334
    ZombieHater: 61
    ZombieRightsActivist: 20

    #Run at 03-Aug-2014 15:29:49#
    Bee: 90
    Cocoon: 516
    Coward: 4298
    EmoWolfWithAGun: 0
    Fox: 1076
    GordonFreeman: 581
    Gunner: 8
    HideyTwitchy: 87
    HuddleWolf: 4298
    Jack: 4715
    JohnNash: 727
    MoveRandomly: 102
    SOS: 859
    Shotguneer: 2471
    Sokie: 2471
    StandStill: 427
    SunTzu: 24
    SuperCoward: 159
    ThePriest: 359
    Vortigaunt: 94
    Waller: 398
    ZombieHater: 54
    ZombieRightsActivist: 21

    #Run at 03-Aug-2014 15:36:50#
    Bee: 18
    Cocoon: 3127
    Coward: 3124
    EmoWolfWithAGun: 0
    Fox: 5094
    GordonFreeman: 255
    Gunner: 43
    HideyTwitchy: 17
    HuddleWolf: 1078
    Jack: 272
    JohnNash: 1270
    MoveRandomly: 55
    SOS: 723
    Shotguneer: 3126
    Sokie: 1388
    StandStill: 179
    SunTzu: 7
    SuperCoward: 45
    ThePriest: 519
    Vortigaunt: 172
    Waller: 200
    ZombieHater: 45
    ZombieRightsActivist: 8

    #Run at 03-Aug-2014 15:40:59#
    Bee: 78
    Cocoon: 1834
    Coward: 4521
    EmoWolfWithAGun: 0
    Fox: 1852
    GordonFreeman: 657
    Gunner: 7
    HideyTwitchy: 2
    HuddleWolf: 969
    Jack: 895
    JohnNash: 1596
    MoveRandomly: 277
    SOS: 694
    Shotguneer: 1397
    Sokie: 844
    StandStill: 325
    SunTzu: 7
    SuperCoward: 192
    ThePriest: 148
    Vortigaunt: 369
    Waller: 232
    ZombieHater: 16
    ZombieRightsActivist: 17

    #Run at 03-Aug-2014 15:44:22#
    Bee: 23
    Cocoon: 2638
    Coward: 2269
    EmoWolfWithAGun: 0
    Fox: 2067
    GordonFreeman: 730
    Gunner: 21
    HideyTwitchy: 60
    HuddleWolf: 763
    Jack: 1469
    JohnNash: 1494
    MoveRandomly: 273
    SOS: 3181
    Shotguneer: 3181
    Sokie: 653
    StandStill: 450
    SunTzu: 19
    SuperCoward: 272
    ThePriest: 215
    Vortigaunt: 299
    Waller: 510
    ZombieHater: 62
    ZombieRightsActivist: 16

    #Run at 03-Aug-2014 15:48:03#
    Bee: 97
    Cocoon: 2009
    Coward: 2798
    EmoWolfWithAGun: 0
    Fox: 1907
    GordonFreeman: 958
    Gunner: 22
    HideyTwitchy: 93
    HuddleWolf: 925
    Jack: 288
    JohnNash: 476
    MoveRandomly: 422
    SOS: 3723
    Shotguneer: 2076
    Sokie: 1090
    StandStill: 134
    SunTzu: 92
    SuperCoward: 141
    ThePriest: 470
    Vortigaunt: 216
    Waller: 340
    ZombieHater: 32
    ZombieRightsActivist: 20

    #Run at 03-Aug-2014 16:03:38#
    Bee: 121
    Cocoon: 501
    Coward: 9704
    EmoWolfWithAGun: 0
    Fox: 3592
    GordonFreeman: 588
    Gunner: 20
    HideyTwitchy: 54
    HuddleWolf: 749
    Jack: 1245
    JohnNash: 1345
    MoveRandomly: 451
    SOS: 835
    Shotguneer: 1548
    Sokie: 589
    StandStill: 166
    SunTzu: 11
    SuperCoward: 158
    ThePriest: 93
    Vortigaunt: 246
    Waller: 1350
    ZombieHater: 18
    ZombieRightsActivist: 11

    #Run at 03-Aug-2014 16:10:24#
    Bee: 66
    Cocoon: 1809
    Coward: 3295
    EmoWolfWithAGun: 0
    Fox: 3214
    GordonFreeman: 1182
    Gunner: 15
    HideyTwitchy: 52
    HuddleWolf: 1514
    Jack: 101
    JohnNash: 745
    MoveRandomly: 211
    SOS: 862
    Shotguneer: 6335
    Sokie: 1504
    StandStill: 384
    SunTzu: 14
    SuperCoward: 259
    ThePriest: 244
    Vortigaunt: 262
    Waller: 1356
    ZombieHater: 24
    ZombieRightsActivist: 20

    #Run at 03-Aug-2014 16:28:05#
    Bee: 61
    Cocoon: 692
    Coward: 11141
    EmoWolfWithAGun: 0
    Fox: 1955
    GordonFreeman: 1234
    Gunner: 42
    HideyTwitchy: 24
    HuddleWolf: 1862
    Jack: 609
    JohnNash: 1579
    MoveRandomly: 167
    SOS: 958
    Shotguneer: 11141
    Sokie: 284
    StandStill: 422
    SunTzu: 66
    SuperCoward: 121
    ThePriest: 207
    Vortigaunt: 128
    Waller: 259
    ZombieHater: 22
    ZombieRightsActivist: 7

    #Run at 03-Aug-2014 16:32:10#
    Bee: 207
    Cocoon: 4414
    Coward: 2670
    EmoWolfWithAGun: 0
    Fox: 978
    GordonFreeman: 620
    Gunner: 19
    HideyTwitchy: 135
    HuddleWolf: 962
    Jack: 657
    JohnNash: 1200
    MoveRandomly: 147
    SOS: 687
    Shotguneer: 2258
    Sokie: 2433
    StandStill: 249
    SunTzu: 49
    SuperCoward: 1056
    ThePriest: 602
    Vortigaunt: 326
    Waller: 593
    ZombieHater: 31
    ZombieRightsActivist: 10

    #Run at 03-Aug-2014 16:38:56#
    Bee: 265
    Cocoon: 2231
    Coward: 4228
    EmoWolfWithAGun: 0
    Fox: 4737
    GordonFreeman: 532
    Gunner: 9
    HideyTwitchy: 75
    HuddleWolf: 2375
    Jack: 1237
    JohnNash: 1249
    MoveRandomly: 109
    SOS: 860
    Shotguneer: 6470
    Sokie: 1096
    StandStill: 126
    SunTzu: 15
    SuperCoward: 393
    ThePriest: 133
    Vortigaunt: 184
    Waller: 257
    ZombieHater: 32
    ZombieRightsActivist: 12

    #Run at 03-Aug-2014 16:52:16#
    Bee: 67
    Cocoon: 1534
    Coward: 9324
    EmoWolfWithAGun: 0
    Fox: 2458
    GordonFreeman: 1019
    Gunner: 24
    HideyTwitchy: 72
    HuddleWolf: 601
    Jack: 399
    JohnNash: 1366
    MoveRandomly: 275
    SOS: 506
    Shotguneer: 1007
    Sokie: 475
    StandStill: 230
    SunTzu: 135
    SuperCoward: 361
    ThePriest: 61
    Vortigaunt: 112
    Waller: 4106
    ZombieHater: 12
    ZombieRightsActivist: 22

    #Run at 03-Aug-2014 17:03:04#
    Bee: 26
    Cocoon: 1159
    Coward: 7796
    EmoWolfWithAGun: 0
    Fox: 3948
    GordonFreeman: 878
    Gunner: 3
    HideyTwitchy: 17
    HuddleWolf: 1490
    Jack: 513
    JohnNash: 1240
    MoveRandomly: 487
    SOS: 1460
    Shotguneer: 1481
    Sokie: 832
    StandStill: 457
    SunTzu: 8
    SuperCoward: 480
    ThePriest: 527
    Vortigaunt: 171
    Waller: 3729
    ZombieHater: 30
    ZombieRightsActivist: 10


  [1]: https://codegolf.stackexchange.com/questions/34833/save-the-last-bullet-for-yourself#35021
  [2]: http://s3.amazonaws.com/codegolf_zombies/0.html
  [3]: http://en.wikipedia.org/wiki/Torus#Topology
  [4]: https://github.com/jamespic/zombies/blob/master/src/main/java/zombie/PlayerContext.java
  [5]: https://github.com/jamespic/zombies/blob/master/src/main/java/player/StandStill.java
  [6]: https://github.com/jamespic/zombies/blob/master/src/main/java/player/Gunner.java
  [7]: https://github.com/jamespic/zombies/blob/master/src/main/java/zombie/Dead.java#L14
  [8]: https://github.com/jamespic/zombies/blob/master/src/main/scala/example/ScalaExample.scala
  [9]: https://github.com/jamespic/zombies/blob/master/src/main/resources/js-example.js
  [10]: https://github.com/jamespic/zombies/blob/master/src/main/resources/py-example.py
  [11]: https://github.com/jamespic/zombies/blob/master/src/main/resources/rb-example.rb
  [12]: https://github.com/jamespic/zombies/blob/master/src/main/resources/clj-example.clj
  [13]: https://github.com/jamespic/zombies/blob/master/src/main/frege/PureFregeExample.fr
  [14]: https://github.com/jamespic/zombies/blob/master/src/main/frege/IOFregeExample.fr
  [15]: http://s3.amazonaws.com/codegolf_zombies/0.html