Sign in to follow this  

Caml Light - Blocks World

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 tree
let 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

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this