-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.go
53 lines (44 loc) · 1.13 KB
/
routes.go
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
package main
import (
"log"
"net/http"
"github.com/zacpez/scape-goat/api"
"github.com/zacpez/scape-goat/snake"
)
// Index thing
func Index(res http.ResponseWriter, req *http.Request) {
res.WriteHeader(http.StatusOK)
res.Write([]byte("Battlesnake documentation can be found at <a href=\"https://docs.battlesnake.io\">https://docs.battlesnake.io</a>."))
}
// Start thing
func Start(res http.ResponseWriter, req *http.Request) {
decoded := api.SnakeRequest{}
err := api.DecodeSnakeRequest(req, &decoded)
if err != nil {
log.Printf("Bad start request: %v", err)
}
dump(decoded)
respond(res, api.StartResponse{
Color: "#69604D",
})
}
// Move thing
func Move(res http.ResponseWriter, req *http.Request) {
decoded := api.SnakeRequest{}
err := api.DecodeSnakeRequest(req, &decoded)
if err != nil {
log.Printf("Bad move request: %v", err)
}
var direction = snake.ComputeDirection(&decoded.You, &decoded.Board)
respond(res, api.MoveResponse{
Move: string(direction),
})
}
// End thing
func End(res http.ResponseWriter, req *http.Request) {
return
}
// Ping thing
func Ping(res http.ResponseWriter, req *http.Request) {
return
}