Advertisement
meshdev

Untitled

Jan 10th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.21 KB | None | 0 0
  1. package kb;
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5.  
  6. //----------------------------------------------------
  7. //----------------------------------------------------
  8. public class smellTest {
  9.     public static void main(String[] args) {
  10.         Scanner sc = new Scanner(System.in);
  11.         int[][] plane = new int [sc.nextInt()][sc.nextInt()];
  12.         sc.close();
  13.         //fill the plane with only zeroes to be sure there can only be zeroes used for placement later
  14.         for ( int planeFillerI = 0 ; plane[0].length > planeFillerI ; planeFillerI++ ){
  15.             for ( int planeFillerJ = 0 ; plane[1].length > planeFillerJ ; planeFillerJ++ ) {
  16.                 plane[planeFillerI][planeFillerJ] = 0;
  17.             }
  18.         }
  19.        
  20.         // compute shortSide
  21.         int shortSide = 0 ;
  22.         if (plane[0].length > plane[1].length) shortSide = plane[1].length/2;
  23.         else shortSide = plane[0].length / 2;
  24.         // end shortSide
  25.  
  26.         //create Hunter and Prey lists
  27.         int[] hunterX = new int [shortSide] ;
  28.         int[] hunterY = new int [shortSide] ;
  29.         //end lists
  30.  
  31.         fil(plane, shortSide);
  32.         printDX(plane);
  33.         fillList(plane, hunterX, hunterY);
  34.         printU(shortSide, hunterX, hunterY);
  35.         canSmell(plane, hunterX, hunterY);
  36.     }
  37.     //----------------------------------------------------
  38.     //----------------------------------------------------
  39.     public static void canSmell( int[][] plane , int[] hunterX, int[] hunterY ) throws ArrayIndexOutOfBoundsException {
  40.         //int pl0 = plane[0].length; // required once so no compute effext can be seen
  41.         int pl1 = plane[1].length;
  42.         for ( int i = 0 ; i < hunterX.length ; i++ ) {
  43.             int x = hunterY[i];
  44.             int y = hunterX[i];
  45.             if( x == 0 ) {
  46.                 if( y == 0 ) canSmellDL(plane, x, y);
  47.                 else if ( y == pl1) canSmellDR(plane, x, y);
  48.                 else canSmellD(plane, x, y);
  49.             }
  50.             else if ( x == plane[0].length ) {
  51.                 if( y == 0 ) canSmellUL(plane, x, y);
  52.                 else if ( y == pl1 ) canSmellUR(plane, x, y);
  53.                 else canSmellU(plane, x, y);
  54.             }
  55.             else {
  56.                 if( y == 0 ) canSmellU(plane, x, y);
  57.                 else if ( y == pl1) canSmellD(plane, x, y);
  58.                 else canSmellM(plane, x, y);
  59.             }
  60.         }
  61.     }
  62.     /**
  63.      * if ( plane[x + 1][y] == 1 ) break;
  64.             else if ( plane[x - 1][y] == 1 ) break;
  65.             else if ( plane[x][y + 1] == 1 ) break;
  66.             else if ( plane[x][y - 1] == 1 ) break;
  67.             else return;
  68.      * It's dangerous to go alone take this
  69.      */
  70.     //----------------------------------------------------
  71.     public static void canSmellM(int[][] plane, int x, int y){
  72.         if ( plane[x + 1][y] == 1 ) right();
  73.             else if ( plane[x - 1][y] == 1 ) left();
  74.             else if ( plane[x][y + 1] == 1 ) below();
  75.             else if ( plane[x][y - 1] == 1 ) above();
  76.             else return;
  77.     }
  78.     //----------------------------------------------------
  79.     public static void canSmellU(int[][] plane, int x, int y){
  80.         if ( plane[x + 1][y] == 1 ) right();
  81.             else if ( plane[x - 1][y] == 1 ) left();
  82.             else if ( plane[x][y + 1] == 1 ) below();
  83.             else return;
  84.     }
  85.     //----------------------------------------------------
  86.     public static void canSmellUL(int[][] plane, int x, int y){
  87.         if ( plane[x + 1][y] == 1 ) right();
  88.             else if ( plane[x][y + 1] == 1 ) below();
  89.             else return;
  90.     }
  91.     //----------------------------------------------------
  92.     public static void canSmellUR(int[][] plane, int x, int y){
  93.         if ( plane[x - 1][y] == 1 ) left();
  94.             else if ( plane[x][y + 1] == 1 ) below();
  95.             else return;
  96.     }
  97.     //----------------------------------------------------
  98.     public static void canSmellD(int[][] plane, int x, int y){
  99.         if ( plane[x + 1][y] == 1 ) right();
  100.             else if ( plane[x - 1][y] == 1 ) left();
  101.             else if ( plane[x][y - 1] == 1 ) above();
  102.             else return;
  103.     }
  104.     //----------------------------------------------------
  105.     public static void canSmellDR(int[][] plane, int x, int y){
  106.         if ( plane[x - 1][y] == 1 ) left();
  107.             else if ( plane[x][y - 1] == 1 ) above();
  108.             else return;
  109.     }
  110.     //----------------------------------------------------
  111.     public static void canSmellDL(int[][] plane, int x, int y){
  112.         if ( plane[x + 1][y] == 1 ) right();
  113.             else if ( plane[x][y - 1] == 1 ) above();
  114.             else return;
  115.     }
  116.     //----------------------------------------------------
  117.     public static void canSmellR(int[][] plane, int x, int y){
  118.         if ( plane[x - 1][y] == 1 ) left();
  119.             else if ( plane[x][y + 1] == 1 ) below();
  120.             else if ( plane[x][y - 1] == 1 ) above();
  121.             else return;
  122.     }
  123.     //----------------------------------------------------
  124.     public static void canSmellL(int[][] plane, int x, int y){
  125.         if ( plane[x + 1][y] == 1 ) right();
  126.             else if ( plane[x][y + 1] == 1 ) below();
  127.             else if ( plane[x][y - 1] == 1 ) above();
  128.             else return;
  129.     }
  130.     //----------------------------------------------------
  131.     public static void below() {
  132.         System.out.print("Below\n---------------\n");        
  133.     }
  134.     public static void above() {
  135.         System.out.print("Below\n---------------\n");        
  136.     }
  137.     public static void left() {
  138.         System.out.print("Below\n---------------\n");        
  139.     }
  140.     public static void right() {
  141.         System.out.print("Below\n---------------\n");
  142.     }
  143.     //----------------------------------------------------
  144.     public static void printU(int shortSide , int[] hunterX, int[] hunterY) {
  145.         for( int i = 0 ; shortSide > i ; i++ ) {
  146.             System.out.println(i + " : ( " + hunterX[i] + " | " + hunterY[i] + " )");
  147.         }
  148.     }
  149.     //----------------------------------------------------
  150.     public static void fillList (int[][] plane, int[] hunterX, int[] hunterY ) {
  151.         int counter = 0;
  152.         for ( int i = 0 ; plane[0].length > i ; i++ ) {
  153.             for ( int j = 0 ; plane[1].length > j ; j++ ) {
  154.                 if(plane[i][j] == 1){
  155.                     hunterX[counter] = i ;
  156.                     hunterY[counter] = j ;
  157.                     counter++;
  158.                 }
  159.             }
  160.         }
  161.     }
  162.     //----------------------------------------------------
  163.     public static void fil ( int[][] plane , int shortSide) {
  164.         Random rng = new Random();
  165.         for ( int o = 0 ; shortSide > o ; o++ ){
  166.             boolean isNotFilled = true;
  167.             while(isNotFilled){                         //used to have it rerolled until a hunter can be placed
  168.                 int x = rng.nextInt( plane[0].length - 1 );
  169.                 int y = rng.nextInt( plane[1].length - 1 );
  170.                 if ( ! (plane[x][y] == 1) ){            // do not fill the same space with more than one onject
  171.                     plane[x][y] = 1 ;
  172.                     isNotFilled = false;
  173.                 }
  174.             }
  175.         }
  176.     }
  177.     //----------------------------------------------------
  178.     public static void printDX( int[][] plane ) {
  179.         for( int i = 0 ; i < plane[0].length ; i++ ) { //[x][y]
  180.             for( int j = 0 ; j < plane[1].length ; j++ ) {
  181.                 //x iteration do not forget about this !!!important!!! DO NOT FORGET AGAIN
  182.                 //No srs don't look for the a non existing logic issue just go [j][i] again and not [i][j]
  183.                 switch(plane[j][i]){
  184.                     case 1:
  185.                         System.out.print("h");
  186.                         break;
  187.                     case 2:
  188.                         System.out.print("p");
  189.                         break;
  190.                     default :
  191.                         System.out.print("0");
  192.                         break;
  193.                 }
  194.             }
  195.             System.out.println("");
  196.         }
  197.     }
  198.     //----------------------------------------------------
  199.     //----------------------------------------------------
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement