Editorial for ECOO '12 R3 P1 - The Word Garden


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Trying to generate and draw the trees on the screen all at once will be quite difficult. A better idea is to create a two-dimensional array of characters (24 rows, 40 columns), "draw" the trees into this array, then draw the array to the screen. Once the array is created, you can fill it with spaces and draw the ground in the final row immediately. Then you need an algorithm (preferably in a method, function, or procedure) for drawing a tree with its trunk at a given location. Test that algorithm to make sure you can draw a single word tree anywhere you want. It's a good idea to put it in a method, procedure, or function.

The next part is figuring out where to draw each tree. The first one is not hard. If the word is 5 characters long, its trunk should be in the 5^\text{th} column of the array. But figuring out where to draw each of the next trees is harder. You could try to do some mathematical or logical reasoning to figure out where each one should go, but once you have the drawing algorithm done, you can copy it and modify it so that instead of actually drawing the tree, it checks all the array locations the tree would need for a "collision" with other trees. This second algorithm can be used to test possible locations for the next tree. If you know where the trunk of the last tree was, you can start at that location plus 1 and then keep moving to the right until your tree checking algorithm says it's ok. Then draw the tree there.


Comments

There are no comments at the moment.