-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
73 lines (61 loc) · 1.9 KB
/
main.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
const Ai = require('./src/ai');
const Match = require('./src/match');
const fs = require('fs');
const chance = new require('chance')();
const mp = require('./mp');
const extend = require('extend');
const express = require('express');
const app = express();
const http = require('http').Server(app);
const io = require('socket.io')(http);
const configName = process.argv[2];
let config = require('./config/' + configName);
config = extend({
port: 8674,
ais: [],
}, config);
console.log(config);
app.use('/bower_components', express.static('bower_components'))
app.get('/angular', function(req, res) {
res.sendFile(__dirname + '/ui/angular.html');
});
app.get('/basic', function(req, res) {
res.sendFile(__dirname + '/ui/basic.html');
});
io.on('connection', function(socket){
console.log('Socket connected');
});
http.listen(config.port, function() {
console.log('Listening on *:' + config.port);
});
let match = new Match('daves_test_game');
let ais = [];
for (let i = 0; i < config.ais.length; i++) {
let ai = new Ai('daves_test_bot_' + i, config.ais[i].name, config.ais[i].mode, config.ais[i].strategy, __dirname + '/data/history-' + configName + '-' + i + '.json', mp.fork({
worker: 'calculate-paths',
}));
ai.joinMatch(match);
ais.push(ai);
}
setTimeout(() => {
for (let i = 0; i < ais.length; i++) {
ais[i].forceStart(match);
}
}, 2000);
// how many units can get where in how many steps
// updaet finish him to check clost distance and if there is enough units in path
// 2v2
// flood fill if stalemate
// combine if biggest stack next to another stack that is > averge
// 2 squads, one defends, one epxands to get free cells
setInterval(() => {
io.emit('data', ais.map(ai => ai.state));
for (let i = 0; i < ais.length; i++) {
if (!ais[i].finished) {
return;
}
}
if (ais.length > 0) {
process.exit();
}
}, 500);