-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparse.ts
62 lines (53 loc) · 1.27 KB
/
parse.ts
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
'use strict';
import * as fs from 'fs';
import * as readline from 'readline';
import { Bot } from './bot';
const clc = require('cli-color')
const reader = readline.createInterface(fs.createReadStream(process.argv[2]))
console.log(clc.bgYellow(clc.black('Running sim...')))
const bot = new Bot();
reader.on('line', (l: string) => {
if (l.length === 0) {
return;
}
const commands = l.split(' ');
const cmd = commands[0];
if (cmd === 'PLACE') {
if (commands.length === 2) {12
const params = commands[1].split(',');
if (params.length === 3) {
const x = Number(params[0]);
const y = Number(params[1]);
const d = params[2].toString().toLowerCase();
bot.place(x, y, d);
}
} else {
console.log('Invalid place command.', commands);
}
} else {
if (bot) {
switch (cmd) {
case 'MOVE': {
bot.move();
break;
}
case 'REPORT': {
bot.report();
break;
}
case 'LEFT': {
bot.left();
break;
}
case 'RIGHT': {
bot.right();
break;
}
default: break;
}
}
}
});
reader.on('close', () => {
console.log(clc.bgYellow(clc.black('Finished running sim...')));
});