Advertisement
Transformator

c++1

Sep 14th, 2014
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <array>
  4. using namespace std;
  5.  
  6. int nav(int posX, int posY, int lastpointX, int lastpointY)
  7. {
  8.     string map = "XXXXXXXXXXXXXXXXXXXXO.XXX...XXXXXX...X.OX...X.X.X...XX.X...XXXX.X.X...X....XXXXXXXX...XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  9.     /*
  10.      *  XXXXXXXXXXXXXXXXXXXX
  11.      *  O.XXX...XXXXXX...X.O
  12.      *  X...X.X.X...XX.X...X
  13.      *  XXX.X.X...X....XXXXX
  14.      *  XXX...XXXXXXXXXXXXXX
  15.      *  XXXXXXXXXXXXXXXXXXXX
  16.      */
  17.    
  18.     // 20 pro zeile
  19.    
  20.     bool end = false;
  21.     int endpos = 0;
  22.    
  23.     while(end != true)
  24.     {
  25.         int direction = 0;
  26.         // direction 1 = von links
  27.         // direction 2 = von rechts
  28.         // direction 3 = von oben
  29.         // direction 4 = von unten
  30.        
  31.         if(lastpointX < posX)
  32.             direction = 1;
  33.         else if(lastpointX > posX)
  34.             direction = 2;
  35.         else if(lastpointY < posY)
  36.             direction = 3;
  37.         else if(lastpointY < posY)
  38.             direction = 4;
  39.         else
  40.             cout << "lastpoint nicht bekannt";
  41.        
  42.         int pos = 0;
  43.        
  44.         // für jedes y wird 20 draufgerechnet
  45.         for(int i=0; i < posY; i++)
  46.             pos+=20;
  47.            
  48.         // für jedes x wird 1 draufgerechnet
  49.         for(int i=0; i < posX; i++)
  50.             pos++;
  51.        
  52.         //---------- anfang wo gehts ----------
  53.        
  54.         try
  55.         {
  56.             // falls man von oben kommt wird oben nicht geschaut
  57.             if(direction != 3)
  58.             {
  59.                 cout << "nach oben schauen" << endl;
  60.                 // ---
  61.                 if(map[pos-20] == '.')
  62.                 {
  63.                     cout << "nach oben geht" << endl;
  64.                     int ep = nav(posX-20, posY, posX, posY);
  65.                     if(ep != 0)
  66.                     {
  67.                         endpos = ep;
  68.                         end = true;
  69.                     }
  70.                 }
  71.                 // ---
  72.                 if(map[pos-20] == 'O')
  73.                 {
  74.                     endpos = pos-20;
  75.                     end = true;
  76.                 }
  77.             }
  78.         }
  79.         catch(...)
  80.         {
  81.             cout << "Fehler: oben feht ein feld" << endl;
  82.         }
  83.        
  84.         try
  85.         {
  86.             // falls man von unten kommt wird unten nicht geschaut
  87.             if(direction !=4)
  88.             {
  89.                 cout << "nach unten schauen" << endl;
  90.                 // ---
  91.                 if(map[pos+20] == '.')
  92.                 {
  93.                     cout << "nach unten geht" << endl;
  94.                     int ep = nav(posX+20, posY, posX, posY);
  95.                     if(ep != 0)
  96.                     {
  97.                         endpos = ep;
  98.                         end = true;
  99.                     }
  100.                 }
  101.                 // ---
  102.                 if(map[pos+20] == 'O')
  103.                 {
  104.                     endpos = pos+20;
  105.                     end = true;
  106.                 }
  107.             }
  108.         }
  109.         catch(...)
  110.         {
  111.             cout << "Fehler: unten feht ein feld" << endl;
  112.         }
  113.        
  114.         try
  115.         {
  116.             // falls man von rechts kommt wird rechts nicht geschaut
  117.             if(direction !=2)
  118.             {
  119.                 cout << "nach rechts schauen" << endl;
  120.                 // ---
  121.                 if(map[pos+1] == '.')
  122.                 {
  123.                     cout << "nach rechts geht" << endl;
  124.                     int ep = nav(posX+1, posY, posX, posY);
  125.                     if(ep != 0)
  126.                     {
  127.                         endpos = ep;
  128.                         end = true;
  129.                     }
  130.                 }
  131.                 // ---
  132.                 if(map[pos+1] == 'O')
  133.                 {
  134.                     endpos = pos+1;
  135.                     end = true;
  136.                 }
  137.             }
  138.         }
  139.         catch(...)
  140.         {
  141.             cout << "Fehler: rechts feht ein feld" << endl;
  142.         }
  143.        
  144.         try
  145.         {
  146.             // falls man von links kommt wird links nicht geschaut
  147.             if(direction !=1)
  148.             {
  149.                 cout << "nach links schauen" << endl;
  150.                 // ---
  151.                 if(map[pos-1] == '.')
  152.                 {
  153.                     cout << "nach links geht" << endl;
  154.                     int ep = nav(posX-1, posY, posX, posY);
  155.                     if(ep != 0)
  156.                     {
  157.                         endpos = ep;
  158.                         end = true;
  159.                     }
  160.                 }
  161.                 // ---
  162.                 if(map[pos-1] == 'O')
  163.                 {
  164.                     endpos = pos-1;
  165.                     end = true;
  166.                 }
  167.             }
  168.         }
  169.         catch(...)
  170.         {
  171.             cout << "Fehler: links feht ein Feld" << endl;
  172.         }
  173.        
  174.         //---------- ende wo gehts ----------
  175.        
  176.         if(end == true)
  177.         {
  178.             return endpos;
  179.         }
  180.     }
  181.     return endpos;
  182. }
  183.  
  184. int nav()
  185. {
  186.     int posX = 0; // 0
  187.     int posY = 1;
  188.    
  189.     int lastpointX = -1; // -1
  190.     int lastpointY = 0;
  191.    
  192.     return nav(posX, posY, lastpointX, lastpointY);
  193. }
  194.  
  195. int main()
  196. {
  197.     int pos = nav();
  198.     if(pos != 0)
  199.     {
  200.         // aus zahl zu x, y umrechnen
  201.     }
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement