Commits

vfiack  committed 9d0d943

play in a loop

  • Participants
  • Parent commits 1dca277

Comments (0)

Files changed (3)

File maze/astar.ml

     loop ()
 end
 
+(*
 let () =
   let maze, goal, ants = Maze.Parser.from_file "maze/maze.txt" in
   let start = List.hd ants in
   Maze.draw maze;
   Printf.printf "%d steps\n" (List.length path);
   let time = (after -. before) *. 1000. in
-  Printf.printf "%f ms\n" time
+  Printf.printf "%f ms\n" time
+*)

File maze/generator.ml

   Maze.set maze goal 'X';  
   maze, start, goal
 
-let rec add_holes maze n = match n with
+let rec add_holes maze n = match+ n with
   | 0 -> maze
   | _ -> 
     let x = Random.int ((Maze.width maze) -1)
     add_holes maze (pred n)
     
 
-let generate width height = gen_backtracker width height
+let generate width height = 
+  let maze, start, goal = gen_backtracker width height in
+  (add_holes maze (width+height)), start, goal
   
-let pixel = 16
+exception Break
+
+let pixel = 32
 
 let load_maze maze name = 
   Graphics.set_window_title ("Maze solver - " ^ name);
   draw_dot maze current; 
   
   let key = Graphics.read_key() in
-  if key = ' ' then solve maze goal start
+  if key = 'k' then raise Break
+  else if key = ' ' then solve maze goal start
   else begin
     let next = match key with
       | '6' -> (fst current) +1, snd current
       else interact maze goal start next
     end       
   end
-         
-                   
+                           
 let _ =
   Random.self_init ();
-  let maze, start, goal = Generator.generate 20 10 in
   Graphics.open_graph "";
-  load_maze maze "auto";
-  interact maze goal start start
+  try
+    while true do
+	    let maze, start, goal = Generator.generate 15 11 in
+	    load_maze maze "auto";
+      interact maze goal start start
+    done
+  with Break -> ()