Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Nicolas FRANCOIS (AKA El Bofo) <nicolas.francois@free.fr>
To: Caml List <caml-list@inria.fr>
Cc: Ocaml beginners <ocaml_beginners@yahoogroups.com>
Subject: [Caml-list] I'm getting slightly mad
Date: Tue, 29 Oct 2002 04:17:13 +0100	[thread overview]
Message-ID: <20021029041713.3cd91c24.nicolas.francois@free.fr> (raw)

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


             reply	other threads:[~2002-10-29  3:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-29  3:17 Nicolas FRANCOIS [this message]
2002-10-29 17:17 ` Nicolas FRANCOIS

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20021029041713.3cd91c24.nicolas.francois@free.fr \
    --to=nicolas.francois@free.fr \
    --cc=caml-list@inria.fr \
    --cc=ocaml_beginners@yahoogroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox