Recursive thinking

posted in KrisWolfe
Published May 07, 2019
Advertisement

Recursive programming is tough, but oh so rewarding. After 2 days of trying to figure out this thing is going to take shape, I've done it:

Recursive1.thumb.JPG.2ccc6fe6bf6f0d5c494f93466357bfb1.JPG

A hierarchy tree. It's quite dynamic too. It can have lopsided trees and uneven trees. But, what it can't have is managers without employees. It's assumed that if there's a manager, it has an employee.

How it works is that while I'm running through the employee roster to get all the idle employees to my idle panel, I count how many bottom nodes there are going to be. Using that, I enqueue up an offset counter, and each time I hit the bottom, I dequeue the list and multiply that by my width of the card. My recursive model races to the bottom first, and then once we've placed the subordinates, the manager just averages their x positions and places himself up. I keep track of how high we are in the tree as we step in and out of our recursive function, and multiply the height counter by the height of the cards.

This has been oh so satisfying to code. Now to figure out how to add and delete branches.

Recursive2.thumb.JPG.6624090872a1d6ba401b7d2f81e47f4f.JPG

1 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement