Advertisement

Caml Light - Blocks World

Started by May 16, 2005 09:19 AM
0 comments, last by gcs584 19 years, 6 months ago
Hi, I've been around with a lot of CAML light code and haven't figured out a way to create the Blocks World game... I've programmed this game before in Prolog, but now I'm trying to do it in Caml Light. The main problem is that in Prolog I used the "compiler built in tree" to run through all possible moves because I understand the way prolog files are read by the compiler. In Caml Light, how is the code file read? Is it read straightforward? Does it have e built-in tree I can use? Thanks for any help you can offer in programming this game in Caml Light. VisualFX
Hi,

Caml light has a built-in tree. You can build a tree as follows:

Binary Tree:
type 'a Tree = Lf of 'a | Nd of ('a * 'a Tree * 'a Tree );//Initialize a treelet tree = Nd(4, Nd(2, Nd( 6, Lf(7), Lf(8)), Lf(10) ), Lf(3) );;


To give you an example, you could traverse a tree in postorder and put all the elements in a list as follows:

let rec postorder = fun    (Lf x) -> [x] |    (Nd (a, b, c)) -> (postorder b)@(postorder c)@[a];;


I don't know much about your experience with Caml Light, but should you have any further questions, I would be glad to help!

Later,

GCS584

This topic is closed to new replies.

Advertisement