Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type noeud = {
- mutable nord: bool;
- mutable est: bool;
- mutable sud: bool;
- mutable ouest: bool
- }
- and graphe_grille = {
- n: int;
- m: int;
- adj: noeud array array
- };;
- let creer_grille l1 l2 =
- let m = Array.make_matrix l1 l2 {nord=false;sud=false;ouest=false;est=false} in
- for x=0 to (l1-1) do
- for y=0 to (l2-1) do
- m.(x).(y)<-{nord=false;sud=false;ouest=false;est=false}
- done
- done;
- {n=l1;m=l2;adj=m};;
- (*
- let string_of_grille a =
- let t = a.adj in
- let md = " |" in
- let vd = " " in
- let mb = "---x" in
- let vb = " x" in
- print_string "x";
- for i = 0 to (a.m-1) do print_string mb done;
- for x = 0 to (a.n-1) do
- for y = 0 to (a.m-1) do
- *)
- let string_of_grille g =
- let res = ref "" in
- for i = 0 to (g.n - 1) do
- for j = 0 to (g.m - 1) do
- res := !res^"x";
- if g.adj.(i).(j).nord then
- res := !res^" "
- else
- res := !res^"---"
- done;
- res := !res^"x\n";
- for j = 0 to (g.m - 1) do
- if g.adj.(i).(j).ouest then
- res := !res^" "
- else
- res := !res^"|";
- res := !res^" "
- done;
- if g.adj.(i).(g.m - 1).est then
- res := !res^" \n"
- else
- res := !res^"|\n"
- done;
- for j = 0 to (g.m - 1) do
- res := !res^"x";
- if g.adj.(g.n-1).(j).sud then
- res := !res^" "
- else
- res := !res^"---"
- done;
- res := !res^"x\n";
- !res
- ;;
- print_string (string_of_grille (creer_grille 24 24));;
- let ouvrir g (i,j) (a,b) =
- let x=i-a in
- let y=j-b in
- if x=1 && y=0
- then ((g.adj.(i).(j)).nord<-true;(g.adj.(a).(b)).sud<-true)
- else if x=(-1) && y=0
- then ((g.adj.(i).(j)).sud<-true;(g.adj.(a).(b)).nord<-true)
- else if x=0 && y=1
- then ((g.adj.(i).(j)).ouest<-true;(g.adj.(a).(b)).est<-true)
- else if x=0 && y=(-1)
- then ((g.adj.(i).(j)).est<-true;(g.adj.(a).(b)).ouest<-true)
- else failwith "nop";;
- let test = creer_grille 3 3 in ouvrir test (0,0) (0,1);print_string (string_of_grille test);;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement