Index: code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc	(revision 12317)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc	(revision 12318)
@@ -241,4 +241,5 @@
             return player->getWorldPosition();
         }
+        //std::cout<<"bug ??"<<endl;
         return Vector3(0,0,0); //default, should not be used
     
@@ -745,10 +746,44 @@
     }
 
+
+    bool PacmanGhost::playerFindPos(Vector3 one, Vector3 other){
+       if((abs(one.x - other.x)<15) && (abs(one.z - other.z)<15)) return true;
+        return false;
+        }
+
+
+
+
     int PacmanGhost::findPlayerTravDir (Vector3 playerPosBefore, Vector3 playerPos){
         //return 0 for south, 1 for west, 2 for north, 3 for east
 
-        Vector3 difference = diffVector(playerPosBefore, playerPos);
-
-
+
+        if(playerFindPos(playerPosBefore, playerPos)){
+            //if player is still near last crossed point
+
+            return 4; //return the last crossed point for simplicity
+        }
+
+
+        if(abs(playerPos.x-playerPosBefore.x)<14){ //player is moving vertically
+            if((playerPos.z-playerPosBefore.z)<0){//move west
+                return 0;
+            }
+            if((playerPos.z-playerPosBefore.z)>0){//move east
+                return 2;
+            }
+        }
+
+        if(abs(playerPos.z-playerPosBefore.z)<14){ //player is moving horizontally
+            if((playerPos.x-playerPosBefore.x)<0){//move south
+                return 1;
+            }
+            if((playerPos.x-playerPosBefore.x)>0){//move north
+                return 3;
+            }
+        }
+
+
+        /*Vector3 difference = diffVector(playerPosBefore, playerPos);
         if((difference.z < 0)&&(difference.z>difference.x)){ //move south
 
@@ -772,5 +807,5 @@
 
         return 1;
-            }
+            }*/
         
         }
@@ -779,4 +814,9 @@
         //return the Vector3 point that Pinky should target to
         //be in front of pacman
+
+        if(indexForSWNE==4){
+            std::cout<<"Ryukyu"<<endl;
+            return pacLasVisPos;
+        }
 
         Vector3 listOfNeighboors[4];
@@ -840,4 +880,9 @@
             }
             else if(findpos(pacLasVisPos,possibleposition[10])){
+
+                if(indexForSWNE==3){ //nothing eastward
+                    return pacLasVisPos;
+                }
+
                 listOfNeighboors[0]=possibleposition[9]; //south
                 listOfNeighboors[1]=possibleposition[45]; //west
@@ -1020,4 +1065,9 @@
             }
             else if(findpos(pacLasVisPos,possibleposition[42])){
+
+                if(indexForSWNE==1){//nothing westward
+                    return pacLasVisPos;
+                }
+
                 listOfNeighboors[0]=possibleposition[39]; //south
                 listOfNeighboors[2]=possibleposition[59]; //north
Index: code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.h
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.h	(revision 12317)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.h	(revision 12318)
@@ -89,5 +89,9 @@
         Vector3 playerPos;
 
-        Vector3 lastPlayerPassedPoint;/*
+        Vector3 lastPlayerPassedPoint;
+
+        Vector3 pointInFrontOfPlayer;
+        /*
+
 
         //Vector3 pathAlgorithm;
@@ -120,4 +124,6 @@
     Vector3 diffVector (Vector3 start, Vector3 goal);
 
+    bool playerFindPos(Vector3 one, Vector3 other);
+
 
     };
Index: code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.cc
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.cc	(revision 12317)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.cc	(revision 12318)
@@ -17,4 +17,5 @@
         this->target_z=15;
         this->lastPlayerPassedPoint=Vector3(70,10,-135);
+        this->isNearPlayer=false;
           
     }
@@ -42,4 +43,5 @@
     void PacmanRed::tick(float dt)
     {
+        std::cout<<"LemanExpress5"<<endl;
         SUPER(PacmanGhost, tick, dt);
 
@@ -52,7 +54,20 @@
             }
 
-        
+
+        /*if((playerFindPos(this->actuelposition, this->getPlayerPos()))&&(isNearPlayer==false)){
+            isNearPlayer=true;
+            setNewTargetRed(this->getPlayerPos());
+        }
+        else if (!(playerFindPos(this->actuelposition, this->getPlayerPos())&&(isNearPlayer==true))){
+            isNearPlayer=false;
+            setNewTargetRed(this->pointInFrontOfPlayer); 
+        }*/
+
+
+
+
         //Stop, if target arrived
         if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){
+            std::cout<<"LemanExpress1"<<endl;
                  this->ismoving = false;
         }
@@ -60,4 +75,5 @@
         //Move, if ghost hasn't arrived yet
         if(this->ismoving){
+            std::cout<<"LemanExpress2"<<endl;
             if(!(abs(this->actuelposition.z-target_z)<0.5)) {
                 velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z));
@@ -68,8 +84,10 @@
                 move(dt, actuelposition, velocity);
             }
+            std::cout<<"LemanExpress4"<<endl;
         }
-        
+
         //Check on which position the ghost has arrived and set new target
         else{
+            std::cout<<"LemanExpress3"<<endl;
 
             while(lockmove){};
@@ -83,22 +101,26 @@
 
             int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos());
+            this->pointInFrontOfPlayer=getPointInFrontOfPacman(lastPlayerPassedPoint, directionV);
 
 
-            if(this->actuelposition!=lastPlayerPassedPoint){
+            if(!findpos(this->actuelposition, lastPlayerPassedPoint)){
                 
                 std::cout<<this->getPlayerPos()<<endl;
                 std::cout<<this->lastPlayerPassedPoint<<endl;
-                std::cout<<getPointInFrontOfPacman(lastPlayerPassedPoint, directionV)<<endl;
+                std::cout<<this->pointInFrontOfPlayer<<endl;
+                std::cout<<this->actuelposition<<endl;
             nextMove(redPos, lastPlayerPassedPoint);
+            std::cout<<"hiuddi"<<endl;
             }
-            else{// red pacman is at lastPlayerPassedPoint
+            else if(findpos(this->actuelposition, lastPlayerPassedPoint)){// red pacman is at lastPlayerPassedPoint
 
-            //int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos());
+                std::cout<<"dhdidjop"<<endl;
+                std::cout<<this->getPlayerPos()<<endl;
+                std::cout<<this->lastPlayerPassedPoint<<endl;
+                std::cout<<this->pointInFrontOfPlayer<<endl;
+                std::cout<<this->actuelposition<<endl;
 
-            Vector3 pointInFrontOfPlayer = getPointInFrontOfPacman(lastPlayerPassedPoint, directionV);
-
-            nextMove(redPos, pointInFrontOfPlayer);
-
-            //nextMove(this->getPlayerPos(), redPos);
+                nextMove(lastPlayerPassedPoint, pointInFrontOfPlayer);
+                std::cout<<"ogslodm"<<endl;
             }
 
Index: code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.h
===================================================================
--- code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.h	(revision 12317)
+++ code/branches/3DPacman_FS19/src/modules/pacman/PacmanRed.h	(revision 12318)
@@ -26,4 +26,6 @@
   			bool jeanfindpos(Vector3 one, Vector3 other);
 
+  			bool isNearPlayer;
+
 
 
