* [Caml-list] I'm getting slightly mad
@ 2002-10-29 3:17 Nicolas FRANCOIS
2002-10-29 17:17 ` Nicolas FRANCOIS
0 siblings, 1 reply; 2+ messages in thread
From: Nicolas FRANCOIS @ 2002-10-29 3:17 UTC (permalink / raw)
To: Caml List; +Cc: Ocaml beginners
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] I'm getting slightly mad
2002-10-29 3:17 [Caml-list] I'm getting slightly mad Nicolas FRANCOIS
@ 2002-10-29 17:17 ` Nicolas FRANCOIS
0 siblings, 0 replies; 2+ messages in thread
From: Nicolas FRANCOIS @ 2002-10-29 17:17 UTC (permalink / raw)
To: Caml List
Le Tue, 29 Oct 2002 04:17:13 +0100 Nicolas FRANCOIS (AKA El Bofo)
<nicolas.francois@free.fr> a écrit :
> 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'
Thanks to Michel Quercia, my problem is solved, by adding a line to this
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) <- case_vide (); (* This is the new line,
essential ! *)
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'
\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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-10-29 17:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-29 3:17 [Caml-list] I'm getting slightly mad Nicolas FRANCOIS
2002-10-29 17:17 ` Nicolas FRANCOIS
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox