Skip to content

Commit f43777d

Browse files
committed
added reset values
1 parent 79522c8 commit f43777d

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

maze_fun.ml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ let update_current_pos p = (fun c -> match c , !p with
1616
| 'L' , (a,b) -> p := (a,b-1); p
1717
)
1818

19-
let positions_visited_so_far = ref [(0,0)];;
19+
let pos_visited = ref [(0,0)];;
2020

21+
let update_pos_visited p = (fun cp -> (p := (cp :: !p)); p);;
22+
2123
let letters_caught = ref []
2224

2325
let remove_first_letter = (fun s -> String.sub s 1 ((String.length s) - 1))
@@ -129,20 +131,24 @@ let current_view = list_of_chars_to_string !current_3_by_4_view_letters;;
129131
print_char (make_naive_move line);;
130132
*)
131133

132-
let rec lets_play n current_view current_pos = match n with
134+
let rec lets_play n current_view current_pos pos_visited = match n with
133135
| 0 -> "End of Game"
134136
| _ -> let move = (make_naive_move current_view) in
135137
Printf.printf "%s\n%!" current_view;
136138
Printf.printf "%c\n%!" move;
137139
let cp = (update_current_pos current_pos move) in
138-
lets_play (n-1) (update_view move) cp
140+
let pv = (update_pos_visited pos_visited !cp) in
141+
lets_play (n-1) (update_view move) cp pv
139142

140143
(* start_game allows us to play n turns on the simplest 3x4 maze, one move is all that is needed to win although our robot is
141144
unaware of this right now.. *)
142-
let start_game = (fun n -> lets_play n starting_view current_pos)
145+
let start_game = (fun n -> lets_play n starting_view current_pos pos_visited)
143146

144147
(* to do
145148
1. implement general solution algorithm
146149
2. create function to sort and return character trophies
147-
*)
148-
150+
*)
151+
(* to reset *)
152+
(current_pos := (0,0); pos_visited := [(0,0)];
153+
current_3_by_4_view_positions := [6;2;10;5;7];
154+
current_3_by_4_view_letters := ['A';'#';'#';'#';'B'])

0 commit comments

Comments
 (0)