mirror of
https://github.com/ProgramSnail/snake_2024.git
synced 2025-12-07 23:18:43 +00:00
Bot class: first iteration, refactoring fix (Worm -> Snake)
This commit is contained in:
parent
360c3b064a
commit
a92c96f91e
3 changed files with 27 additions and 8 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <deque>
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
|
||||
#include "Canvas.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
|
@ -61,6 +62,21 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
std::optional<Veci> find_nearest_food(Veci pos) {
|
||||
if (food_.empty()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
Veci target = food_.front().pos;
|
||||
for (const auto &food : food_) {
|
||||
if ((pos - food.pos).len_sq() < (pos - target).len_sq()) {
|
||||
target = food.pos;
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
private:
|
||||
void generate() {
|
||||
++current_gen_;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue