-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (39 loc) · 1.06 KB
/
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
41
42
43
44
45
46
const colors = require('colors');
const { ENV, TIME} = require('./config');
const Bot = require('./bot');
const { generate } = require('./env');
const { sleep } = require('./utils');
let currentSize = ENV.STARTING_SIZE;
let level = currentSize;
let score = 0;
const main = async () => {
const forest = generate(currentSize);
const bot = new Bot(forest, score);
const res = await think(bot);
if (res) { // agent escaped
console.log(("WON ! GOING TO LEVEL:" + level).green);
await sleep(TIME.RECAP_DISPLAY);
score += bot._score;
level++;
currentSize++;
await main();
} else { // agent died
console.log("LOST ! GOING TO A NEW GAME".red);
/* resetting default values */
score = 0;
currentSize = ENV.STARTING_SIZE;
level = currentSize;
await sleep(TIME.AFTER_GAME_LOST);
await main();
}
};
/* launches the agent */
const think = async (bot) => {
let res = null;
while(res === null || typeof res === "undefined") {
await sleep(TIME.BETWEEN_PLAYS);
res = await bot.think();
}
return res;
};
main();