forked from maxluetkemeyer/informatiCup-2021-luceki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tacticController.js
96 lines (86 loc) · 2.24 KB
/
tacticController.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//npm
// eslint-disable-next-line no-unused-vars
import * as colors from "colors";
//imports
import {sendTacticData} from "./monitoring/monitoring";
//tactic imports
import exampleTactic from "./tactics/exampleTactic";
import dontHit from "./tactics/dontHit/dontHit";
import dontHitRandom from "./tactics/dontHit/dontHitRandom";
import dontHitSemiRandom from "./tactics/dontHit/dontHitSemiRandom";
import recursiveBnB from "./tactics/recursiveBnB/recursiveBnB";
import dangerFields from "./tactics/dangerFields/dangerFields";
import tfModels from "./tactics/tfModels/tfModels";
export default class tacticController{
/**
* Constructor of tacticController
*/
constructor(){
this.tactic;
this.alreadyInit = false;
this.move = "";
}
/**
* gets nextMove from active tactic
* @param {object} gameData
*/
async nextMove(gameData){
//update gameData
this.tactic.updateGameData(gameData);
if(!this.alreadyInit){
this.tactic.init();
this.alreadyInit = true;
}
//calculate next Move
const startCalcTime = new Date().getTime();
this.move = await this.tactic.nextMove();
const calcTime = (new Date().getTime())-startCalcTime;
const data = {
dataToSend: this.tactic.dataToSend,
calcTime
};
sendTacticData(data);
this.tactic.lastMove = this.move;
const tacticMsg = "[TC]: " + this.move;
console.log(tacticMsg.green.bold);
return this.move;
}
/**
* activates the given tactic
* @param {object} options
*/
init(options){
this.alreadyInit = false;
console.log("[TC]: Using "+options.tactic);
switch (options.tactic) {
case "exampleTactic":
this.tactic = new exampleTactic();
break;
case "recursiveBnB":
this.tactic = new recursiveBnB(options);
break;
case "dontHit":
this.tactic = new dontHit(options);
break;
case "dontHitRandom":
this.tactic = new dontHitRandom();
break;
case "dontHitSemiRandom":
this.tactic = new dontHitSemiRandom();
break;
case "dangerFields":
this.tactic = new dangerFields(options);
break;
case "tfModels":
this.tactic = new tfModels(options);
break;
}
this.tactic.setServerTimeDiff(options.time_url);
}
/**
* Returns the name of the active tactic
*/
getActiveName(){
return this.tactic.name;
}
}