Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <array>
- using namespace std;
- int nav(int posX, int posY, int lastpointX, int lastpointY)
- {
- string map = "XXXXXXXXXXXXXXXXXXXXO.XXX...XXXXXX...X.OX...X.X.X...XX.X...XXXX.X.X...X....XXXXXXXX...XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
- /*
- * XXXXXXXXXXXXXXXXXXXX
- * O.XXX...XXXXXX...X.O
- * X...X.X.X...XX.X...X
- * XXX.X.X...X....XXXXX
- * XXX...XXXXXXXXXXXXXX
- * XXXXXXXXXXXXXXXXXXXX
- */
- // 20 pro zeile
- bool end = false;
- int endpos = 0;
- while(end != true)
- {
- int direction = 0;
- // direction 1 = von links
- // direction 2 = von rechts
- // direction 3 = von oben
- // direction 4 = von unten
- if(lastpointX < posX)
- direction = 1;
- else if(lastpointX > posX)
- direction = 2;
- else if(lastpointY < posY)
- direction = 3;
- else if(lastpointY < posY)
- direction = 4;
- else
- cout << "lastpoint nicht bekannt";
- int pos = 0;
- // für jedes y wird 20 draufgerechnet
- for(int i=0; i < posY; i++)
- pos+=20;
- // für jedes x wird 1 draufgerechnet
- for(int i=0; i < posX; i++)
- pos++;
- //---------- anfang wo gehts ----------
- try
- {
- // falls man von oben kommt wird oben nicht geschaut
- if(direction != 3)
- {
- cout << "nach oben schauen" << endl;
- // ---
- if(map[pos-20] == '.')
- {
- cout << "nach oben geht" << endl;
- int ep = nav(posX-20, posY, posX, posY);
- if(ep != 0)
- {
- endpos = ep;
- end = true;
- }
- }
- // ---
- if(map[pos-20] == 'O')
- {
- endpos = pos-20;
- end = true;
- }
- }
- }
- catch(...)
- {
- cout << "Fehler: oben feht ein feld" << endl;
- }
- try
- {
- // falls man von unten kommt wird unten nicht geschaut
- if(direction !=4)
- {
- cout << "nach unten schauen" << endl;
- // ---
- if(map[pos+20] == '.')
- {
- cout << "nach unten geht" << endl;
- int ep = nav(posX+20, posY, posX, posY);
- if(ep != 0)
- {
- endpos = ep;
- end = true;
- }
- }
- // ---
- if(map[pos+20] == 'O')
- {
- endpos = pos+20;
- end = true;
- }
- }
- }
- catch(...)
- {
- cout << "Fehler: unten feht ein feld" << endl;
- }
- try
- {
- // falls man von rechts kommt wird rechts nicht geschaut
- if(direction !=2)
- {
- cout << "nach rechts schauen" << endl;
- // ---
- if(map[pos+1] == '.')
- {
- cout << "nach rechts geht" << endl;
- int ep = nav(posX+1, posY, posX, posY);
- if(ep != 0)
- {
- endpos = ep;
- end = true;
- }
- }
- // ---
- if(map[pos+1] == 'O')
- {
- endpos = pos+1;
- end = true;
- }
- }
- }
- catch(...)
- {
- cout << "Fehler: rechts feht ein feld" << endl;
- }
- try
- {
- // falls man von links kommt wird links nicht geschaut
- if(direction !=1)
- {
- cout << "nach links schauen" << endl;
- // ---
- if(map[pos-1] == '.')
- {
- cout << "nach links geht" << endl;
- int ep = nav(posX-1, posY, posX, posY);
- if(ep != 0)
- {
- endpos = ep;
- end = true;
- }
- }
- // ---
- if(map[pos-1] == 'O')
- {
- endpos = pos-1;
- end = true;
- }
- }
- }
- catch(...)
- {
- cout << "Fehler: links feht ein Feld" << endl;
- }
- //---------- ende wo gehts ----------
- if(end == true)
- {
- return endpos;
- }
- }
- return endpos;
- }
- int nav()
- {
- int posX = 0; // 0
- int posY = 1;
- int lastpointX = -1; // -1
- int lastpointY = 0;
- return nav(posX, posY, lastpointX, lastpointY);
- }
- int main()
- {
- int pos = nav();
- if(pos != 0)
- {
- // aus zahl zu x, y umrechnen
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement