(* TP07 - Ricochet Robots - partie 2 *) let obs_l = [| [|0; 4; 10; 16|]; [|0; 14; 16|]; [|0; 6; 16|]; [|0; 9; 16|]; [|0; 3; 15; 16|]; [|0; 7; 16|]; [|0; 1; 12; 16|]; [|0; 7; 9; 16|]; [|0; 7; 9; 16|]; [|0; 4; 13; 16|]; [|0; 6; 16|]; [|0; 10; 16|]; [|0; 8; 16|]; [|0; 2; 15; 16|]; [|0; 4; 10; 16|]; [|0; 5; 12; 16|] |];; let obs_c = [| [|0; 5; 11; 16|]; [|0; 6; 13; 16|]; [|0; 4; 16|]; [|0; 15; 16|]; [|0; 10; 16|]; [|0; 3; 16|]; [|0; 10; 16|]; [|0; 6; 7; 9; 12; 16|]; [|0; 7; 9; 16|]; [|0; 3; 12; 16|]; [|0; 14; 16|]; [|0; 16|]; [|0; 7; 16|]; [|0; 2; 10; 16|]; [|0; 4; 13; 16|]; [|0; 2; 12; 16|] |];; (* Q1 *) let dichotomie a t = let i = ref 0 in (* inclus *) let j = ref (Array.length t) in (* exclu *) (* A COMPLETER *) failwith "A IMPLEMENTER";; (* Tests dichotomie *) Printf.printf "Test dichotomie : %d\n " (dichotomie 3 [|0;1;5;15;21;30|]);; assert (dichotomie 3 [|0;1;5;15;21;30|] = 1);; assert (dichotomie 5 [|0;1;5;15;21;30|] = 2);; assert (dichotomie 29 [|0;1;5;15;21;30|] = 4);; (* Q2 *) let deplacements_grille (a,b) = failwith "A IMPLEMENTER";; (* affichage d'un tableau de positions *) let affichePos tab = Array.iter (fun (a,b)->Printf.printf "(%d,%d)" a b) tab; print_newline ();; Printf.printf "Test deplacement solo \n";; affichePos (deplacements_grille (0,0));; assert (deplacements_grille (0,0) = [|(0,0);(0,3);(0,0);(4,0)|]);; assert (deplacements_grille (2,7) = [|(2,6);(2,15);(0,7);(5,7)|]);; assert (deplacements_grille (9,7) = [|(9,4);(9,12);(9,7);(11,7)|]);; (* Q4 *) let matrice_deplacements () = failwith "A IMPLEMENTER";; (* Q6 *) let mat_depl = matrice_deplacements ();; let modif t (a,b) (c,d) = failwith "A IMPLEMENTER";; ;; Printf.printf "Test deplacement vs. 1 robot :\n";; let t0 = deplacements_grille (2,7) in modif t0 (2,7) (2,12); affichePos t0; assert (t0 = [|(2,6);(2,11);(0,7);(5,7)|]);; (* Q8 *) let deplacements_robots (a,b) q = failwith "A IMPLEMENTER";; Printf.printf "Test deplacement vs. plusieurs robots :\n";; let t1 = deplacements_robots (2,7) [(2,6); (4,7); (2,15); (2,10)] in affichePos t1; assert (t1 = [|(2,7);(2,9);(0,7);(3,7)|]);; (* Q10 *) (* affichage d'un tableau de positions *) let direction_of_int x = match x with | 0 -> "ouest" | 1 -> "est" | 2 -> "nord" | 3 -> "sud" | _ -> failwith "direction invalide" let afficheSol lst = List.iter (fun (a,b)->Printf.printf "robot %d vers %s\n" a (direction_of_int b)) lst;; let rec resol_backtracking deplacements robots p = failwith "A IMPLEMENTER";; Printf.printf "configuration facile:\n"; resol_backtracking [] [|(5,12);(4,0);(3,1);(0,7)|] 6;; Printf.printf "configuration initiale:\n"; resol_backtracking [] [|(5,12);(0,0);(2,1);(4,7);|] 8;;