/** @param args the command line arguments */ public static void main(String[] args) { // create city, robot and environment City thomas = new City(); Robot tom = new Robot(thomas, 3, 1, Direction.NORTH); new Wall(thomas, 1, 1, Direction.NORTH); new Wall(thomas, 1, 1, Direction.EAST); new Wall(thomas, 1, 1, Direction.SOUTH); new Wall(thomas, 1, 1, Direction.WEST); new Wall(thomas, 2, 2, Direction.NORTH); new Wall(thomas, 2, 2, Direction.WEST); new Wall(thomas, 3, 2, Direction.WEST); new Wall(thomas, 4, 1, Direction.WEST); new Wall(thomas, 4, 1, Direction.NORTH); new Wall(thomas, 4, 1, Direction.SOUTH); new Wall(thomas, 4, 1, Direction.EAST); new Wall(thomas, 2, 3, Direction.NORTH); new Wall(thomas, 3, 2, Direction.SOUTH); new Wall(thomas, 3, 3, Direction.SOUTH); new Wall(thomas, 4, 4, Direction.WEST); new Wall(thomas, 4, 4, Direction.NORTH); new Wall(thomas, 4, 4, Direction.EAST); new Wall(thomas, 4, 4, Direction.SOUTH); new Wall(thomas, 3, 3, Direction.EAST); new Wall(thomas, 2, 3, Direction.EAST); new Wall(thomas, 1, 4, Direction.EAST); new Wall(thomas, 1, 4, Direction.SOUTH); new Wall(thomas, 1, 4, Direction.NORTH); new Wall(thomas, 1, 4, Direction.WEST); // a right side following robot // loop program while (true) { if (tom.frontIsClear()) { tom.turnLeft(); tom.turnLeft(); tom.turnLeft(); if (tom.frontIsClear()) { tom.move(); } } else { tom.turnLeft(); tom.move(); } } }
/** @param args the command line arguments */ public static void main(String[] args) { // Make city City A3Q3 = new City(); // Make robot Robot karel = new Robot(A3Q3, 2, 2, Direction.WEST); karel.setColor(Color.white); // MAKE WALLS // Top wall new Wall(A3Q3, 1, 1, Direction.NORTH); new Wall(A3Q3, 1, 3, Direction.NORTH); new Wall(A3Q3, 1, 4, Direction.NORTH); // Right wall new Wall(A3Q3, 1, 4, Direction.EAST); new Wall(A3Q3, 2, 4, Direction.EAST); new Wall(A3Q3, 3, 4, Direction.EAST); // Bottom wall new Wall(A3Q3, 3, 4, Direction.SOUTH); new Wall(A3Q3, 3, 3, Direction.SOUTH); new Wall(A3Q3, 3, 2, Direction.SOUTH); new Wall(A3Q3, 3, 1, Direction.SOUTH); // Left wall new Wall(A3Q3, 3, 1, Direction.WEST); new Wall(A3Q3, 2, 1, Direction.WEST); new Wall(A3Q3, 1, 1, Direction.WEST); // Code Solution while (karel.frontIsClear()) { karel.move(); } karel.turnLeft(); while (true) { karel.turnLeft(); karel.turnLeft(); karel.turnLeft(); if (!karel.frontIsClear()) { karel.turnLeft(); if (!karel.frontIsClear()) { karel.turnLeft(); } karel.move(); } else { karel.move(); break; } } }
/** @param args the command line arguments */ public static void main(String[] args) { // make city City kw = new City(); // make walls new Wall(kw, 1, 1, Direction.NORTH); new Wall(kw, 1, 3, Direction.NORTH); new Wall(kw, 1, 4, Direction.NORTH); new Wall(kw, 1, 4, Direction.EAST); new Wall(kw, 2, 4, Direction.EAST); new Wall(kw, 3, 4, Direction.EAST); new Wall(kw, 3, 4, Direction.SOUTH); new Wall(kw, 3, 3, Direction.SOUTH); new Wall(kw, 3, 2, Direction.SOUTH); new Wall(kw, 3, 1, Direction.SOUTH); new Wall(kw, 3, 1, Direction.WEST); new Wall(kw, 2, 1, Direction.WEST); new Wall(kw, 1, 1, Direction.WEST); // make robot Robot karel = new Robot(kw, 2, 2, Direction.SOUTH); // make karel reach the wall while (true) { if (karel.frontIsClear()) { karel.move(); } else if (karel.frontIsClear() == false) { break; } } // make karel escape the room while (true) { if (karel.frontIsClear()) { karel.move(); karel.turnLeft(); karel.turnLeft(); karel.turnLeft(); { if (karel.frontIsClear()) { break; } } } else if (karel.frontIsClear() == false) { karel.turnLeft(); } } // make karel move out of the room karel.move(); }
/** @param args the command line arguments */ public static void main(String[] args) { // make city for robot City a2q4 = new City(); // make robot Robot lali = new Robot(a2q4, 0, 1, Direction.EAST); // create all walls new Wall(a2q4, 1, 1, Direction.SOUTH); new Wall(a2q4, 1, 1, Direction.NORTH); new Wall(a2q4, 1, 1, Direction.EAST); new Wall(a2q4, 1, 1, Direction.WEST); new Wall(a2q4, 4, 1, Direction.SOUTH); new Wall(a2q4, 4, 1, Direction.NORTH); new Wall(a2q4, 4, 1, Direction.EAST); new Wall(a2q4, 4, 1, Direction.WEST); new Wall(a2q4, 1, 4, Direction.SOUTH); new Wall(a2q4, 1, 4, Direction.NORTH); new Wall(a2q4, 1, 4, Direction.EAST); new Wall(a2q4, 1, 4, Direction.WEST); new Wall(a2q4, 4, 4, Direction.WEST); new Wall(a2q4, 4, 4, Direction.EAST); new Wall(a2q4, 4, 4, Direction.NORTH); new Wall(a2q4, 4, 4, Direction.SOUTH); new Wall(a2q4, 2, 2, Direction.NORTH); new Wall(a2q4, 2, 3, Direction.NORTH); new Wall(a2q4, 2, 2, Direction.WEST); new Wall(a2q4, 3, 2, Direction.WEST); new Wall(a2q4, 3, 2, Direction.SOUTH); new Wall(a2q4, 3, 3, Direction.SOUTH); new Wall(a2q4, 2, 3, Direction.EAST); new Wall(a2q4, 3, 3, Direction.EAST); while (lali.frontIsClear()) { lali.move(); lali.turnLeft(); lali.turnLeft(); lali.turnLeft(); lali.move(); lali.turnLeft(); lali.move(); lali.turnLeft(); lali.move(); lali.turnLeft(); lali.turnLeft(); lali.turnLeft(); lali.move(); lali.move(); lali.turnLeft(); lali.turnLeft(); lali.turnLeft(); lali.move(); } }
/** @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here // skiped City jw = new City(); Robot rob = new Robot(jw, 1, 1, Direction.EAST); new Wall(jw, 1, 1, Direction.WEST); new Wall(jw, 1, 1, Direction.NORTH); new Wall(jw, 1, 2, Direction.NORTH); new Wall(jw, 1, 3, Direction.NORTH); new Wall(jw, 1, 4, Direction.NORTH); new Wall(jw, 1, 4, Direction.EAST); new Wall(jw, 2, 4, Direction.EAST); new Wall(jw, 3, 4, Direction.EAST); new Wall(jw, 3, 4, Direction.SOUTH); new Wall(jw, 3, 3, Direction.SOUTH); new Wall(jw, 3, 2, Direction.SOUTH); new Wall(jw, 3, 1, Direction.SOUTH); new Wall(jw, 3, 1, Direction.WEST); new Wall(jw, 2, 1, Direction.WEST); // walls for days new Thing(jw, 1, 2); new Thing(jw, 2, 2); new Thing(jw, 2, 3); new Thing(jw, 2, 4); new Thing(jw, 3, 4); new Thing(jw, 3, 1); // Things!!! rob.turnLeft(); while (rob.frontIsClear()) { rob.move(); if (rob.canPickThing()) { rob.pickThing(); } while (!rob.frontIsClear()) { rob.turnLeft(); } } }
/** @param args the command line arguments */ public static void main(String[] args) { // make things City town = new City(); Robot jarvis = new Robot(town, 2, 1, Direction.NORTH); new Wall(town, 1, 1, Direction.NORTH); new Wall(town, 1, 1, Direction.SOUTH); new Wall(town, 1, 1, Direction.EAST); new Wall(town, 1, 1, Direction.WEST); new Wall(town, 1, 4, Direction.NORTH); new Wall(town, 1, 4, Direction.SOUTH); new Wall(town, 1, 4, Direction.EAST); new Wall(town, 1, 4, Direction.WEST); new Wall(town, 4, 1, Direction.NORTH); new Wall(town, 4, 1, Direction.SOUTH); new Wall(town, 4, 1, Direction.EAST); new Wall(town, 4, 1, Direction.WEST); new Wall(town, 4, 4, Direction.NORTH); new Wall(town, 4, 4, Direction.SOUTH); new Wall(town, 4, 4, Direction.EAST); new Wall(town, 4, 4, Direction.WEST); new Wall(town, 2, 2, Direction.NORTH); new Wall(town, 2, 2, Direction.WEST); new Wall(town, 2, 3, Direction.NORTH); new Wall(town, 2, 3, Direction.EAST); new Wall(town, 3, 2, Direction.SOUTH); new Wall(town, 3, 2, Direction.WEST); new Wall(town, 3, 3, Direction.SOUTH); new Wall(town, 3, 3, Direction.EAST); // move while (!jarvis.frontIsClear()) { jarvis.turnLeft(); jarvis.move(); jarvis.turnLeft(); jarvis.turnLeft(); jarvis.turnLeft(); jarvis.move(); jarvis.move(); jarvis.turnLeft(); jarvis.turnLeft(); jarvis.turnLeft(); jarvis.move(); jarvis.move(); jarvis.turnLeft(); jarvis.turnLeft(); jarvis.turnLeft(); jarvis.move(); jarvis.turnLeft(); jarvis.move(); } }
/** @param args the command line arguments */ public static void main(String[] args) { // Can use Wall1.txt, Wall2.txt, or Wall3.txt City kw = new City("Wall1.txt"); Robot karel = new Robot(kw, 1, 1, Direction.WEST); // program solutions coded under here while (!karel.frontIsClear()) { karel.turnLeft(); karel.move(); karel.turnLeft(); karel.turnLeft(); karel.turnLeft(); } }
/** @param args the command line arguments */ public static void main(String[] args) { // make city City kw = new City(); // make robot Robot karel = new Robot(kw, 1, 1, Direction.EAST); // make walls new Wall(kw, 1, 1, Direction.NORTH); new Wall(kw, 1, 1, Direction.WEST); new Wall(kw, 1, 2, Direction.NORTH); new Wall(kw, 1, 3, Direction.NORTH); new Wall(kw, 1, 4, Direction.NORTH); new Wall(kw, 3, 1, Direction.SOUTH); new Wall(kw, 3, 2, Direction.SOUTH); new Wall(kw, 3, 3, Direction.SOUTH); new Wall(kw, 3, 4, Direction.SOUTH); new Wall(kw, 3, 1, Direction.WEST); new Wall(kw, 2, 1, Direction.WEST); new Wall(kw, 3, 4, Direction.EAST); new Wall(kw, 2, 4, Direction.EAST); new Wall(kw, 1, 4, Direction.EAST); // New things new Thing(kw, 3, 1); new Thing(kw, 1, 2); new Thing(kw, 2, 2); new Thing(kw, 2, 3); new Thing(kw, 3, 4); while (true) { if (karel.canPickThing()) { karel.pickThing(); } if (karel.frontIsClear()) { karel.move(); } else { if (karel.getDirection() == Direction.EAST) { karel.turnLeft(); karel.turnLeft(); karel.turnLeft(); } if (karel.getDirection() == Direction.SOUTH && (!karel.frontIsClear())) { karel.turnLeft(); karel.turnLeft(); } if (karel.getDirection() == Direction.SOUTH) { karel.move(); karel.turnLeft(); karel.turnLeft(); karel.turnLeft(); } if (karel.getDirection() == Direction.WEST && (!karel.frontIsClear())) { karel.turnLeft(); karel.move(); karel.turnLeft(); } if (karel.getDirection() == Direction.NORTH && (!karel.frontIsClear())) { karel.turnLeft(); } if (karel.getDirection() == Direction.WEST) { karel.move(); } } if (karel.getAvenue() == 1 && (karel.getStreet()) == 1) { karel.turnLeft(); karel.turnLeft(); break; } } }