mirror of
https://github.com/ProgramSnail/snake_2024.git
synced 2025-12-27 08:38:44 +00:00
functional bots, small refactoring, readme edit
This commit is contained in:
parent
5299e89633
commit
7e67a3bd30
13 changed files with 179 additions and 91 deletions
|
|
@ -28,16 +28,41 @@ protected:
|
|||
target_ = map_.find_nearest_food(get_pos());
|
||||
}
|
||||
|
||||
// check for case when no food found
|
||||
if (target_.has_value()) {
|
||||
direction_ = (Vecf(target_.value()) - real_pos_).norm();
|
||||
// TODO: manually change direction
|
||||
if (target_ != prev_target_) {
|
||||
direction_ = (Vecf(target_.value()) - real_pos_).norm();
|
||||
}
|
||||
} else {
|
||||
direction_ = {};
|
||||
}
|
||||
|
||||
prev_target_ = target_;
|
||||
}
|
||||
|
||||
protected:
|
||||
const Config bot_config_;
|
||||
|
||||
std::optional<Veci> target_ = {};
|
||||
std::optional<Veci> prev_target_ = {};
|
||||
float time_from_target_set_ = 0;
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
inline Bot::Config default_bot_config = {
|
||||
.time_between_targets = 0.5,
|
||||
};
|
||||
|
||||
inline Bot default_bot(Veci pos, Map &map) {
|
||||
return Bot(
|
||||
{
|
||||
.obj =
|
||||
{
|
||||
.pos = pos,
|
||||
.color = {color::GRAY},
|
||||
},
|
||||
.initial_length = 20,
|
||||
.radius = 10,
|
||||
},
|
||||
default_snake_config, default_bot_config, map);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue