User Tools

Site Tools


make_a_maze

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
make_a_maze [2020/08/18 18:59] frchrismake_a_maze [2021/09/05 13:16] (current) – [Make Maze Algorithm] frchris
Line 14: Line 14:
 ====== 3 Ways to Make Walls ====== ====== 3 Ways to Make Walls ======
   - 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 [[http://csis.pace.edu/%7Ebergin/KarelJava2ed/KJRdocs/kareltherobot/World.html|API]] of a class you can quickly use or build upon other people's code (or even your own). <code java>import kareltherobot.*;   - 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 [[http://csis.pace.edu/%7Ebergin/KarelJava2ed/KJRdocs/kareltherobot/World.html|API]] of a class you can quickly use or build upon other people's code (or even your own). <code java>import kareltherobot.*;
-public class Maze implements Directions { +public class MyMaze implements Directions { 
- public static void task() { +    public static void task() { 
- Robot robby = new Robot(1, 2East, 0); +        Robot robby = new Robot(1, 1North, 0); 
- robby.move();     +        // Place the code to run the maze here 
- robby.move();    +        robby.turnOff();
- robby.pickBeeper();                     +
- robby.move();    +
- robby.turnLeft();    +
- robby.move(); +
- robby.move();    +
- robby.putBeeper();   +
- robby.move(); +
- robby.turnOff();+
  
- +    
- // Main entry point +    // Main entry point 
- public static void main(String[] args) { +    public static void main(String[] args) { 
- World.setDelay(150); +        World.setDelay(150); 
- World.setSize(8, 9); +        World.setSize(8, 9); 
- World.placeBeepers(1, 4, 1); +        //Plce beeps at the begining and the end 
- World.placeEWWall(3, 1, 3); +        World.placeBeepers(6, 7, 1); 
- World.placeNSWall(1,6, 5); +        World.placeBeepers(1, 1, 1); 
- World.placeEWWall(6, 1, 6); +        //Walls that make the maze 
- World.setVisible(); +        World.placeEWWall(5, 1, 3); 
- task(); +        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(); 
 +    }
 }</code> }</code>
   - You can make a long string and send it all at once to the World.  :<code java>public static void main(String[] args) {   - You can make a long string and send it all at once to the World.  :<code java>public static void main(String[] args) {
Line 60: Line 60:
 eastwestwalls 6 1 6</code>Give the text a file a name (like ''maze.txt'') , and add it to your project and use the call <code java> World.readWorld("maze.txt"); </code>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.   eastwestwalls 6 1 6</code>Give the text a file a name (like ''maze.txt'') , and add it to your project and use the call <code java> World.readWorld("maze.txt"); </code>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 [[https://drive.google.com/open?id=10dAqaHXdDkvM9kT7neze5SXVaUXAaqQe|Google classroom]].  If you want you can post it with or without the task that is the solution to your mazeThis would be the sorce code file Name it YourFirstNameMaze.java+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 [[https://en.wikipedia.org/wiki/Maze_generation_algorithm|Wikipeadia article]] about it which I implemented   
 + 
 +===== Make Maze Algorithm ===== 
 +Try making this one, that was made by the java application [[https://mathorama.com/apcs/pmwiki.php?n=Main.MakeMaze|MakeMaze]] 
 +{{::sample.png?400|}}
  
 [[Try Running these Student Made Mazes]] [[Try Running these Student Made Mazes]]
make_a_maze.1597791578.txt.gz · Last modified: 2020/08/18 18:59 by frchris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki