• 15
• 15
• 11
• 9
• 10

Caml Light - Blocks World

This topic is 4692 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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

Share on other sites
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