Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 DEFAULT = 0;
- /**
- * even start
- */
- private static final int EVEN_START = 2;
- /**
- * odd start
- */
- public static final int ODD_START = 1;
- /**
- * data size final variable
- */
- private static final int DATA_SIZE = 4;
- private static int[] spinOut;
- private static int[] compArray;
- 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) {
- compArray = new int[DATA_SIZE];
- spinOut = new int[numOfSwitches];
- compArray[SWITCH_NUM] = numOfSwitches;
- int index = numOfSwitches;
- unlockGame(index);
- compArray[TOTAL_STEPS] = compArray[LOCK_STEPS]
- + compArray[UNLOCK_STEPS];
- return compArray;
- }
- /**
- * This method will play through the game, acquiring step data
- *
- * @param compArray
- * array were data will be stored
- * @param spinOut
- * array with values for locked or unlocked switches
- * @param index
- * spot on the array to start unlocking
- */
- public static void unlockGame(int index) {
- if(Math.abs(DEFAULT - index) % 2 == 0 && !isSolved()){
- index --;
- flip(index);
- if(isSolved()){
- }
- }
- else {
- flip(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() {
- for (int i = DEFAULT; i < spinOut.length; i++) {
- if (spinOut[i] != UNLOCKED) {
- return false;
- }
- }
- return true;
- }
- public static void flip(int index){
- if(spinOut[index] == UNLOCKED){
- spinOut[index] = LOCKED;
- }
- else {
- spinOut[index] = UNLOCKED;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement