@@ -16,8 +16,10 @@ let update_current_pos p = (fun c -> match c , !p with
16
16
| 'L' , (a ,b ) -> p := (a,b-1 ); p
17
17
)
18
18
19
- let positions_visited_so_far = ref [(0 ,0 )];;
19
+ let pos_visited = ref [(0 ,0 )];;
20
20
21
+ let update_pos_visited p = (fun cp -> (p := (cp :: ! p)); p);;
22
+
21
23
let letters_caught = ref []
22
24
23
25
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;;
129
131
print_char (make_naive_move line);;
130
132
*)
131
133
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
133
135
| 0 -> " End of Game"
134
136
| _ -> let move = (make_naive_move current_view) in
135
137
Printf. printf " %s\n %!" current_view;
136
138
Printf. printf " %c\n %!" move;
137
139
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
139
142
140
143
(* 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
141
144
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 )
143
146
144
147
(* to do
145
148
1. implement general solution algorithm
146
149
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