public class Lab3 { static void testLightCandles1() { Robot.load("candles1.txt"); Robot.setDelay(0.05); Lab3.lightCandles(); } static void testLightCandles2() { Robot.load("candles2.txt"); Robot.setDelay(0.05); Lab3.lightCandles(); } public static void lightCandles() { //insert instructions below lightOneCandle(); lightOneCandle(); lightOneCandle(); lightOneCandle(); lightOneCandle(); lightOneCandle(); lightOneCandle(); lightOneCandle(); lightOneCandle(); lightOneCandle(); } // Before: Robot is facing right, facing the bottom of the next candle. // After: Robot is facing right, facing the bottom of the next candle (if any) public static void lightOneCandle() { // Move robot up one level, still facing right Robot.turnLeft(); Robot.move(); Lab3.turnRight(); // If the candle is one block high, then the front of robot should be clear if (Robot.frontIsClear()) { // Move forward, light candle Robot.move(); Robot.makeDark(); Robot.move(); Lab3.turnRight(); Robot.move(); Robot.turnLeft(); } else { // Candle must be two blocks high so move up one more level Robot.turnLeft(); Robot.move(); Lab3.turnRight(); Robot.move(); Robot.makeDark(); Robot.move(); Lab3.turnRight(); Robot.move(); Robot.move(); Robot.turnLeft(); } } public static void turnRight() { Robot.turnLeft(); Robot.turnLeft(); Robot.turnLeft(); } public static void backUp() { Robot.turnLeft(); Robot.turnLeft(); Robot.move(); Robot.turnLeft(); Robot.turnLeft(); } //Run this method to test completeRoom on map room1.txt static void testCompleteRoom1() { Robot.load("room1.txt"); Robot.setDelay(0.05); Lab3.completeRoom(); } //Run this method to test completeRoom on map room2.txt static void testCompleteRoom2() { Robot.load("room2.txt"); Robot.setDelay(0.05); Lab3.completeRoom(); } //Complete this method. You will need to write additional helper methods. public static void completeRoom() { //insert instructions below completeOneSide(); completeOneSide(); completeOneSide(); completeOneSide(); } public static void completeOneSide() { checkOneCell(); Robot.move(); checkOneCell(); Robot.move(); checkOneCell(); Robot.move(); checkOneCell(); Robot.move(); checkOneCell(); Lab3.turnRight(); } public static void checkOneCell() { Robot.turnLeft(); if (Robot.frontIsClear()) { Robot.move(); if (!Robot.onDark()) { Robot.makeDark(); } Lab3.backUp(); } Lab3.turnRight(); } //Run this method to test swapAll on map swap1.txt static void testSwapAll1() { Robot.load("swap1.txt"); Robot.setDelay(0.05); Lab3.swapAll(); } //Run this method to test swapAll on map swap2.txt static void testSwapAll2() { Robot.load("swap2.txt"); Robot.setDelay(0.05); Lab3.swapAll(); } //Complete this method. You will need to write additional helper methods. public static void swapAll() { //insert instructions below swapRow(); swapRow(); swapRow(); swapRow(); swapRow(); swapRow(); swapRow(); swapRow(); swapRow(); swapRow(); } public static void swapRow() { if (differentColors()) { changeColors(); } else { dontChangeColors(); } if (Robot.frontIsClear()) { Robot.move(); } } public static boolean differentColors() { Robot.turnLeft(); Robot.move(); if (Robot.onDark()) { Lab3.backUp(); Lab3.backUp(); if (Robot.onDark()) { return false; } else { return true; } } else { Lab3.backUp(); Lab3.backUp(); if (!Robot.onDark()) { return false; } else { return true; } } } public static void changeColors() { // This method is called only if the two colors are different. // Afterwards, restore robot to point up in middle column. Lab3.toggleColor(); Robot.move(); Robot.move(); Lab3.toggleColor(); Lab3.backUp(); Lab3.turnRight(); } public static void dontChangeColors() { // Restore robot to point up in middle column. Robot.move(); Lab3.turnRight(); } public static void toggleColor() { if (Robot.onDark()) { Robot.makeLight(); } else { Robot.makeDark(); } } }