Skip to content

redevined/Snakepit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Food shortage in the Snakepit

For the first time in 35 years, the snakepit is running out of food. The inhabitant snakes now have to fight each other in order to survive this food shortage. Only one snake can stand at the top of the food chain!


Leaderboard

Not here yet!

Last update on February, 24th

Link to visualizations of last matches


Description

If you want to fight for the last remaining apples/cherries/whatever, you have to provide a snake in form of a program that accepts a given input and returns its next move.

The only twist is that you're not alone in your pit. Another snake will try to get the rare food too! But it's dark inside the snakepit so you can only see yourself and the apple. Crashing into your opponent will result in your death, just like biting yourself or hitting a wall. Additionally, because apples are rare these days, you starve if your opponent ate enough to reach a length of 7.

The snakepit is a two-dimensional map with a width and height of 15, while the outermost tiles build an impassable wall:

  0 1 2 . . . c d e
0 # # # # # # # # #
1 #               #
2 #           x   #
. #               #
. #               #
. #               #
c #               #
d #               #
e # # # # # # # # #

Coordinates are zero-indexed, so the point where the x is would be 12,2.

Your bot will be called with two arguments:

  • The location of the food
  • The locations of your body segments, separated by /

It should then write one of the following to stdout:

  • L for a quarter left turn as its next move
  • R for a quarter right turn
  • Anything else for a move in the same direction

Example:

Projects/Snakepit> python bot.py 12,2 4,8/4,9/3,9/2,9
'R'
Projects/Snakepit>

Rules

Your bot is allowed to:

  • Output anything, because anything is a valid move
  • Read/write files in its own directory which is located under ./snakes/ThisIsYourSnake
  • Run on Ubuntu 14.04 and Windows 7 (it actually has to)

Your bot must not:

  • Read/write files outside its own directory
  • Use external resources such as the internet
  • Have a runtime above 10 seconds per execution

You have to provide in your answer:

  • The source code of the bot
  • A bot/snake name
  • (Your own name)
  • A command to run your bot

If you want to make my life easier, please provide a line like CoolSnake MyOwnName python bot.py.


Scoring

Your snake gets a point for winning a game against another snake. A game is won under the following circumstances:

  • Your opponent hits himself, you or a wall
  • You reach length 7

Additionally, both snakes starve after 200 cycles.

Each snake will fight 10 matches for their survival against each other snake.


Example Bots

Just to give you an idea, I'll provide these two (participating) example snakes:

SneakySnake

#!/usr/bin/env python

import sys, random

def main(food, me) :
    food = [int(i) for i in food.split(",")]
    me = [[int(i) for i in seg.split(",")] for seg in me.split("/")]
    head = me[0]
    v = [head[0] - me[1][0], head[1] - me[1][1]]

    if food[0] < head[0] :
        vn = [-1, 0]
    elif food[0] > head[0] :
        vn = [1, 0]
    elif food[0] == head[0] :
        if food[1] < head[1] :
            vn = [0, -1]
        elif food[1] > head[1] :
            vn = [0, 1]

    if v == vn :
        return "..."
    elif [-v[1], v[0]] == vn :
        return "R"
    elif [v[1], -v[0]] == vn :
        return "L"
    else :
        return random.choice(("R", "L"))

if __name__ == "__main__" :
    print main(*sys.argv[1:3])

SneakySnake Cipher python bot.py

ViciousViper

#!/usr/bin/env python

import sys, random

def main(food, me) :
    food = [int(i) for i in food.split(",")]
    me = [[int(i) for i in seg.split(",")] for seg in me.split("/")]
    head = me[0]
    v = [head[0] - me[1][0], head[1] - me[1][1]]
    vn = [food[0] - head[0], food[1] - head[1]]
    if 0 not in vn :
        vn[v.index(0)-1] = 0
    vn[vn.index(0)-1] = vn[vn.index(0)-1] / abs(vn[vn.index(0)-1])

    if v == vn :
        return "..."
    elif [v[0] + vn[0], v[1] + vn[1]] == [0, 0] :
        return random.choice(("R", "L"))
    else :
        return "R" if [-v[1], v[0]] == vn else "L"

if __name__ == "__main__" :
    print main(*sys.argv[1:3])

ViciousViper Cipher python bot.py

And their matches:

Example match 1 Example match 2 Example match 3


Control program

You can find the control program on github, along with all bots and records of past matches.

Requirements:

  • Python 2 + the libraries numpy and pillow (you can check if they are present via python -c "import numpy, PIL", if it throws errors, the modules are missing)
  • Copying the full folder structure is required in order for the controller to work
  • Register your bot(s) in the ./snakes/list.txt file in the style of CoolSnake MyOwnName Command To Run My Bot
  • Place your bot inside a directory with its name under ./snakes
  • Neither your, nor your bot's name is allowed to contain whitespaces!

Usage:

python run.py [-h] [-n int] [-s int] [-l int] [-c int] [-g]

python run.py will run the tournament with all bots registered in list.txt and the standard properties. Advanced options are:

  • -h displays a help message
  • -n int rounds of battles for each combination of opponents
  • -s int determines the size of the grid (width and height)
  • -l int sets the required length to win
  • -c int sets the limit of cycles
  • -g or --no-gifs creates no gifs of the matches

About

Snakepit tournament for Stack Exchange KOTH

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages