-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (33 loc) · 824 Bytes
/
index.js
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
const express = require('express');
const Board = require('./board');
const Move = require('./move');
const Avoid = require('./avoid');
const TowardsFood = require('./towardsFood');
const app = express();
app.use(express.json());
app.get('/', function (req, res) {
res.json({
apiversion: "1"
});
})
app.post('/start', function (req, res) {
res.json();
})
app.post('/move', function (req, res) {
const id = req.body.you.id.substr(-4);
const head = req.body.you.head;
const board = Board(req.body.board);
const food = req.body.board.food;
const towardsFood = new TowardsFood(head, food);
res.json({
move: Move(
Avoid(head, board, req.body.board.snakes),
towardsFood.towards(),
id
)
});
})
app.post('/end', function (req, res) {
res.json();
})
app.listen(443);