2023-08-19 12:56:40 -05:00
|
|
|
#include "botinterface.hpp"
|
|
|
|
#include "common.hpp"
|
|
|
|
#include <SFML/System/Vector2.hpp>
|
|
|
|
|
|
|
|
namespace snakeplusplus
|
|
|
|
{
|
|
|
|
PlayerDirection lastKnownDirection = kNone;
|
2023-08-19 23:32:53 -05:00
|
|
|
PlayerDirection GetBotInput(const sf::Vector2f* snakeHeadLocation, const sf::Vector2f* foodLocation)
|
2023-08-19 12:56:40 -05:00
|
|
|
{
|
|
|
|
sf::Vector2f directionDelta;
|
2023-08-19 23:32:53 -05:00
|
|
|
directionDelta = *snakeHeadLocation - *foodLocation;
|
2023-08-19 12:56:40 -05:00
|
|
|
if ((directionDelta.y > 0)
|
|
|
|
&& (lastKnownDirection != kDown))
|
|
|
|
{ lastKnownDirection = kUp; }
|
|
|
|
else if ((directionDelta.y < 0)
|
|
|
|
&& (lastKnownDirection != kUp))
|
|
|
|
{ lastKnownDirection = kDown; }
|
|
|
|
else if ((directionDelta.x > 0)
|
|
|
|
&& (lastKnownDirection != kRight))
|
|
|
|
{ lastKnownDirection = kLeft; }
|
|
|
|
else if ((directionDelta.x < 0)
|
|
|
|
&& (lastKnownDirection != kLeft))
|
|
|
|
{ lastKnownDirection = kRight; }
|
|
|
|
return lastKnownDirection;
|
|
|
|
}
|
|
|
|
}
|