Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] I'm getting slightly mad
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nicolas FRANCOIS <nicolas.francois@f...>
Subject: [Caml-list] I'm getting slightly mad
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