forked from derrickchwong/cloud-run-hackathon-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.js
75 lines (60 loc) · 1.96 KB
/
web.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
app.use(bodyParser.json());
app.get("/", function (req, res) {
res.send("Let the battle begin!");
});
const shootOrTurn = () => {};
let count = 0;
app.post("/", function (req, res) {
console.log(JSON.stringify(req.body));
const moves = ["F", "T", "L", "R"];
// const dims = req.body.arena.dims;
// const states = req.body.arena.state;
// const me =
// states["https://cloud-run-hackathon-nodejs-nnwktxrvja-uc.a.run.app"];
// console.log("ME");
// console.log(me);
// delete states["https://cloud-run-hackathon-nodejs-nnwktxrvja-uc.a.run.app"];
// console.log(states);
// const stateArr = Object.values(states);
// console.log(stateArr);
// let xmap = [];
// let ymap = [];
// if (me.direction == "N" || me.direction == "S") {
// for (let i = 0; i < stateArr.length; i++) {
// const state = stateArr[i];
// if (me.y == state.y) {
// xmap.push(state.x - me.x);
// }
// if (me.x == state.x) {
// ymap.push(state.y - me.y);
// }
// }
// } else {
// for (let i = 0; i < stateArr.length; i++) {
// const state = stateArr[i];
// if (me.y == state.y) {
// xmap.push(state.x - me.x);
// }
// if (me.x == state.x) {
// ymap.push(state.y - me.y);
// }
// }
// }
// const xs = stateArr.map((state) => state.x);
// const ys = stateArr.map((state) => state.y);
// console.log(xs.sort());
// console.log(ys.sort());
// const state = getShortestState(states);
// TODO add your implementation here to replace the random response
if (count < 5) {
count++;
res.send("T");
} else {
count = 0;
res.send("R");
}
});
app.listen(process.env.PORT || 8080);