-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (29 loc) · 948 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
var express = require('express');
var app = express();
// app.js
var http = require('http'),
fs = require('fs'),
express = require('express'),
bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
var chess = require("./chess");
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
app.get('/', function(request, response) {
response.send(chess.oppositeColor("white"));
})
app.post('/get-move', function(request, response) {
console.log(request.body.board);
var board = chess.getBoardFromHash(request.body.board);
var turn = request.body.turn;
chess.printBoard(board);
var move = chess.getBestMove(turn, board);
response.send('{"move": "' + move + '"}');
})
app.listen(app.get('port'), function() {
console.log("Node app is running at localhost:" + app.get('port'))
})