Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package edu.ben.labs.lab3;
- public class lab3 {
- /**
- * final variable for locked switch
- */
- private static final int LOCKED = 0;
- /**
- * final variable for unlocked switch
- */
- private static final int UNLOCKED = 1;
- /**
- * final variable for the number of switches spot on the array
- */
- private static final int SWITCH_NUM = 0;
- /**
- * final variable for the number of lock steps spot on the array
- */
- private static final int LOCK_STEPS = 1;
- /**
- * final variable for the number of unlock steps spot on the array
- */
- private static final int UNLOCK_STEPS = 2;
- /**
- * final variable for the total number of steps spot on the array
- */
- private static final int TOTAL_STEPS = 3;
- /**
- * counter start
- */
- private static final int COUNT_START = 0;
- /**
- * even start
- */
- private static final int EVEN_START = 1;
- /**
- * odd start
- */
- public static final int ODD_START = 0;
- /**
- * data size final variable
- */
- private static final int DATA_SIZE = 4;
- public static void main(String[] args){
- int[] toDisplay = compute(3);
- for(int i = 0; i < toDisplay.length; i++){
- System.out.println(toDisplay[i]);
- }
- }
- /**
- * This method will compute the amount of steps it takes to play Spin Out
- *
- * @param numOfSwitches
- * the amount of switches in the game
- * @return int array with the steps info for the game
- */
- public static int[] compute(int numOfSwitches) {
- int[] compArray = new int[DATA_SIZE];
- int[] spinOut = new int[numOfSwitches];
- compArray[SWITCH_NUM] = numOfSwitches;
- int index;
- if(numOfSwitches%2 == 0){
- index = EVEN_START;
- }
- else {
- index = ODD_START;
- }
- unlockGame(compArray, spinOut, index);
- compArray[TOTAL_STEPS] = compArray[LOCK_STEPS] + compArray[UNLOCK_STEPS];
- return compArray;
- }
- /**
- * This method will play through the game, aquiring step data
- * @param compArray array were data will be stored
- * @param spinOut
- * @param index
- */
- public static void unlockGame(int[] compArray, int[] spinOut, int index){
- //temp...must change it
- if(index + 2 < spinOut.length){
- //This does not work...fix it
- if(index + 3 %2 != 0){
- spinOut[index] = UNLOCKED;
- compArray[UNLOCK_STEPS]++;
- spinOut[index + 2] = UNLOCKED;
- compArray[UNLOCK_STEPS]++;
- spinOut[index] = LOCKED;
- compArray[LOCK_STEPS]++;
- spinOut[index + 1] = UNLOCKED;
- compArray[UNLOCK_STEPS]++;
- spinOut[index] = UNLOCKED;
- }
- }
- //Will it work?
- if(!isSolved(spinOut)){
- unlockGame(compArray, spinOut, index);
- }
- }
- /**
- * Checks to see if the game has been solved
- *
- * @param spinOut
- * array of switches
- * @return boolean true or false depending on whether the game has been
- * solved
- */
- public static boolean isSolved(int[] spinOut) {
- for (int i = COUNT_START; i < spinOut.length; i++) {
- if (spinOut[i] != UNLOCKED) {
- return false;
- }
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement