generated from BattlesnakeOfficial/starter-snake-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
49 lines (43 loc) · 1.46 KB
/
app.rb
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
require 'rack'
require 'rack/contrib'
require 'sinatra'
require './app/util'
require './app/move'
use Rack::PostBodyContentTypeParser
# This function is called when you register your Battlesnake on play.battlesnake.com
# It controls your Battlesnake appearance and author permissions.
# TIP: If you open your Battlesnake URL in browser you should see this data
get '/' do
appearance = {
apiversion: "1",
author: "ChaelCodes",
color: "#E95678",
head: "evil",
tail: "hook",
}
camelcase(appearance).to_json
end
# This function is called everytime your snake is entered into a game.
# rack.request.form_hash contains information about the game that's about to be played.
# TODO: Use this function to decide how your snake is going to look on the board.
post '/start' do
request = underscore(env['rack.request.form_hash'])
puts "START"
"OK\n"
end
# This function is called on every turn of a game. It's how your snake decides where to move.
# Valid moves are "up", "down", "left", or "right".
# TODO: Use the information in rack.request.form_hash to decide your next move.
post '/move' do
request = underscore(env['rack.request.form_hash'])
# Implement move logic in app/move.rb
response = move(request)
content_type :json
camelcase(response).to_json
end
# This function is called when a game your Battlesnake was in ends.
# It's purely for informational purposes, you don't have to make any decisions here.
post '/end' do
puts "END"
"OK\n"
end