@@ -189,9 +189,11 @@ void GameState::update_game_state_on_player_message()
189
189
// with the conditions above it means some round has finished recently
190
190
if (std::get<0 >(round .is_active ())) {
191
191
if (round .game_over_raised ) {
192
+ std::cerr << " Prepare for new round" << std::endl;
192
193
round .game_over_raised = false ;
193
194
for (auto &p : players) {
194
195
p.pressed_arrow = false ;
196
+ p.lurking = true ;
195
197
}
196
198
}
197
199
}
@@ -201,7 +203,8 @@ void GameState::update_game_state_on_player_message()
201
203
continue ;
202
204
}
203
205
counter++;
204
- if (counter >= 1 ) {
206
+ if (counter >= REQUIRED_PLAYERS) {
207
+ std::cerr << " Starting new game" << std::endl;
205
208
start_new_round ();
206
209
return ;
207
210
}
@@ -238,6 +241,9 @@ void GameState::start_new_round()
238
241
p.snake_id = j;
239
242
p.lurking = false ;
240
243
}
244
+ decltype (pending_queue) empty_pendign_queue;
245
+ std::swap (pending_queue, empty_pendign_queue);
246
+ pending.clear ();
241
247
round = Round{board, eager};
242
248
}
243
249
@@ -295,8 +301,8 @@ void Round::event(Event::SerializableEvent &e)
295
301
uint32_t crc = crc32 (0 , reinterpret_cast <unsigned char *>(&s[0 ]), s.length ());
296
302
s.resize (s.length () + 4 );
297
303
*reinterpret_cast <uint32_t *>(&s[s.length () - 4 ]) = crc;
298
- events_positions.push_back (events_history.size ());
299
304
events_history.insert (events_history.end (), s.begin (), s.end ());
305
+ events_positions.push_back (events_history.size ());
300
306
}
301
307
302
308
void Round::new_game ()
@@ -357,10 +363,10 @@ void Round::register_move(Position const &new_position, Snake &s, size_t player)
357
363
void Round::move (Snake &s, size_t player)
358
364
{
359
365
auto old_position = s.position ();
360
- s.direction += s.last_turn_direction * board.turning_speed ;
366
+ s.direction += 360 + s.last_turn_direction * board.turning_speed ;
361
367
s.direction %= 360 ;
362
- s.x += sin (M_PI * s.direction / 180 .);
363
- s.y += cos (M_PI * s.direction / 180 .);
368
+ s.x += cos (M_PI * s.direction / 180 .);
369
+ s.y += sin (M_PI * s.direction / 180 .);
364
370
auto new_position = s.position ();
365
371
if (old_position != new_position) {
366
372
register_move (new_position, s, player);
@@ -371,7 +377,10 @@ void Round::cycle()
371
377
{
372
378
size_t player = 0 ;
373
379
for (auto &snake: snakes) {
374
- move (snake, player++);
380
+ if (!snake.eliminated ) {
381
+ move (snake, player);
382
+ }
383
+ player++;
375
384
}
376
385
}
377
386
@@ -382,7 +391,8 @@ Board::Board(uint32_t gs, uint32_t ts, uint32_t mx, uint32_t my)
382
391
383
392
Round::Snake::Snake (std::string name, int32_t direction, Board const &board)
384
393
: eliminated{false }, x{r.next () % board.maxx + 0.5 }, y{r.next () % board.maxy + 0.5 },
385
- direction{r.next () % 360 }, last_turn_direction{direction}, name{name}
394
+ direction{static_cast <int32_t >(r.next () % 360 )}, last_turn_direction{direction},
395
+ name{name}
386
396
{
387
397
388
398
};
0 commit comments