-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathsolution.js
173 lines (152 loc) · 4.91 KB
/
solution.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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
'use strict'; /*jslint node:true*/
module.exports = class Agent {
constructor(me, counts, values, max_rounds, log){
this.counts = counts;
this.values = values;
this.rounds = max_rounds;
this.max_rounds = max_rounds;
this.me = me;
this.log = log;
this.total = 0;
this.variant = 0;
this.skidka_full = 0;
this.maxValue = 0;
this.maxValueCount = -1;
this.maxValueI = -1;
this.variant_mass_uje = new Array (counts.length);
this.contr_variant = this.counts.slice();
for (let i = 0; i<counts.length; i++)
{
this.variant_mass_uje[i] = counts[i];
this.total += counts[i]*values[i]; ;
if (this.values[i] > 0)
{
this.contr_variant[i] = 0;
this.variant_mass_uje[i] = 0;
if((this.values[i] > this.maxValue) && ((this.values[i] * this.counts[i]) <=7 ))
{
this.maxValue = this.values[i];
this.maxValueCount = this.counts[i];
this.maxValueI = i;
}
}
}
}
offer(o){
this.log(`${this.rounds} rounds left~~~`);
this.rounds--;
let sum;
let contr_sum;
let mne_pred;
if (o)
{
sum = 0;
mne_pred = o.slice();
for (let i = 0; i<o.length; i++)
{
sum += this.values[i]*o[i];
}
if (sum > this.variant)
{
this.variant = sum;
for (let i = 0; i<o.length; i++)
{
this.contr_variant[i] = o[i];
}
}
var skidka_raschetnaya =this.total - this.total*((this.max_rounds - this.rounds - 1)/(this.max_rounds + this.me + 1));
if(this.me == 1) {skidka_raschetnaya = skidka_raschetnaya - 1;}
let uslovie51 = (this.me == 0);
let uslovie52 = (this.rounds == 0);
let uslovie55 = ( uslovie51 && uslovie52 && (sum >= this.total * 0.37));
let uslovie1 = (sum >= 0.75 * this.total) && ((this.rounds + 1) < this.max_rounds );
let uslovie2 = (sum > 0 && this.me == 1 && this.rounds == 0);
let uslovie3 = (sum >= skidka_raschetnaya);
let uslovie4 = (sum >= 0.9 * this.total) && ((this.rounds + 1) == this.max_rounds );
if (uslovie1 || uslovie2 || uslovie3 || uslovie4 || uslovie55)
{
return;
}
}
else
{
o = this.counts.slice();
for (let i = 0; i<o.length; i++)
{
if (!this.values[i])
o[i] = 0;
}
return o;
}
if (this.rounds >= 0)
{
contr_sum = 0;
let flag_skidki = 0;
for (let i = 0; i<o.length; i++)
{
let uslovie23 = (flag_skidki == 0);
let uslovie24 = ((this.values[i]+ this.skidka_full) <= (this.total - skidka_raschetnaya));
let uslovie22 = (this.counts[i] > this.variant_mass_uje[i]);
let uslovie21 = (! (mne_pred[i] > this.variant_mass_uje[i]) );
if (uslovie21 && uslovie22 && uslovie23 && uslovie24)
{
flag_skidki = 1;
let skidkaFull = this.skidka_full;
let variantMassUje = this.variant_mass_uje[i];
while((skidkaFull < (this.total - skidka_raschetnaya))&& (variantMassUje < this.counts[i]))
{
variantMassUje = variantMassUje + 1;
skidkaFull =this.skidka_full + (this.values[i] * (variantMassUje +1 ));
if(skidkaFull <= (this.total - skidka_raschetnaya))
{
variantMassUje = variantMassUje + 1;
}
}
this.variant_mass_uje[i] = variantMassUje;
this.skidka_full = this.skidka_full + (this.values[i] * this.variant_mass_uje[i]);
}
o[i] = this.counts[i] - this.variant_mass_uje[i];
let uslovie71 = (o[i] < mne_pred[i]);
if(uslovie71)
{
o[i] = mne_pred[i];}
contr_sum = contr_sum + this.variant_mass_uje[i] * this.values[i];
}
}
if(contr_sum > 0)
{
if(sum >= (this.total - contr_sum)) return;
}
let uslovie61 = (this.me == 0);
let uslovie62 = (this.rounds == 0);
let uslovie63 = (this.variant > 0);
let uslovie64 = (this.variant < this.maxValue * this.maxValueCount);
if (uslovie61 && uslovie62 && uslovie63 && !uslovie64)
{
o = this.contr_variant.slice();
}
if (uslovie61 && uslovie62 && !uslovie63 && !uslovie64)
{
o = this.counts.slice();
contr_sum = 0;
for (let i = 0; i<o.length; i++)
{
if (!this.values[i])
o[i] = 0;
contr_sum =contr_sum + o[i]*this.values[i];
}
}
if (uslovie61 && uslovie62 && !uslovie63 && uslovie64)
{
o = this.counts.slice();
contr_sum = 0;
for (let i = 0; i<o.length; i++)
{
if (!this.values[i]) o[i] = 0;
if(i == this.maxValueI) o[i] = 0;
contr_sum =contr_sum + o[i]*this.values[i];
}
}
return o;
}
};