-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
60 lines (48 loc) · 1.34 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
import cherrypy
from snake import Battlesnake
"""
This is a simple Battlesnake server written in Python.
For instructions see https://github.com/BattlesnakeOfficial/starter-snake-python/README.md
"""
class Server(object):
@cherrypy.expose
@cherrypy.tools.json_out()
def index(self):
snake = Battlesnake()
return {
"apiversion": snake.apiversion,
"author": snake.author,
"version": snake.version,
"color": snake.color,
"head": snake.head,
"tail": snake.tail,
}
@cherrypy.expose
@cherrypy.tools.json_in()
def start(self):
print("START")
return "ok"
@cherrypy.expose
@cherrypy.tools.json_in()
@cherrypy.tools.json_out()
def move(self):
data = cherrypy.request.json
move = Battlesnake().move(data)
return {"move": move}
@cherrypy.expose
@cherrypy.tools.json_in()
def end(self):
print("END")
return "ok"
if __name__ == "__main__":
server = Server()
# cherrypy.log.screen = None
cherrypy.config.update({"server.socket_host": "0.0.0.0"})
cherrypy.config.update(
{
"server.socket_port": int(os.environ.get("PORT", "8080")),
}
)
print("Starting Battlesnake Server...")
cherrypy.quickstart(server)