Index: common/Player.cpp
===================================================================
--- common/Player.cpp	(revision 11d21ee11d4c61808a4280cdafbf7778a7af72c9)
+++ common/Player.cpp	(revision ff2133aee0f65c9b2661b1823a42193172c15167)
@@ -191,2 +191,18 @@
    return moving;
 }
+
+void Player::updateTarget(map<unsigned int, Player>& mapPlayers) {
+   if (this->isChasing) {
+      this->target.x = mapPlayers[this->targetPlayer].pos.x;
+      this->target.y = mapPlayers[this->targetPlayer].pos.y;
+
+      if (posDistance(this->pos, this->target.toFloat()) <= this->range) {
+         this->target.x = this->pos.x;
+         this->target.y = this->pos.y;
+
+         this->isChasing = false;
+         this->isAttacking = true;
+         this->timeAttackStarted = getCurrentMillis();
+      }
+   }
+}
Index: common/Player.h
===================================================================
--- common/Player.h	(revision 11d21ee11d4c61808a4280cdafbf7778a7af72c9)
+++ common/Player.h	(revision ff2133aee0f65c9b2661b1823a42193172c15167)
@@ -12,4 +12,5 @@
 
 #include <string>
+#include <map>
 
 #include "Common.h"
@@ -46,8 +47,9 @@
    void deserialize(char* buffer);
 
+   void updateTarget(map<unsigned int, Player>& mapPlayers);
    bool move(WorldMap *map);
 
-   void takeFlag(int flag, WorldMap *map);
-   void dropFlag(int flag, WorldMap *map);
+   void takeFlag(int flag, WorldMap* map);
+   void dropFlag(int flag, WorldMap* map);
 
    int id;
Index: common/Projectile.cpp
===================================================================
--- common/Projectile.cpp	(revision 11d21ee11d4c61808a4280cdafbf7778a7af72c9)
+++ common/Projectile.cpp	(revision ff2133aee0f65c9b2661b1823a42193172c15167)
@@ -72,4 +72,8 @@
 
 bool Projectile::move(map<unsigned int, Player>& mapPlayers) {
+   // if the current target logs off, this method will run into problems
+
+   //cout << "Inside projectile move" << endl;
+
    unsigned long long curTime = getCurrentMillis();
    Player targetP = mapPlayers[target];
@@ -85,4 +89,6 @@
    float dist = sqrt(pow(targetP.pos.x-pos.x, 2) + pow(targetP.pos.y-pos.y, 2));
 
+   //cout << "About to finish projectile move" << endl;
+
    if (dist <= pixels) {
       pos.x = targetP.pos.x;
Index: server/server.cpp
===================================================================
--- server/server.cpp	(revision 11d21ee11d4c61808a4280cdafbf7778a7af72c9)
+++ server/server.cpp	(revision ff2133aee0f65c9b2661b1823a42193172c15167)
@@ -149,6 +149,8 @@
          // set targets for all chasing players (or make them attack if they're close enough)
          for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) {
-            Player* p = &it->second;
-
+            //Player* p = &it->second;
+            it->second.updateTarget(mapPlayers);
+
+            /*
             if (p->isChasing) {
                p->target.x = mapPlayers[p->targetPlayer].pos.x;
@@ -164,4 +166,5 @@
                }
             }
+            */
          }
 
@@ -171,4 +174,5 @@
          bool broadcastMove = false;
          for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) {
+            cout << "Starting new for loop iteration" << endl;
             oldPos = it->second.pos;
             if (it->second.move(gameMap)) {
@@ -362,4 +366,6 @@
 
                if (it->second.attackType == Player::ATTACK_MELEE) {
+                  cout << "Melee attack" << endl;
+
                   Player* target = &mapPlayers[it->second.targetPlayer];
 
@@ -371,4 +377,6 @@
                   target->serialize(serverMsg.buffer);
                }else if (it->second.attackType == Player::ATTACK_RANGED) {
+                  cout << "Ranged attack" << endl;
+
                   Projectile proj(it->second.pos.x, it->second.pos.y, it->second.targetPlayer, it->second.damage);
                   proj.id = unusedProjectileId;
@@ -389,4 +397,29 @@
 
                // broadcast either a PLAYER or PROJECTILE message
+               cout << "Broadcasting player or projectile message" << endl;
+               for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
+               {
+                  if (sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
+                     error("sendMessage");
+               }
+               cout << "Done broadcasting" << endl;
+            }
+         }
+
+         cout << "Done with the for loop" << endl;
+
+         // move all projectiles
+         cout << "Moving projectiles" << endl;
+         map<unsigned int, Projectile>::iterator itProj;
+         for (itProj = mapProjectiles.begin(); itProj != mapProjectiles.end(); itProj++) {
+            if (itProj->second.move(mapPlayers)) {
+               // send a REMOVE_PROJECTILE message
+               cout << "send a REMOVE_PROJECTILE message" << endl;
+               serverMsg.type = MSG_TYPE_REMOVE_PROJECTILE;
+               memcpy(serverMsg.buffer, &itProj->second.id, 4);
+               mapProjectiles.erase(itProj->second.id);
+
+               map<unsigned int, Player>::iterator it2;
+               cout << "Broadcasting REMOVE_PROJECTILE" << endl;
                for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
                {
@@ -394,17 +427,17 @@
                      error("sendMessage");
                }
-            }
-         }
-
-         // move all projectiles
-         map<unsigned int, Projectile>::iterator itProj;
-         for (itProj = mapProjectiles.begin(); itProj != mapProjectiles.end(); itProj++) {
-            if (itProj->second.move(mapPlayers)) {
-               // send a REMOVE_PROJECTILE message
-               serverMsg.type = MSG_TYPE_REMOVE_PROJECTILE;
-               memcpy(serverMsg.buffer, &itProj->second.id, 4);
-               mapProjectiles.erase(itProj->second.id);
-
-               map<unsigned int, Player>::iterator it2;
+
+               cout << "send a PLAYER message after dealing damage" << endl;
+               // send a PLAYER message after dealing damage
+               Player* target = &mapPlayers[itProj->second.target];
+
+               target->health -= itProj->second.damage;
+               if (target->health < 0)
+                  target->health = 0;
+
+               serverMsg.type = MSG_TYPE_PLAYER;
+               target->serialize(serverMsg.buffer);
+
+               cout << "Sending a PLAYER message" << endl;
                for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
                {
@@ -412,23 +445,8 @@
                      error("sendMessage");
                }
-
-               // send a PLAYER message after dealing damage
-               Player* target = &mapPlayers[itProj->second.target];
-
-               target->health -= itProj->second.damage;
-               if (target->health < 0)
-                  target->health = 0;
-
-               serverMsg.type = MSG_TYPE_PLAYER;
-               target->serialize(serverMsg.buffer);
-
-               for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++)
-               {
-                  if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 )
-                     error("sendMessage");
-               }
-            }
-         }
-      }
+            }
+         }
+      }
+      cout << "Done moving projectiles" << endl;
 
       n = receiveMessage(&clientMsg, sock, &from);
