CSnathan

ACSL Lights Out

Mar 1st, 2017
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.80 KB | None | 0 0
  1. //***********************************************
  2. // Nathan Schnitzer
  3. // 3/1/17
  4. //********************************
  5.  
  6. import java.util.Arrays;
  7. import java.util.Scanner;
  8.  
  9. public class LightsOut {
  10.  
  11.     public static void main(String[] args) {
  12.         int rowAmount;
  13.         int strNumbers = 0;
  14.         String indicateTile;
  15.         Scanner scan = new Scanner(System.in);
  16.         boolean[] power = new boolean[64];
  17.         String[] position = new String[64];
  18.         String[] desc = new String[64];
  19.        
  20.         //Set all desc values to "none"
  21.         for (int a = 0; a < 64; a++)
  22.         {
  23.             desc[a] = "none";
  24.         }
  25.        
  26.        
  27.        
  28.         System.out.println("Enter the amount of rows");
  29.         rowAmount = scan.nextInt();
  30.         String[] locations = new String[rowAmount];
  31.        
  32.         for (int w = 0; w < rowAmount; w++)
  33.         {
  34.             System.out.println("Enter a string:");
  35.             locations[w] = scan.next();
  36.             strNumbers = w;
  37.         }
  38.        
  39.         //Prompt for the tile indication string
  40.         System.out.println("Enter the location of the pressed tile");
  41.         indicateTile = scan.next();
  42.        
  43.         System.out.println(Character.toString(locations[0].charAt(0)));
  44.        
  45.         //set all power[] values to false
  46.         for (int k = 0; k < 64; k++)
  47.         {
  48.             power[k] = false;
  49.         }
  50.        
  51.         //set all value[] values to its position
  52.         // i is the row & m is the column (0,0) is top right
  53.         for (int i = 0; i < 8; i++)
  54.         {
  55.             for (int m = 0; m < 8; m++)
  56.             {
  57.                 //Array its on
  58.                 int n = (i*8) + m;
  59.                 position[n] = "" + i + m;
  60.             }
  61.         }
  62.        
  63.         int length;
  64.         String[] columns = new String[rowAmount];
  65.         String[] rows = new String[rowAmount];
  66.         String row;
  67.         String loc = "";
  68.         for (int r = 0; r <= strNumbers; r++)
  69.         {
  70.             columns[r] = Character.toString(locations[r].charAt(0));
  71.             length = locations[r].length();
  72.             row = Character.toString(locations[r].charAt(0));
  73.             boolean match = false;
  74.             for (int o = 1; o < length -1; o++)
  75.             {
  76.                 columns[o] = Character.toString(locations[r].charAt(o));
  77.                 loc = row.concat(columns[o]);
  78.                 for (int c = 0; c < 64; c++)
  79.                 {
  80.                     power[Integer.valueOf(loc)] = true;
  81.                     desc[Integer.valueOf(loc)] = "on";
  82.                 }
  83.             }
  84.         }
  85.         int tracker = 0;
  86.         while(tracker < 64)
  87.         {
  88.         boolean tenDown = false, tenUp = false, oneDown = false, oneUp = false;
  89.        
  90.         //Set the pressed tiles values
  91.         power[Integer.valueOf(indicateTile)] = true;
  92.         desc[Integer.valueOf(indicateTile)] = "pressed";
  93.        
  94.         //Set all tiles values adjacent to pressed tile
  95.         if (Integer.valueOf(indicateTile) > 10)
  96.         {
  97.         desc[(Integer.valueOf(indicateTile))-10] = "adjacent a";
  98.         tenDown = true;
  99.         }
  100.         if (!(Integer.valueOf(indicateTile) >= 70))
  101.         {
  102.             desc[(Integer.valueOf(indicateTile))+10] = "adjacent a";
  103.             tenUp = true;
  104.         }
  105.        
  106.         if ((Integer.valueOf(indicateTile))/10 != (int)Integer.valueOf(indicateTile))
  107.         {
  108.             desc[(Integer.valueOf(indicateTile)) -1] = "adjacent a";
  109.             oneDown = true;
  110.         }
  111.        
  112.         if (((Integer.valueOf(indicateTile))-7)/10 != (int)Integer.valueOf(indicateTile))
  113.         {
  114.             desc[(Integer.valueOf(indicateTile)) + 1] = "adjacent a";
  115.             oneUp = true;
  116.         }
  117.        
  118.         if (oneUp == true)
  119.         {
  120.             if (Integer.valueOf(indicateTile) > 20)
  121.             {
  122.             desc[(Integer.valueOf(indicateTile))-20] = "adjacent b";
  123.             }
  124.             if (!(Integer.valueOf(indicateTile) >= 60))
  125.             {
  126.                 desc[(Integer.valueOf(indicateTile))+20] = "adjacent b";
  127.             }
  128.            
  129.             if ((Integer.valueOf(indicateTile))/10 != (int)Integer.valueOf(indicateTile))
  130.             {
  131.                 desc[(Integer.valueOf(indicateTile)) -2] = "adjacent b";
  132.             }
  133.            
  134.             if (((Integer.valueOf(indicateTile))-7)/10 != (int)Integer.valueOf(indicateTile))
  135.             {
  136.                 desc[(Integer.valueOf(indicateTile)) + 2] = "adjacent b";
  137.             }
  138.         }
  139.        
  140.        
  141.         if (oneDown == true)
  142.         {
  143.             if (Integer.valueOf(indicateTile) > 20)
  144.             {
  145.             desc[(Integer.valueOf(indicateTile))-20] = "adjacent b";
  146.             }
  147.             if (!(Integer.valueOf(indicateTile) >= 60))
  148.             {
  149.                 desc[(Integer.valueOf(indicateTile))+20] = "adjacent b";
  150.             }
  151.            
  152.             if ((Integer.valueOf(indicateTile))/10 != (int)Integer.valueOf(indicateTile))
  153.             {
  154.                 desc[(Integer.valueOf(indicateTile)) -2] = "adjacent b";
  155.             }
  156.            
  157.             if (((Integer.valueOf(indicateTile))-7)/10 != (int)Integer.valueOf(indicateTile))
  158.             {
  159.                 desc[(Integer.valueOf(indicateTile)) + 2] = "adjacent b";
  160.             }
  161.         }
  162.        
  163.         if (tenUp == true)
  164.         {
  165.             if (Integer.valueOf(indicateTile) > 20)
  166.             {
  167.             desc[(Integer.valueOf(indicateTile))-20] = "adjacent b";
  168.             }
  169.             if (!(Integer.valueOf(indicateTile) >= 60))
  170.             {
  171.                 desc[(Integer.valueOf(indicateTile))+20] = "adjacent b";
  172.             }
  173.            
  174.             if ((Integer.valueOf(indicateTile))/10 != (int)Integer.valueOf(indicateTile))
  175.             {
  176.                 desc[(Integer.valueOf(indicateTile)) -2] = "adjacent b";
  177.             }
  178.            
  179.             if (((Integer.valueOf(indicateTile))-7)/10 != (int)Integer.valueOf(indicateTile))
  180.             {
  181.                 desc[(Integer.valueOf(indicateTile)) + 2] = "adjacent b";
  182.             }
  183.         }
  184.        
  185.        
  186.         if (tenDown == true)
  187.         {
  188.             if (Integer.valueOf(indicateTile) > 20)
  189.             {
  190.             desc[(Integer.valueOf(indicateTile))-20] = "adjacent b";
  191.             }
  192.             if (!(Integer.valueOf(indicateTile) >= 60))
  193.             {
  194.                 desc[(Integer.valueOf(indicateTile))+20] = "adjacent b";
  195.             }
  196.            
  197.             if ((Integer.valueOf(indicateTile))/10 != (int)Integer.valueOf(indicateTile))
  198.             {
  199.                 desc[(Integer.valueOf(indicateTile)) -2] = "adjacent b";
  200.             }
  201.            
  202.             if (((Integer.valueOf(indicateTile))-7)/10 != (int)Integer.valueOf(indicateTile))
  203.             {
  204.                 desc[(Integer.valueOf(indicateTile)) + 2] = "adjacent b";
  205.             }
  206.         }
  207.        
  208.         int count = 0;
  209.         for (int x = 0; x < 64; x++)
  210.         {
  211.             if ((desc[x].equals("adjacent a") || desc[x].equals("adjacent b")) && power[x] == false)
  212.                 count++;
  213.         }
  214.         System.out.println(Integer.valueOf(loc));
  215.         System.out.println(loc);
  216.         System.out.println(Character.toString(locations[0].charAt(0)));
  217.         System.out.println(Arrays.toString(power));
  218.         System.out.println(Arrays.toString(position));
  219.         System.out.println(Arrays.toString(desc));
  220.         System.out.println(count);
  221.     }
  222.  
  223. }
  224. }
Advertisement
Add Comment
Please, Sign In to add comment