From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id EAA20119; Tue, 29 Oct 2002 04:08:41 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id EAA19273 for ; Tue, 29 Oct 2002 04:08:39 +0100 (MET) Received: from postfix3-2.free.fr (postfix3-2.free.fr [213.228.0.169]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g9T38cD24642 for ; Tue, 29 Oct 2002 04:08:39 +0100 (MET) Received: from www.mydomain.com (strasbourg-4-a7-62-147-196-181.dial.proxad.net [62.147.196.181]) by postfix3-2.free.fr (Postfix) with SMTP id A989817E1A; Tue, 29 Oct 2002 04:08:37 +0100 (CET) Date: Tue, 29 Oct 2002 04:17:13 +0100 From: Nicolas FRANCOIS (AKA El Bofo) To: Caml List Cc: Ocaml beginners Subject: [Caml-list] I'm getting slightly mad Message-Id: <20021029041713.3cd91c24.nicolas.francois@free.fr> X-Mailer: Sylpheed version 0.8.3 (GTK+ 1.2.10; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk I have a problem with a maximax function (I want to maximize at each step, for this is a solitaire game ;-). let rec explorer_niveau i prof table score_max liste_meilleurs = function | [] -> (* pause ("fin de l'exploration du niveau " ^ (string_of_int i)); *) (score_max, liste_meilleurs) | t::q -> if i = prof then begin let v = valeur_coup table t in if v > score_max then explorer_niveau i prof table v [t] q else if v = score_max then explorer_niveau i prof table v (t::liste_meilleurs) q else explorer_niveau i prof table score_max liste_meilleurs q end else begin let table' = essaye_coup table t in let liste = liste_coups_jouables table' in let lo = List.length liste in (* pause ("La liste de meilleurs coups au niveau " ^ (string_of_int i) ^ " comporte " ^ (string_of_int lo) ^ " éléments"); *) if lo = 0 then explorer_niveau i prof table score_max liste_meilleurs q else let (s, _) = explorer_niveau (i + 1) prof table' (-1) [] liste in if s > score_max then explorer_niveau i prof table s [t] q else if s = score_max then explorer_niveau i prof table score_max (t::liste_meilleurs) q else explorer_niveau i prof table score_max liste_meilleurs q end Some details : tableau is a 31*31 array of {occupe : bool; etatdir array}, etatdir being a list of labels (AUCUN|MILIEU|DEBUT|FIN|DEBUT_FIN). I think the problem comes from the fact this is not a simple table. This is the copy function : let recopie_tableau tableau = let tableau' = Array.make_matrix 31 31 (case_vide ()) in for i = 0 to 30 do for j = 0 to 30 do tableau'.(i).(j).occupe <- tableau.(i).(j).occupe; for k = 0 to 3 do tableau'.(i).(j).etat.(k) <- tableau.(i).(j).etat.(k) done done done; tableau' My problem is : the exlorer_niveau function works fine called with prof = 0 (the deepness of exploration). But starting from prof = 1, I get an empty list of best moves, which is what I would have expected. Do you have any idea what could go wrong ? I know it's a problem with the tables not being correctly copied, or this function being buggy, but I can't solve either problem. Thanks for any help. If this sounds tricky, I can send you the complet package (about 5k !) for you to test. \bye -- Nicolas FRANCOIS http://nicolas.francois.free.fr We are the Micro$oft. Resistance is futile. You will be assimilated. ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners