-
Notifications
You must be signed in to change notification settings - Fork 0
/
mechanic.h
796 lines (705 loc) · 24.3 KB
/
mechanic.h
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
#ifndef MECHANIC_H
#define MECHANIC_H
#include <functional>
#include <map>
#include <set>
#include <list>
#include <array>
#include "logger.h"
#include "entities/food.h"
#include "entities/virus.h"
#include "entities/player.h"
#include "entities/ejection.h"
#include "strategies/strategy.h"
typedef std::function<void(double, double)> AddFunc;
typedef std::function<Strategy*(Player*)> StrategyGet;
struct t_burst_hack{
int pId=-1;
int n=0;
bool need_sim_without_burst=false;
};
struct t_score_hack{
int pId=-1;
int n=0;
bool need_ignore_food=false;
};
struct Mechanic{
int tick;
int id_counter;
t_burst_hack burst_hack;
t_score_hack score_hack;
typedef Player MechPlayer;
t_foodmap*pfoodmap=nullptr;
FoodArray food_array;
EjectionArray eject_array;
VirusArray virus_array;
PlayerArray player_array;
StrategyArray strategy_array;
QMap<int, Direct> strategy_directs;
QMap<int, int> player_scores;
std::mt19937_64 rand;
Mechanic(const Mechanic&){QapNoWay();}
public:
explicit Mechanic() :
tick(0),
id_counter(1)
{}
virtual ~Mechanic() {
clear_objects(false);
}
public:
double get_max_TTF()const{
return Constants::instance().TICKS_TIL_FUSION;
}
public:
typedef QMap<int,Direct> QMap_int_Direct;
typedef QMap<int,int> QMap_int_int;
#define F(TYPE)static void clone(TYPE&dest,const TYPE&src){dest=src;}
F(int);F(double);F(bool);F(QMap_int_Direct);F(QMap_int_int);
#undef F
template<class TYPE>
static void clone(vector<TYPE*>&dest,vector<TYPE*>&src){
dest.resize(src.size());
for(int i=0;i<src.size();i++){
auto&ex=dest[i];
ex=new TYPE(*src[i]);
//*ex=src[i];
}
}
void fork_from(Mechanic&src)
{
#define F(FIELD)clone(this->FIELD,src.FIELD);
F(tick);
F(id_counter);
F(food_array);
F(eject_array);
F(virus_array);
F(player_array);
F(strategy_array);
F(strategy_directs);
F(player_scores);
#undef F
}
public:
void init_objects(const std::string &seed, const StrategyGet &get_strategy) {
std::seed_seq seq(seed.begin(), seed.end());
rand.seed(seq);
std::array<uint, 1> simple_seeds;
seq.generate(simple_seeds.begin(), simple_seeds.end());
srand(simple_seeds[0]); // на всякий случай, если вдруг где-то когда-то будет использоваться обычный rand().
// он используется, например, в умолчальной стратегии
//logger->init_file(QString::number(simple_seeds[0]), LOG_FILE, false);
add_player(START_PLAYER_SETS, get_strategy);
add_food(START_FOOD_SETS);
add_virus(START_VIRUS_SETS);
}
void clear_objects(bool with_log=true) {
tick = 0;
id_counter = 1;
for (Food *food : food_array) {
if (food) delete food;
}
food_array.clear();
for (Ejection *eject : eject_array) {
if (eject) delete eject;
}
eject_array.clear();
for (Virus *virus : virus_array) {
if (virus) delete virus;
}
virus_array.clear();
for (Player *player : player_array) {
if (player) delete player;
}
player_array.clear();
/*for (Strategy *strategy : strategy_array) {
if (strategy) delete strategy;
}*/
strategy_array.clear();
}
int tickEvent_v2(bool inside_sim=false) {
if(!inside_sim)apply_strategies();
tick++;
move_moveables();
player_ejects();
player_splits();
if (tick % SHRINK_EVERY_TICK == 0) {
shrink_players();
}
eat_all();
fuse_players();
burst_on_viruses();
update_players_radius();
split_viruses();
if(!inside_sim)
{
if (tick % ADD_FOOD_DELAY == 0 && food_array.size() < MAX_GAME_FOOD) {
add_food(ADD_FOOD_SETS);
}
if (tick % ADD_VIRUS_DELAY == 0 && virus_array.size() < MAX_GAME_VIRUS) {
add_virus(ADD_VIRUS_SETS);
}
}
if (tick % Constants::instance().BASE_TICK == 0) {
//write_base_tick();
}
strategy_directs.clear();
return tick;
}
bool known() const {
QapNoWay();return false;
/*
QVector<int> livingIds;
for (Player *player : player_array) {
int pId = player->getId();
if (! livingIds.contains(pId)) {
livingIds.append(pId);
}
}
if (livingIds.length() == 0) {
return true;
}
else if (livingIds.length() == 1) {
int living_score = player_scores[livingIds[0]];
for (int pId : player_scores.keys()) {
if (pId != livingIds[0] && player_scores[pId] >= living_score) {
return false;
}
}
return true;
}
return false;*/
}
public:
bool is_space_empty(double _x, double _y, double _radius) const {
for (Player *player : player_array) {
if (player->is_intersected(_x, _y, _radius)) {
return false;
}
}
for (Virus *virus : virus_array) {
if (virus->is_intersected(_x, _y, _radius)) {
return false;
}
}
return true;
}
public:
#define append push_back
void add_circular(int sets_cnt, double one_radius, const AddFunc &add_one) {
double center_x = Constants::instance().GAME_WIDTH / 2, center_y = Constants::instance().GAME_HEIGHT / 2;
for (int I = 0; I < sets_cnt; I++) {
double _x = rand() % qCeil(center_x - 4 * one_radius) + 2 * one_radius;
double _y = rand() % qCeil(center_y - 4 * one_radius) + 2 * one_radius;
add_one(_x, _y);
add_one(center_x + (center_x - _x), _y);
add_one(center_x + (center_x - _x), center_y + (center_y - _y));
add_one(_x, center_y + (center_y - _y));
}
}
void add_food(int sets_cnt) {
add_circular(sets_cnt, FOOD_RADIUS, [=] (double _x, double _y) {
Food *new_food = new Food(id_counter, _x, _y, FOOD_RADIUS, Constants::instance().FOOD_MASS);
food_array.append(new_food);
id_counter++;
if (tick % Constants::instance().BASE_TICK != 0) {
//logger->write_add_cmd(tick, new_food);
}
});
}
void add_virus(int sets_cnt) {
double rad = Constants::instance().VIRUS_RADIUS;
add_circular(sets_cnt, rad, [=] (double _x, double _y) {
if (! is_space_empty(_x, _y, rad)) {
return;
}
Virus *new_virus = new Virus(id_counter, _x, _y, rad, VIRUS_MASS);
virus_array.append(new_virus);
id_counter++;
if (tick % Constants::instance().BASE_TICK != 0) {
//logger->write_add_cmd(tick, new_virus);
}
});
}
void add_player(int sets_cnt, const StrategyGet &get_strategy) {
bool by_mouse = true;
add_circular(sets_cnt, PLAYER_RADIUS, [=, &by_mouse] (double _x, double _y) {
if (! is_space_empty(_x, _y, PLAYER_RADIUS)) {
return;
}
Player *new_player = new Player(id_counter, _x, _y, PLAYER_RADIUS, PLAYER_MASS);
player_array.append(new_player);
new_player->update_by_mass(Constants::instance().GAME_WIDTH, Constants::instance().GAME_HEIGHT);
#ifdef LOCAL_RUNNER
Strategy *new_strategy = get_strategy(new_player);
strategy_array.append(new_strategy);
#endif
player_scores[id_counter] = 0;
id_counter++;
if (tick % Constants::instance().BASE_TICK != 0) {
//logger->write_add_cmd(tick, new_player);
}
});
}
template<class TYPE>
static void delete_if_eq(vector<TYPE*>&arr,TYPE*ptr,bool dont=false){
auto func=[&](TYPE*ex)
{
auto out=ptr==ex;
if(!dont)if(out&&ex){
delete ex;
}
return out;
};
clean_if(arr,func);
}
template<class TYPE>
static void delete_if_eq(std::set<TYPE*>&arr,TYPE*ptr){
auto it=arr.find(ptr);
arr.erase(it);
delete ptr;
}
public:
PlayerArray get_players_by_id_v2_deprecated_for_highload(int pId) const {
PlayerArray result;
for (Player *player : player_array) {
if (player->getId() == pId) {
if(!result.capacity())result.reserve(player_array.size());
result.append(player);
}
}
return result;
}
void get_players_by_id_v3(PlayerArray&out,int pId) const {
out.clear();
for (Player *player : player_array) {
if (player->getId() == pId) {
out.append(player);
}
}
}
template<class FUNC>
void foreach_players(int pId,FUNC func) const {
for (Player *player : player_array) {
if (player->getId() == pId) {
func(player);
}
}
}
PlayerArray get_players_by_id_deprecated(int pId) const {
PlayerArray result;
for (Player *player : player_array) {
if (player->getId() == pId) {
result.append(player);
}
}
return result;
}
int get_fragments_cnt(int pId) const {
int cnt = 0;
for (Player *player : player_array) {
if (player->getId() == pId) {
cnt++;
}
}
return cnt;
}
int get_max_fragment_id(int pId) const {
int max_fId = 0;
for (Player *player : player_array) {
if (player->getId() == pId && max_fId < player->get_fId()) {
max_fId = player->get_fId();
}
}
return max_fId;
}
Strategy *get_strategy_by_id(int sId) const {
for (Strategy *strategy : strategy_array) {
if (strategy->getId() == sId) {
return strategy;
}
}
return NULL;
}
CircleArray get_visibles(const PlayerArray& for_them) const {
// fog of war
for (Player *player : player_array) {
int frag_cnt = get_fragments_cnt(player->getId());
bool updated = player->update_vision(frag_cnt);
if (updated) {
//logger->write_fog_for(tick, player);
}
}
auto can_see = [&for_them](Circle* c){
for (Player *fragment : for_them) {
if (fragment->can_see(c)) {
return true;
}
}
return false;
};
CircleArray visibles;
for (Food *food : food_array) {
if (can_see(food)) {
visibles.append(food);
}
}
for (Ejection *eject : eject_array) {
if (can_see(eject)) {
visibles.append(eject);
}
}
auto pId = for_them.empty() ? -1 : for_them.front()->getId();
for (Player *player : player_array) {
if (player->getId() != pId && can_see(player)) {
visibles.append(player);
}
}
for (Virus *virus : virus_array) {
visibles.append(virus);
}
return visibles;
}
public:
void apply_strategies() {
for (Strategy *strategy : strategy_array) {
int sId = strategy->getId();
PlayerArray fragments = get_players_by_id_v2_deprecated_for_highload(sId);
if (fragments.empty()) {
continue;
}
CircleArray visibles = get_visibles(fragments);
Direct direct = strategy->tickEvent(fragments, visibles);
// //logger->write_direct(tick, sId, direct);
apply_direct_for(sId, direct);
}
}
void apply_direct_for(int sId, Direct direct) {
// //logger->write_direct(tick, sId, direct);
foreach_players(sId,[&](Player*frag){
frag->apply_direct(direct, Constants::instance().GAME_WIDTH, Constants::instance().GAME_HEIGHT);
});
strategy_directs[sId]=direct;
}
bool can_player_do_split(int sId){
bool out=false;
int n=0;
foreach_players(sId,[&](Player*frag){n++;});
foreach_players(sId,[&](Player*frag){out=out||frag->can_split(n);});
return out;
}
PlayerArray split_fragments_v2_buff;
void split_fragments_v2(int sId) {
auto&fragments=split_fragments_v2_buff;
get_players_by_id_v3(fragments,sId);
std::sort(fragments.begin(), fragments.end(), [] (const Player* lhs, const Player* rhs) {
return
std::make_tuple(lhs->getM(), lhs->get_fId()) >
std::make_tuple(rhs->getM(), rhs->get_fId());
});
int fragments_count = fragments.size();
for (Player *frag : fragments) {
if (frag->can_split(fragments_count)) {
int max_fId = get_max_fragment_id(frag->getId());
//QString old_id = frag->id_to_str();
Player *new_frag= frag->split_now(max_fId);
player_array.push_back(new_frag);
fragments_count++;
//logger->write_add_cmd(tick, new_frag);
//logger->write_change_mass_id(tick, old_id, frag);
}
}
}
void player_splits() {
for (auto it = strategy_directs.begin(); it != strategy_directs.end(); it++) {
const Direct& direct = it->second;
if (direct.split) {
const int player_id = it->first;
split_fragments_v2(player_id);
}
}
}
PlayerArray player_ejects_fragments_buff;
void player_ejects() {
for (auto it = strategy_directs.begin(); it != strategy_directs.end(); it++) {
int sId = (*it).first;
Direct direct = (*it).second;
if(direct.split || !direct.eject) {
continue;
}
PlayerArray&fragments=player_ejects_fragments_buff;
get_players_by_id_v3(fragments,sId);
for (Player *frag : fragments) {
if (frag->can_eject()) {
Ejection *new_eject = frag->eject_now(id_counter);
eject_array.append(new_eject);
id_counter++;
//logger->write_add_cmd(tick, new_eject);
}
}
}
}
void eat_all() {
auto nearest_player = [this] (Circle *circle) {
Player *nearest_predator = NULL;
double deeper_dist = -INFINITY;
for (Player *predator : player_array) {
double qdist = predator->can_eat(circle);
if (qdist > deeper_dist) {
deeper_dist = qdist;
nearest_predator = predator;
}
}
return nearest_predator;
};
auto nearest_virus = [this] (Ejection *eject) {
Virus *nearest_predator = NULL;
double deeper_dist = -INFINITY;
for (Virus *predator : virus_array) {
double qdist = predator->can_eat(eject);
if (qdist > deeper_dist) {
deeper_dist = qdist;
nearest_predator = predator;
}
}
return nearest_predator;
};
for (auto fit = food_array.begin(); fit != food_array.end();) {
if (Player *eater = nearest_player(*fit)) {
eater->eat(*fit);
if(score_hack.need_ignore_food&&score_hack.pId==eater->id)
{
score_hack.n+=SCORE_FOR_FOOD;
}else{
player_scores[eater->getId()]+=SCORE_FOR_FOOD;
}
delete *fit;
fit = food_array.erase(fit);
} else {
fit++;
}
}
if(pfoodmap&&pfoodmap->need_use_inside_sim)
{
auto FOOD_MASS=Constants::instance().FOOD_MASS;
QapAssert(food_array.empty());
auto&arr=player_array;
for(int i=0;i<arr.size();i++){
auto&ex=arr[i];
auto fer=ex->get_food_eat_radius();
auto dn=pfoodmap->sim_eat(ex->get_pos(),fer,tick);
if(!dn)continue;
ex->mass+=dn*FOOD_MASS;
player_scores[ex->id]+=SCORE_FOR_FOOD*dn;
int gg=1;
}
}
for (auto eit = eject_array.begin(); eit != eject_array.end(); ) {
auto eject = *eit;
if (Virus *eater = nearest_virus(eject)) {
eater->eat(eject);
} else if (Player *eater = nearest_player(eject)) {
eater->eat(eject);
if (!eject->is_my_eject(eater)) {
player_scores[eater->getId()] += SCORE_FOR_FOOD;
}
} else {
eit++;
continue;
}
//logger->write_kill_cmd(tick, eject);
delete eject;
eit = eject_array.erase(eit);
}
for (auto pit = player_array.begin(); pit != player_array.end(); ) {
if(Player *eater = nearest_player(*pit)) {
bool is_last = get_fragments_cnt((*pit)->getId()) == 1;
eater->eat(*pit);
player_scores[eater->getId()] += is_last? SCORE_FOR_LAST : SCORE_FOR_PLAYER;
//logger->write_kill_cmd(tick, *pit);
delete *pit;
pit = player_array.erase(pit);
} else {
pit++;
}
}
}
void burst_on_viruses() { // TODO: improve target selection
//PlayerArray targets = player_array; // WTF? this is not used
auto nearest_to = [this] (Virus *virus) {
double nearest_dist = INFINITY;
Player *nearest_player = NULL;
for (Player *player : player_array) {
double qdist = virus->can_hurt(player);
if (qdist < nearest_dist) {
int yet_cnt = get_fragments_cnt(player->getId());
if (player->can_burst(yet_cnt)) {
nearest_dist = qdist;
nearest_player = player;
}
}
}
return nearest_player;
};
for (auto vit = virus_array.begin(); vit != virus_array.end(); ) {
if (Player *player = nearest_to(*vit)) {
if(burst_hack.need_sim_without_burst)if(player->id==burst_hack.pId){vit++;continue;}
if(player->id==burst_hack.pId){
burst_hack.n++;
}
int yet_cnt = get_fragments_cnt(player->getId());
int max_fId = get_max_fragment_id(player->getId());
player->burst_on(*vit);
player_scores[player->getId()] += SCORE_FOR_BURST;
PlayerArray fragments = player->burst_now(max_fId, yet_cnt);
player_array+=fragments;
delete *vit;
vit = virus_array.erase(vit);
} else {
vit++;
}
}
}
PlayerArray fuse_players_fragments_buff;
vector<int> fuse_players_pids_buff;
void fuse_players()
{
vector<int>&pids=fuse_players_pids_buff;int sId_offset=-1;
pids.clear();
if(!player_array.empty())
{
int min_id=QAP_MINVAL_ID_OF_VEC(player_array,+ex->id);int min_pid=player_array[min_id]->id;
int max_id=QAP_MINVAL_ID_OF_VEC(player_array,-ex->id);int max_pid=player_array[max_id]->id;
pids.resize(max_pid-min_pid+1,0);
QAP_FOREACH(player_array,pids[ex->id-min_pid]++);
sId_offset=min_pid;
}
PlayerArray fused_players;
for(int i=0;i<pids.size();i++)
{
auto present=pids[i];
if(!present)continue;
int id=sId_offset+i;
auto&fragments=fuse_players_fragments_buff;
get_players_by_id_v3(fragments,id);
std::sort(fragments.begin(),fragments.end(),[](const Player*a,const Player*b){return(
std::make_tuple(a->mass,-a->fragmentId) >
std::make_tuple(b->mass,-b->fragmentId)
);});
for(bool new_fusion_check=true;new_fusion_check;)
{
new_fusion_check=false;
for(int i=0;i<fragments.size();i++)
{
auto&a=fragments[i];
if(!a||a->fuse_timer)continue;
for(int j=i+1;j<fragments.size();j++)
{
auto&b=fragments[j];
if(!a||a->fuse_timer)continue;
if(!b||b->fuse_timer)continue;
if(!a->can_fuse_v2(b))continue;
a->fusion(b);
fused_players.push_back(b);
new_fusion_check=true;
b=nullptr;
}
}
if(!new_fusion_check)continue;
for(int i=0;i<fragments.size();i++)
{
auto&ex=fragments[i];
if(!ex)continue;
fragments[i]->update_by_mass(Constants::instance().GAME_WIDTH, Constants::instance().GAME_HEIGHT);
}
}
}
for (Player *p : fused_players) {
//logger->write_kill_cmd(tick, p);
//delete p;
delete_if_eq(player_array,p);
}
}
PlayerArray move_moveables_fragments_buff;
vector<int> move_moveables_pids_buff;
void move_moveables() {
Constants &ins = Constants::instance();
for (Ejection *eject : eject_array) {
bool changed = eject->move(ins.GAME_WIDTH, ins.GAME_HEIGHT);
if (changed) {
//logger->write_change_pos(tick, eject);
}
}
for (Virus *virus : virus_array) {
bool changed = virus->move(ins.GAME_WIDTH, ins.GAME_HEIGHT);
if (changed) {
//logger->write_change_pos(tick, virus);
}
}
vector<int>&pids=move_moveables_pids_buff;int sId_offset=-1;
pids.clear();
if(!player_array.empty())
{
int min_id=QAP_MINVAL_ID_OF_VEC(player_array,+ex->id);int min_pid=player_array[min_id]->id;
int max_id=QAP_MINVAL_ID_OF_VEC(player_array,-ex->id);int max_pid=player_array[max_id]->id;
pids.resize(max_pid-min_pid+1,0);
QAP_FOREACH(player_array,pids[ex->id-min_pid]++);
sId_offset=min_pid;
}
for(int i=0;i<pids.size();i++)
{
auto present=pids[i];
if(!present)continue;
int sId=sId_offset+i;
PlayerArray&fragments=move_moveables_fragments_buff;
get_players_by_id_v3(fragments,sId);
for (int i = 0; i != fragments.size(); ++i) {
Player *curr = fragments[i];
for (int j = i + 1; j < fragments.size(); ++j) {
curr->collisionCalc(fragments[j]);
}
}
}
for (Player *player : player_array) {
bool changed = player->move(ins.GAME_WIDTH, ins.GAME_HEIGHT);
if (changed) {
//logger->write_change_pos(tick, player);
}
}
}
void update_players_radius() {
for (Player *player : player_array) {
bool changed = player->update_by_mass(Constants::instance().GAME_WIDTH, Constants::instance().GAME_HEIGHT);
if (changed) {
//logger->write_change_mass(tick, player);
}
}
}
void split_viruses() {
VirusArray append_viruses;
for (Virus *virus : virus_array) {
if (virus->can_split()) {
Virus *new_virus = virus->split_now(id_counter);
//logger->write_add_cmd(tick, new_virus);
append_viruses.append(new_virus);
id_counter++;
}
}
virus_array+=append_viruses;
}
void shrink_players() {
for (Player *player : player_array) {
if (player->can_shrink()) {
player->shrink_now();
//logger->write_change_mass(tick, player);
}
}
}
int get_score_for(int pId) const {
return player_scores.at(pId);
}
QMap<int, int> get_scores() const {
return player_scores;
}
};
#endif // MECHANIC_H