diff options
| author | manuel <manuel@mausz.at> | 2011-04-18 01:43:28 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-04-18 01:43:28 +0200 |
| commit | e373442901064d07791c9739daa380acb1dfbb8c (patch) | |
| tree | 084853c769579a321e5bfb3d1861720d6f887e3e /pacman-c++/server.cpp | |
| parent | 479818cfae62809788367fb04db1f9d6a509b498 (diff) | |
| download | foop-e373442901064d07791c9739daa380acb1dfbb8c.tar.gz foop-e373442901064d07791c9739daa380acb1dfbb8c.tar.bz2 foop-e373442901064d07791c9739daa380acb1dfbb8c.zip | |
few bot improvements
Diffstat (limited to 'pacman-c++/server.cpp')
| -rw-r--r-- | pacman-c++/server.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp index 02055b7..65a8f8b 100644 --- a/pacman-c++/server.cpp +++ b/pacman-c++/server.cpp | |||
| @@ -56,7 +56,7 @@ void Server::tick() | |||
| 56 | { | 56 | { |
| 57 | //qDebug() << "[Tick] Doing server update"; | 57 | //qDebug() << "[Tick] Doing server update"; |
| 58 | foreach(Color::Color color, m_bots) | 58 | foreach(Color::Color color, m_bots) |
| 59 | aiCalculate(m_actors[color]); | 59 | botCalculate(m_actors[color]); |
| 60 | Transmission::map_t map = calculateUpdates(); | 60 | Transmission::map_t map = calculateUpdates(); |
| 61 | updateMap(map); | 61 | updateMap(map); |
| 62 | 62 | ||
| @@ -340,16 +340,27 @@ void Server::sendUpdate(Transmission::map_t map) | |||
| 340 | } | 340 | } |
| 341 | } | 341 | } |
| 342 | 342 | ||
| 343 | void Server::aiCalculate(Actor *actor) | 343 | void Server::botCalculate(Actor *actor) |
| 344 | { | 344 | { |
| 345 | /* move as long as possible in one direction */ | 345 | /* move as long as possible in one direction */ |
| 346 | //if (m_actorMovements[actor->color()] != Actor::None) | 346 | //if (m_actorMovements[actor->color()] != Actor::None) |
| 347 | // return; | 347 | // return; |
| 348 | 348 | ||
| 349 | QPoint actorpos = CoordToMapPosition(actor->pos().toPoint()); | 349 | QPoint actorpos = CoordToMapPosition(actor->pos().toPoint()); |
| 350 | |||
| 351 | /* first make list of possible directions based on current actor position */ | ||
| 350 | QList<Actor::Movement> directions; | 352 | QList<Actor::Movement> directions; |
| 351 | directions << Actor::Left << Actor::Right << Actor::Up << Actor::Down; | 353 | if (actorpos.x() > 0) |
| 352 | QList<Actor::Movement> directions2(directions); // used if directions got empty | 354 | directions.append(Actor::Left); |
| 355 | if (actorpos.x() < visualMap.size() - 1) | ||
| 356 | directions.append(Actor::Right); | ||
| 357 | if (actorpos.y() > 0) | ||
| 358 | directions.append(Actor::Up); | ||
| 359 | if (actorpos.y() < visualMap[actorpos.x()].size() - 1) | ||
| 360 | directions.append(Actor::Down); | ||
| 361 | |||
| 362 | /* copy of directions: used if there's no good direction based on rules */ | ||
| 363 | QList<Actor::Movement> directions2(directions); | ||
| 353 | 364 | ||
| 354 | QMutableListIterator<Actor::Movement> i(directions); | 365 | QMutableListIterator<Actor::Movement> i(directions); |
| 355 | while(i.hasNext()) | 366 | while(i.hasNext()) |
