summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pacman-c++/sceneholder.cpp12
-rw-r--r--pacman-c++/server.cpp19
-rw-r--r--pacman-c++/server.h2
3 files changed, 22 insertions, 11 deletions
diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp
index 6879ea1..578b0df 100644
--- a/pacman-c++/sceneholder.cpp
+++ b/pacman-c++/sceneholder.cpp
@@ -138,14 +138,14 @@ void SceneHolder::updateMap(const Transmission::map_t& map, const unsigned int x
138 Actor::Movement direction = Util::transmissionMovementToActor( 138 Actor::Movement direction = Util::transmissionMovementToActor(
139 cur & Transmission::direction_mask); 139 cur & Transmission::direction_mask);
140 /* WARNING: do NOT add actor to visualMap as visualMap-items may 140 /* WARNING: do NOT add actor to visualMap as visualMap-items may
141 * get deleted during update and actors are referenced in_mactors too 141 * get deleted during update and actors are referenced in_mactors too
142 * if you REALLY need that you need to changed updateMap so that all actors 142 * if you REALLY need that you need to changed updateMap so that all actors
143 * will be moved before any new items get allocated (totally untested) 143 * will be moved before any new items get allocated (totally untested)
144 */ 144 */
145 actor->move(direction); 145 actor->move(direction);
146 /* that's kind a hack but working right now 146 /* that's kind a hack but working right now
147 * I think that will fall on our's hat sooner or later 147 * I think that will fall on our's hat sooner or later
148 */ 148 */
149 if (!(cur & Transmission::empty)) 149 if (!(cur & Transmission::empty))
150 actor->stopEating(); 150 actor->stopEating();
151 qDebug() << "[SceneUpdate] actor moves: color=" << color 151 qDebug() << "[SceneUpdate] actor moves: color=" << color
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
343void Server::aiCalculate(Actor *actor) 343void 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())
diff --git a/pacman-c++/server.h b/pacman-c++/server.h
index a4bbe58..8d40f27 100644
--- a/pacman-c++/server.h
+++ b/pacman-c++/server.h
@@ -36,7 +36,7 @@ protected:
36 36
37 QPoint addRandomPoint(Transmission::map_t map, Transmission::field_t type = Transmission::bonuspoint); 37 QPoint addRandomPoint(Transmission::map_t map, Transmission::field_t type = Transmission::bonuspoint);
38 void colorizeBlocks(Transmission::map_t map); 38 void colorizeBlocks(Transmission::map_t map);
39 void aiCalculate(Actor *actor); 39 void botCalculate(Actor *actor);
40 40
41protected: 41protected:
42 QMap<Color::Color, QTcpSocket *> m_clientConnections; 42 QMap<Color::Color, QTcpSocket *> m_clientConnections;