Thursday, August 02, 2007

My attempt at trees

I already have two proposals, and I want to get some feedback, but I think I simplified trees enough to make it workable and not too complex.

The Monkey Tree is an endless tree made of Nodes. Each Node has one parent node and two children node and is referred to by its row and rank in the form row.rank. For nodes with row I, only nodes with rank 2 ^ (I – 1) exist. (So the node 2.5 does not exist).

The parent of node I.J is node I-1.J./2 (when odd, J/2 is rounded up).

The children of node I.J are the nodes I+1,2J and I+1,2J-1. (So the parent of the node 3.4 is 2.2, and the children of the node 3.4 are 4.7 and 4.8).

The node 1.1 is called the root node and does not have a parent node.

When a monkey joins the monkey tree they are added to first empty row with the lowest row, lowest rank is used to break ties. (3.3 is picked before 4.2 as 3 is less than four. 4.2 is picked before 4.4 because 4 equals 4 and 2 is less than four).

The monkey tree is unbalanced if a monkey is in a node and there is no monkey in that node’s parent. (provided that the node is not 1.1 of course), or if there is more than one monkey in the same node.

If a monkey is in a node and there is no monkey in that node’s parent, then the monkey simply moves to the parent node.

If there are two monkeys in the same node then the monkey’s whose name appears later alphabetically moves to the lower of the two children of that node. The exception to this rule is if the lower of the two children already contains a monkey and the greater of the two children does not, in this case the lower alphabetically monkey moves to the greater of the two children. (So if Monkey A and B are in node 4.5 and monkey C is in node 5.9, then monkey B would move to node 5.10. If monkey D is already in node 5.10, then monkey B would move to node 5.9 even if 5.10 has no children and 5.9 has both).

When displaying the monkey tree, only nodes containing monkeys should be displayed.

Comments

Icarus:

02-08-2007 15:29:58 UTC

for We’re going to have some very confused monkeys, but I like it.

Icarus:

02-08-2007 15:30:35 UTC

Blast, I was too voting-happy again!

Kevan: he/him

02-08-2007 15:38:22 UTC

So is this instead of the Line? Could we maybe just draw it semi-graphically in the wiki (with whatever weird asymmetrical shape we like), rather than having to worry about notation?

Clucky: he/him

02-08-2007 15:45:55 UTC

This is in addition to the line, and the barrel. Provide three different structures for the monkeys to dwell in.

Notation is needed for doing the dance, so that I can say “Give the monkey that is in Node 7.3 three bananas”. It is also useful for making sure the tree behaves properly. We do not want a node with three children, two nodes with NULL parents, a loop, or anything else yucky that could occur if we are not careful with notation.

Oracular rufio:

02-08-2007 15:48:39 UTC

Trying to describe a tree structure in terms of rows and columns seems very unintuitive to me.  Maybe I’m just too recursion-happy, though.

Clucky: he/him

02-08-2007 16:05:26 UTC

Would ‘depth’ work better than row for you? Row is how deep into the tree you are. Rank its where in that row you are. By their very definition, they are based on recursion.

Oracular rufio:

02-08-2007 16:40:33 UTC

Oh, I don’t have any problems with denoting rows.  It just seems a bit confusing to talk about what you call “rank” by counting from the left edge the way you would with a Cartesian plane.

It also seems more natural to name Nodes after their relationships to other Nodes, rather than their absolute position in space.

Clucky: he/him

02-08-2007 17:02:14 UTC

If you can provide another way that uniquely names nodes, I’d love to here it =)

Kevan: he/him

02-08-2007 17:22:40 UTC

Labelling them A-Z on a graphical map would be fine, particularly as (if I’m reading this right) it doesn’t need many more nodes than Monkeys.

Clucky: he/him

02-08-2007 17:32:21 UTC

I guess that would work, although to keep the tree binary it would have to be A-AE (or EE). I am thinking that with NPCs, 30 monkeys is good to have and not all of them will be in the tree, so we don’t have to go much beyond that.

Oracular rufio:

02-08-2007 19:53:21 UTC

Personally, I was thinking we could do something like, have the Root be “O”, and then append “L"s and “R"s to successive Nodes to show to reach them from the root.  E.g. OR is the right child of the root, OL is the left child, ORRLLR is the right child of the left child of the left child of the right child of the right child of the root, etc.