I want to draw some overlapping rectangles, for example:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,backgrounds}
\begin{document}

\begin{tikzpicture}
\draw [fill=blue,ultra thick] (0.4,0.5) rectangle (0,1);
\draw [fill=red,ultra thick] (0,0.3) rectangle (1,1);
\draw [fill=green,ultra thick] (0,0) rectangle (0.5,0.5);
\end{tikzpicture}

\end{document}


But I want (in this example) the green rectangle under the red and the red under the blue. Is that possible (without changing the order of commands)?

More explanation: the latex commands are generated by a C++ program which computes coordinates of some rectangles. I want to draw them and they can overlap. The program computes the rectangles in some order and I want to show them in the reverse order. (It seems difficult to me to write the lines of C++ output to a file in reverse order.) 

Here is what I have and what I want:




Question: How do I create a great fantasy villain that inspires the party to rally against them?
Answer: The most memorable villians in my experience are the ones that defeat the PCs especially if it happens more than once. Nothing drives the passions of the players more than a familiar villian who has managed to outwit them. I was once had an entire campaign revolve around defeating a single recurring villian. The key was to allow the players to frequently win. Each time creating set backs for the villian and his minions but not fatally.