Table of Contents

Make a Maze

Make a Maze with 4 to 6 walls and one beeper. Place the Robot in the start position, and the beeper in the end position.

You can post your .java file in GoogleClassroom.

Make your plan and exchange it with another student. He has to make a task to run your maze, and you have to make a task to run his. Help one another. Start with a simplified task that turns off right after the robot is made. After the maze is correct, you can finish the task by adding the move() and turnLeft() methods for the robot to run the maze.

Walls or obstacles are pared of the World class and can be placed in a NS or a EW direction, and have length. Here is a link to the API which shows all the constructors and methods that belong to the World class.

World.setSize(int numberOfStreets, int numberOfAvenues) will change the size of the World.

It is actually easier to see the available methods and their parameters in the API

3 Ways to Make Walls

  1. World.placeNSWall(), World.placeEWWall() have three parameters (sometimes called arguments). You need to tell these methods three integers, For a East-West Street: the number of the street, the number of the Avenue, and the length of the wall (either going East or North, depending on the direction. Once you get the hang of reading the API of a class you can quickly use or build upon other people's code (or even your own).
    import kareltherobot.*;
    public class MyMaze implements Directions {
        public static void task() {
            Robot robby = new Robot(1, 1, North, 0);
            // Place the code to run the maze here
            robby.turnOff();
     
        }
        // Main entry point
        public static void main(String[] args) {
            World.setDelay(150);
            World.setSize(8, 9);
            //Plce beeps at the begining and the end
            World.placeBeepers(6, 7, 1);
            World.placeBeepers(1, 1, 1);
            //Walls that make the maze
            World.placeEWWall(5, 1, 3);
            World.placeNSWall(1, 6, 5);
            World.placeNSWall(2, 3, 4);
            World.placeNSWall(2, 5, 5);
            World.placeNSWall(1, 4, 5);
            World.placeEWWall(2, 3, 1);
            World.placeNSWall(1, 1, 4);
            World.placeEWWall(6, 1, 6);
            World.setVisible();
            task();
        }
    }
  2. You can make a long string and send it all at once to the World. :
    public static void main(String[] args) {
    		String hurdles = "streets 8\n" + 
    				"avenues 9\n" + 
    				"eastwestwalls 3 1 3\n" + 
    				"northsouthwalls 1 6 5\n" + 
    				"eastwestwalls 6 1 6\n" + 
    				"beepers 1 4 1";
    		World.getWorld(hurdles);
    		World.setVisible();
            task();
    	}
  3. You can place a text file with string commands like this:
     KarelWorld
    streets 8
    avenues 9
    beepers 1 4 1
    eastwestwalls 3 1 3
    northsouthwalls 1 6 5
    eastwestwalls 6 1 6

    Give the text a file a name (like maze.txt) , and add it to your project and use the call

     World.readWorld("maze.txt"); 

    This way has extra steps, but once you make this text file, you can easily send your maze to someone else and have them figure out a way to navigate it. You can actually use the first method, and then use the method call World.saveWorld(“myMaze.txt”); to make this text file.

You can post world text file so others can run your maze with karel naming it (YourFirstName or Initials)Maze.txt - replacing (YourFirstName or initials) of course. for example, FrancisMaze.txt. You can upload it in SFHS Portals. This would be the sorce code file. Name it YourFirstNameMaze.java

Note: Make sure your Maze has a solution, no islands, and that all locations are reachable. If you are so creative, use an algorithm. There is a Wikipeadia article about it which I implemented

Make Maze Algorithm

Try making this one, that was made by the java application MakeMaze

Try Running these Student Made Mazes