Tag Archives: Project

PATRIOT : Missile and The Enemy Launcher

I like to program by step, and steps i can verify their results quick and easily. 

I tend to do this more often when I’m not sure this is the way to go, and this is a good example.

I haven’t posted yet, but I will, a small introduction to this project/problem.

This is for a class of Real-Time Systems. i have to build a simulator an anti-missile system. It has to work on threads, communicate by queue, and it should have some real-time properties.

I am doing this in Ocaml because its the language I must learn for my final thesis, therefore its a win win situation I guess.


My solution is simple, and real straight forward to implement in a language like C. But in Ocaml there is so much choices and approaches, that I am not still sure was the best way to go.

The solution consist of 3 main Task: The enemy, The World and The PATRIOT system, more detail in my next post.


In this first approach I will start by defining my Missile and create a first version of the enemy missile launcher, and also name it! Maybe to Gundam! Or V.A.D.E.R, we will see.


Slow Steps

I told you I like slow steps.


So my first try will be to make a small module with a method printMissile that simply prints out: “I am Missile nº X”.


let print_Missile id =
Printf.printf “I am Missile %d\n” id;;


Now, this is done, easy right? Ok, so, let me try putting this on an endless loop and stop when I insert ‘x’.

This was also possible using recursion, but here I preferred to use imperative programming, using references, it is more intuitive for an infinite loop with this purpose.


let i = ref 1 in
while !i != 0 do
print_Missile !i;
i := read_int () ;
done ;;


I wanted to try and launch a process that would keep updating the value of the string printMissile but seems I can’t compile a program when calling the Unix module.

I will stop this for now, and come back to finish it later.


I asked in StackOverflow for some help, because help on this topic seems inexistent. 
I will go back trying to solve the Tree exercises. 


(Published 3/12/12)


Problem solved. Seems I had an incomplete installation of Ocaml. Unix module is now working, tested it with .Date function and .Time

Paused this function while I couldn’t solve it and started working on the Graphics interface.

So I will return to this point as soon as possible.


(Published 9/12/12)


After studying a bit more of Unix and Threads I was able to develop a small program that would launch a missile.

In this example, missile are threads, therefore we can launch as many missiles as we want.

Here is the code:


And here is the class module:



More info on both of these specific subjects can be found in these posts:




Tagged , , , , ,