User Tools

Site Tools


This is an old revision of the document!

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 Google classroom. If you want you can post it with or without the task that is the solution to your maze.

Make your plan and exchange it with another student. He has to make your maze, and you have to make his. Help one another. Start with 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 Maze implements Directions {
    	public static void task() {
    		Robot robby = new Robot(1, 2, East, 0);
    	// Main entry point
    	public static void main(String[] args) {
    		World.setSize(8, 9);
    		World.placeBeepers(1, 4, 1);
    		World.placeEWWall(3, 1, 3);
    		World.placeNSWall(1,6, 5);
    		World.placeEWWall(6, 1, 6);
  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";
  3. You can place a text file with string commands like this:
    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


    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)Maze.txt - replacing (YourFirstName) of course. for example, FrancisMaze.txt. You can send it to the class inbox in Google classroom. If you want you can post it with or without the task that is the solution to your maze. This would be the sorce code file. Name it

make_a_maze.1566514788.txt.gz · Last modified: 2019/08/22 18:59 by frchris