diff options
| author | manuel <manuel@mausz.at> | 2011-04-17 22:04:04 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-04-17 22:04:04 +0200 |
| commit | 479818cfae62809788367fb04db1f9d6a509b498 (patch) | |
| tree | 6562d3f5f14f86df9aa5445d63fe85eebc3c99e7 | |
| parent | f5c00e32e6f32ca1216c72281b547faf372f0179 (diff) | |
| download | foop-479818cfae62809788367fb04db1f9d6a509b498.tar.gz foop-479818cfae62809788367fb04db1f9d6a509b498.tar.bz2 foop-479818cfae62809788367fb04db1f9d6a509b498.zip | |
more ai stuff
| -rw-r--r-- | pacman-c++/server.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp index 516d1f7..02055b7 100644 --- a/pacman-c++/server.cpp +++ b/pacman-c++/server.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | #include "block.h" | 4 | #include "block.h" |
| 5 | #include "anyoption.h" | 5 | #include "anyoption.h" |
| 6 | #include "bonuspoint.h" | 6 | #include "bonuspoint.h" |
| 7 | #include "point.h" | ||
| 7 | #include <QtNetwork/QTcpServer> | 8 | #include <QtNetwork/QTcpServer> |
| 8 | #include <QtNetwork/QTcpSocket> | 9 | #include <QtNetwork/QTcpSocket> |
| 9 | #include <QTextStream> | 10 | #include <QTextStream> |
| @@ -342,12 +343,13 @@ void Server::sendUpdate(Transmission::map_t map) | |||
| 342 | void Server::aiCalculate(Actor *actor) | 343 | void Server::aiCalculate(Actor *actor) |
| 343 | { | 344 | { |
| 344 | /* move as long as possible in one direction */ | 345 | /* move as long as possible in one direction */ |
| 345 | if (m_actorMovements[actor->color()] != Actor::None) | 346 | //if (m_actorMovements[actor->color()] != Actor::None) |
| 346 | return; | 347 | // return; |
| 347 | 348 | ||
| 348 | QPoint actorpos = CoordToMapPosition(actor->pos().toPoint()); | 349 | QPoint actorpos = CoordToMapPosition(actor->pos().toPoint()); |
| 349 | QList<Actor::Movement> directions; | 350 | QList<Actor::Movement> directions; |
| 350 | directions << Actor::Left << Actor::Right << Actor::Up << Actor::Down; | 351 | directions << Actor::Left << Actor::Right << Actor::Up << Actor::Down; |
| 352 | QList<Actor::Movement> directions2(directions); // used if directions got empty | ||
| 351 | 353 | ||
| 352 | QMutableListIterator<Actor::Movement> i(directions); | 354 | QMutableListIterator<Actor::Movement> i(directions); |
| 353 | while(i.hasNext()) | 355 | while(i.hasNext()) |
| @@ -366,12 +368,23 @@ void Server::aiCalculate(Actor *actor) | |||
| 366 | if (block != NULL && block->color() != actor->color()) | 368 | if (block != NULL && block->color() != actor->color()) |
| 367 | { | 369 | { |
| 368 | i.remove(); | 370 | i.remove(); |
| 371 | directions2.removeAll(direction); | ||
| 372 | continue; | ||
| 373 | } | ||
| 374 | |||
| 375 | /* if neighbour is not a point */ | ||
| 376 | BonusPoint *bpoint = qgraphicsitem_cast<BonusPoint *>(item); | ||
| 377 | Point *point = qgraphicsitem_cast<Point *>(item); | ||
| 378 | if (bpoint == NULL && point == NULL) | ||
| 379 | { | ||
| 380 | i.remove(); | ||
| 369 | continue; | 381 | continue; |
| 370 | } | 382 | } |
| 371 | } | 383 | } |
| 372 | 384 | ||
| 373 | int rand = (int) (directions.size() * (qrand() / (RAND_MAX + 1.0))); | 385 | QList<Actor::Movement> *ptr = (!directions.empty()) ? &directions : &directions2; |
| 374 | m_actorMovements[actor->color()] = directions.at(rand); | 386 | int rand = (int) (ptr->size() * (qrand() / (RAND_MAX + 1.0))); |
| 387 | m_actorMovements[actor->color()] = ptr->at(rand); | ||
| 375 | } | 388 | } |
| 376 | 389 | ||
| 377 | void Server::keyPressUpdate() | 390 | void Server::keyPressUpdate() |
