(* ===================================================== *)
(* Apprentissage de la programmation avec OCaml *)
(* Catherine Dubois & Valérie Ménissier-Morain *)
(* Éditions Hermès Sciences *)
(* Mars 2004 *)
(* ===================================================== *)
(* Fichier MLSRC/CC/CC_base_modulaire/representation.ml *)
(* ===================================================== *)
type case = Vide | Occupée of int;;
let lignes = 4 and colonnes = 6;;
let nb_couleurs = 16;;
let bord_gauche = 1
and bord_droit = 1
and bord_bas = 1
and bord_haut = 1;;
let débutc = bord_gauche
and finc = bord_gauche+colonnes-1;;
let débutl = bord_bas
and finl = bord_bas+lignes-1;;
let nb_colonnes = bord_gauche+colonnes+bord_droit;;
let nb_lignes = bord_bas+lignes+bord_haut;;
let zone_de_jeu =
Array.make_matrix nb_colonnes nb_lignes Vide;;
let création_tableau_ordonné () =
for j = débutl to finl do
let i = ref débutc in
while !i <= finc do
zone_de_jeu.(!i).(j) <-
Occupée (Random.int nb_couleurs);
zone_de_jeu.(!i+1).(j) <- zone_de_jeu.(!i).(j);
i := !i+2;
done;
done;;
let mélange_couleurs_tableau () =
for i = débutc to finc do
for j = débutl to finl do
let c = i+Random.int (finc-i+1)
and l = j+Random.int (finl-j+1) in
let tmp = zone_de_jeu.(c).(l) in
zone_de_jeu.(c).(l) <- zone_de_jeu.(i).(j);
zone_de_jeu.(i).(j) <- tmp
done;
done;;
let création_zone_de_jeu () =
création_tableau_ordonné ();
mélange_couleurs_tableau ();;
Ce document a été traduit de LATEX par
HEVEA.