-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode4life.js
More file actions
158 lines (149 loc) · 5.31 KB
/
code4life.js
File metadata and controls
158 lines (149 loc) · 5.31 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/**
* Bring data on patient samples from the diagnosis machine to the laboratory with enough molecules to produce medicine!
**/
var read = ()=>readline().split(' '),
pos=a=>+a>0?+a:0,
abcde = (a,b,c,d,e)=>({
a:pos(a),b:pos(b),c:pos(c),d:pos(d),e:pos(e),
tot:function(){return this.a+this.b+this.c+this.d+this.e;},
firstPos:function(){
var r = false;
if(this.e>0) r='e';
if(this.d>0) r='d';
if(this.c>0) r='c';
if(this.b>0) r='b';
if(this.a>0) r='a';
return r;
}
}),
difabcde=(a,b)=>abcde(a.a-b.a,a.b-b.b,a.c-b.c,a.d-b.d,a.e-b.e),
minabcde=(a,b)=>abcde(Math.min(a.a,b.a),Math.min(a.b,b.b),Math.min(a.c,b.c),Math.min(a.d,b.d),Math.min(a.e,b.e)),
readArr=(func)=>[...Array(+readline())].map(a=>func()),
robot = ()=>{
var t,e,s,sa,sb,sc,sd,se,ea,eb,ec,ed,ee;
[t,e,s,sa,sb,sc,sd,se,ea,eb,ec,ed,ee] = read();
return {
target:t,
eta: +e,
score:+s,
storage:abcde(sa,sb,sc,sd,se),
expertise:abcde(ea,eb,ec,ed,ee)
};
},
rabcde=()=>abcde(...read()),
sample= ()=>{
var sid,prop,rank,exp,health,a,b,c,d,e;
[sid,prop,rank,exp,health,a,b,c,d,e]=read();
return {
id:+sid,
prop:+prop,
rank:+rank,
exp:exp,
health:+health,
cost:abcde(a,b,c,d,e)
};
},
modules={diag:'DIAGNOSIS',mol:'MOLECULES',lab:'LABORATORY'},
readGame = ()=>{
return {
me:robot(),
other:robot(),
availlables:rabcde(),
samples:readArr(sample),
filtSample:function(prop){return this.samples.filter(s=>s.prop===prop)},
carSample:function(){var s=this.filtSample(0);return s.length>0?s[0]:false},
availSamples:function(){return this.filtSample(-1)}
};
},
goto=(mod)=>print('GOTO',mod),
connect=(o)=>print('CONNECT',(''+o).toUpperCase()),
debug=(o)=>printErr(JSON.stringify(o));
// Init
var projects = readArr(rabcde);
// game loop
while (true) {
// for (var i = 0; i < 2; i++) {
// var inputs = readline().split(' ');
// var target = inputs[0];
// var eta = parseInt(inputs[1]);
// var score = parseInt(inputs[2]);
// var storageA = parseInt(inputs[3]);
// var storageB = parseInt(inputs[4]);
// var storageC = parseInt(inputs[5]);
// var storageD = parseInt(inputs[6]);
// var storageE = parseInt(inputs[7]);
// var expertiseA = parseInt(inputs[8]);
// var expertiseB = parseInt(inputs[9]);
// var expertiseC = parseInt(inputs[10]);
// var expertiseD = parseInt(inputs[11]);
// var expertiseE = parseInt(inputs[12]);
// }
// var inputs = readline().split(' ');
// var availableA = parseInt(inputs[0]);
// var availableB = parseInt(inputs[1]);
// var availableC = parseInt(inputs[2]);
// var availableD = parseInt(inputs[3]);
// var availableE = parseInt(inputs[4]);
// var sampleCount = parseInt(readline());
// for (var i = 0; i < sampleCount; i++) {
// var inputs = readline().split(' ');
// var sampleId = parseInt(inputs[0]);
// var carriedBy = parseInt(inputs[1]);
// var rank = parseInt(inputs[2]);
// var expertiseGain = inputs[3];
// var health = parseInt(inputs[4]);
// var costA = parseInt(inputs[5]);
// var costB = parseInt(inputs[6]);
// var costC = parseInt(inputs[7]);
// var costD = parseInt(inputs[8]);
// var costE = parseInt(inputs[9]);
// }
// Write an action using print()
// To debug: printErr('Debug messages...');
var game = readGame();
//printErr(JSON.stringify(game));
var carSample = game.carSample(),
target = game.me.target;
if(!carSample){
if(target != modules.diag){
goto(modules.diag);
}else{
var samps = game.availSamples().sort((a,b)=>b.health-a.health);
if(samps.length >0){
connect(samps[0].id);
}else{
//what to do here ???
printErr("no sample to take :(")
goto(modules.diag);
}
}
}else{
//carSample ok
var need = difabcde(carSample.cost,game.me.storage),
totneed = need.tot();
debug(need);
debug(totneed);
if(totneed >0){
if(target != modules.mol){
goto(modules.mol);
}else{
var needAndAvail = minabcde(need,game.availlables),
toTake = needAndAvail.firstPos();
debug(needAndAvail);
debug(toTake);
if(toTake !== false){
connect(toTake);
}else{
printErr("nothing to take :(");
goto(modules.diag);
}
}
}else{
if(target != modules.lab){
goto(modules.lab);
}else{
connect(carSample.id);
}
}
}
}