diff options
author | Dominique Martinet <asmadeus@codewreck.org> | 2011-11-29 01:58:45 +0100 |
---|---|---|
committer | Dominique Martinet <asmadeus@codewreck.org> | 2011-11-29 01:58:45 +0100 |
commit | d9154634911f757dc645f653d3b42d428dd4f21f (patch) | |
tree | d43a5097687d8660cea7d659a78dde06b7196562 /AIController.cpp | |
parent | f096cba3b737eb01e657e76187cf140f4c7a1acc (diff) |
more AI work, just gotta make the compiler happy now... where's mario when we need him :) (uncomment part in game to call the think function
Diffstat (limited to 'AIController.cpp')
-rw-r--r-- | AIController.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/AIController.cpp b/AIController.cpp new file mode 100644 index 0000000..fd74e63 --- /dev/null +++ b/AIController.cpp @@ -0,0 +1,40 @@ +#include "AIController.h" + + +AIController::AIController(Player &player, Field& field, int inhibitSpeed): + Controller(player), m_field(field), m_inhibitSpeed(inhibitSpeed) +{ +} + +AIController::~AIController(void) +{ +} + + +void AIController::think() { + Coordinates coord = m_player.getCoordinates(); + VelocityVector velocity = m_player.getVelocity(); + + int sgn_x = velocity.x >= 0 ? 1 : -1; + int sgn_y = velocity.y >= 0 ? 1 : -1; + + for (int i = 0; i <= abs(velocity.x) ; ++i ) { + for (int j = 0; j <= abs(velocity.y) ; ++j ) { + if (m_field.getCell(Coordinates(coord.x+i*sgn_x, coord.y+j*sgn_y)).getState()) { + turnRandom(); + } + } + } + if (rand() % 100 >=7) turnRandom(); + m_inhibit = max(0,m_inhibit-1); +} + +void AIController::turnRandom() { + if (m_inhibit == 0) { + if (rand()%100>=50) + m_player.turnLeft(); + else + m_player.turnRight(); + m_inhibit = m_inhibitSpeed; + } +} |