27 lines
928 B
C++
27 lines
928 B
C++
|
#include "botinterface.hpp"
|
||
|
#include "common.hpp"
|
||
|
#include <SFML/System/Vector2.hpp>
|
||
|
|
||
|
namespace snakeplusplus
|
||
|
{
|
||
|
PlayerDirection lastKnownDirection = kNone;
|
||
|
PlayerDirection GetBotInput(sf::Vector2f snakeHeadLocation, sf::Vector2f foodLocation)
|
||
|
{
|
||
|
sf::Vector2f directionDelta;
|
||
|
directionDelta = snakeHeadLocation - foodLocation;
|
||
|
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;
|
||
|
}
|
||
|
}
|