Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.25 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /*
  4.  * Create by Arthur, Dennis, Dimitri
  5.  */
  6.  
  7. public class PathNodes{
  8.     private static int xz; //Ziel in x Koordinate
  9.     private static int yz; //Ziel in y Koordinate
  10.     private static int x; //Start in x Koordinate
  11.     private static int y; //Start in y Koordinate
  12.     private static int counter; //Zähler für die Pfade
  13.  
  14.     public static void main(String[] args) {
  15.  
  16.         //Scanner sc = new Scanner(System.in); //ermöglicht Eingabe
  17.         //System.out.print("Bitte eine Zahl eingeben (> 0)" + ": "); //Test zum eingeben
  18.         //int eingabe = sc.nextInt(); //scannt den Eingabewert
  19.         //if (eingabe > 0) {//Wenn Eingabe größer als 0 erfolgt
  20.  
  21.             xz = 1;//eingabe; //Ziel
  22.             yz = 1;//eingabe; //Ziel
  23.  
  24.             x = 0; //Start
  25.             y = 0; //Start
  26.             counter = 0;//Zähler
  27.  
  28.             search();
  29.  
  30.        // } else {//kleinere Zahl eingegeben als Erlaubt
  31.          //   System.out.println("Wups, da gab es wohl einen kleinen Fehler in der Eingabe. Bitte nochmals versuchen!");
  32.         }
  33.    // }
  34.  
  35.  
  36.     public static void right() {//Schritt nach oben!
  37.         x = x + 1;
  38.         counter = counter + 1;
  39.     }
  40.  
  41.     public static void rightup() {//Schritt nach obenrechts!
  42.         x = x + 1;
  43.         y = y + 1;
  44.         counter = counter + 1;
  45.     }
  46.  
  47.     public static void rightdown() {//Schritt nach rechtsunten!
  48.         x = x + 1;
  49.         y = y - 1;
  50.         counter = counter + 1;
  51.     }
  52.  
  53.     public static void up() {//Schritt nach oben!
  54.         y = y + 1;
  55.         counter = counter + 1;
  56.     }
  57.  
  58.     public static void upleft() {//Schritt nach obenlinks
  59.         x = x - 1;
  60.         y = y + 1;
  61.         counter = counter + 1;
  62.     }
  63.  
  64.     public static void sRight() {//Schritt nach oben! Startpunkt!!
  65.         x = x + 1;
  66.         counter = counter + 2;
  67.     }
  68.  
  69.     public static void sRightup() {//Schritt nach obenrechts! Startpunkt!!
  70.         x = x + 1;
  71.         y = y + 1;
  72.         counter = counter + 2;
  73.     }
  74.  
  75.     public static void sUp() {//Schritt nach oben! Startpunkt!!
  76.         y = y + 1;
  77.         counter = counter + 2;
  78.     }
  79.  
  80.  
  81.  
  82.     public static void search() {
  83.  
  84.         boolean direkt = true;
  85.         boolean oben = true;
  86.         boolean rechts = true;
  87.  
  88.  
  89.             if (direkt) {//der direkte Weg (zu Erst)
  90.                 for (int i = 0; i < xz; i++) {
  91.                     sRightup();
  92.                 }
  93.                 if (x == xz && y == yz) {
  94.                     direkt = false;
  95.                     x=0;
  96.                     y=0;
  97.                 }
  98.             }
  99.  
  100.                         if (oben) {//Weg nach oben (zweiter Weg)
  101.                             boolean upup = true;
  102.                             boolean updown = true;
  103.                             if (upup) {
  104.                                 for (int i = 0; i < yz; i++) {
  105.                                     sUp();
  106.                                 }
  107.                             }
  108.                             if (x < xz && y == yz) {
  109.                                 for (int i = 0; i < yz; i++) {
  110.                                     up();
  111.                                 }
  112.                             }
  113.                             if (x < xz && y > yz){
  114.                                 for (int ii = 0; ii < yz; ii++){
  115.                                     rightdown();
  116.                                 }
  117.                             }
  118.                             if (x == xz && y == yz) {
  119.                                 upup = false;
  120.                                 x = 0;
  121.                                 y = 0;
  122.                             }
  123.  
  124.                                         if (updown) {//Weg nach oben und dann unten!
  125.                                             for (int i = 0; i < xz; i++)
  126.                                                 sUp();
  127.                                             if (x < xz && y == yz) {
  128.                                                 for (int i = 0; i < xz; i++) {
  129.                                                     rightdown();
  130.                                                 }
  131.                                             }
  132.                                             if (x == xz && y < yz) {
  133.                                                 for (int ii = 0; ii < xz; ii++) {
  134.                                                     right();
  135.                                                 }
  136.                                             }
  137.                                             if (x > xz && y < yz) {
  138.                                                 for (int iii = 0; iii < xz; iii++) {
  139.                                                     upleft();
  140.                                                 }
  141.                                             }
  142.                                             if(x == xz && y == yz){
  143.                                                 updown = false;
  144.                                                 oben = false;
  145.                                                 x=0;
  146.                                                 y=0;
  147.                                         }
  148.                             }
  149.                         }
  150.         if(rechts) {//dritter Weg
  151.             boolean rightright = true;
  152.             boolean rightup = true;
  153.             if (rightright) {//Der Weg nach rechts
  154.                 for (int i = 0; i < xz; i++) {
  155.                     sRight();
  156.                 }
  157.                 if (x == xz && y < yz) {
  158.                     for (int ii = 0; ii < xz; ii++) {
  159.                         right();
  160.                     }
  161.                 }
  162.                 if (x > xz && y < yz) {
  163.                     for (int iii = 0; iii < xz; iii++) {
  164.                         upleft();
  165.                     }
  166.                 }
  167.                 if(x ==xz && y == yz){
  168.                     rightright = false;
  169.                     x=0;
  170.                     y=0;
  171.                 }
  172.             }
  173.                             if(rightup){//Der Weg nach rechts und dann oben
  174.                                 for(int i = 0;i<xz;i++){
  175.                                     sRight();
  176.                                 }
  177.                                 if(x == xz && y < yz){
  178.                                     for(int ii = 0;ii<yz;ii++){
  179.                                         upleft();
  180.                                     }
  181.                                 }
  182.                                 if(x < xz && y ==yz){
  183.                                     for(int iii =0; iii<yz;iii++){
  184.                                         up();
  185.                                     }
  186.                                 }
  187.                                 if(x < xz && y > yz){
  188.                                     for(int iiii=0; iiii<yz;iiii++){
  189.                                         rightdown();
  190.                                     }
  191.                                 }
  192.                                 if(x ==xz && y == yz){
  193.                                     rightup = false;
  194.                                     rechts = false;
  195.                                     x = 0;
  196.                                     y = 0;
  197.                                 }
  198.                             }
  199.         }
  200.  
  201.         System.out.println("Es gab genau " +counter+ " Pfade");
  202.     }//end search()
  203. }//end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement