Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1448

Random-Depth Tree Creator/Editor (Finished and MUCH better!)

$
0
0
This code is Significantly revised - cleaner, better, much faster, many more features than the previous upload a couple weeks ago. I think it deserves it's own thread. Let me know if I'm wrong about that please.

------------------------------------------------------

******** Tree Generator v1.02.zip ********

------------------------------------------------------


=================================================================
There are no Revision Notes prior to v1.02. (A copy of these Notes and a ReadMe is included in the .zip)
=================================================================

Extensive Revision Notes to follow...

If you download this, I again strongly encourage you to play around with the application *before* you Generate any new Trees.

The provided Database includes a Tree with some Data filled in. If you create a New Tree then all Data in the Existing Tree will be Empty (unless you select the option to fill Random Sample Points). But there won't be any Text with the Nodes in the Tree Editor.

A copy of the Database is included in the Backup Folder in case you wipe out the provided Tree and want to see it with data.

This is now a finished product pending any fixes that may be necessary. The code has been tested extensively.

Any new features added will be part of a future version. That includes *probably, but not promising...* changing the Storage from an Access Db to a Binary File.


===========================================================
v1.02 Revision Notes:
===========================================================


* Multiple optimizations were made that increase efficiency and code-speed dramatically.

* The Tree Creator/Editor is now dependent on the Database. (See Game Notes below).

* The Text File being generated has been rem'd out but is still integrated. Check the cmdCreateTree_Click Event in frmTree for instructions to re-enable saving to a Text File. The Text File has not been updated to include new Node Data being saved in the Database.

* The Number of Roots specified in the Tree Generator Window is now the number being generated. Previously it Generated a Random Number of Roots in the range of 1 to the Number Specified.

* The Probability of each Node being Rolled is Calculated when it is Created. The Value is Stored with each Node in the Database.

* Added an Option to include Random Sample Data to Nodes when they're being Created. The percent of Nodes having Sample Data can Range from 1 to 99% (0% if the Option is not Selected).

* Fixed an issue of the entire Contents of the Textbox being refilled every time a new Node was Created during Tree Generation. It now adds the new Node String to the end of the existing text in the Textbox.

* Textbox Updates can be turned off when Generating a new Tree. This *dramatically* decreases the time required to create a Tree.

* Several fields on frmTree are now filled from the database when the application starts *if* a tree has already been generated and saved.

*A Combobox on frmTree lists all Branches that are the Maximum Length generated for the Current Tree.

* Added a simple Search feature to the Tree Editor Window.

* Added a Probability Textbox to the Tree Editor Window that displays the Probability of the Selected Node being Rolled. This is a Raw Number, not a Percent (move the Decimal right two places per usual to get the Percent).

* Added cNumericTextbox.cls Class to project. An Instance is Created for all Textboxes that are Numeric-only. Go to the CreateObjects Procedure in frmTree to see how the Class is Implemented.

* Optimized the Create Procedure in cNode.cls. Several Conditional Statements were being checked every time a new Node was created even though the Conditions being checked for were only true for the First Node created. The Public Create Procedure now checks those items and calls an internal procedure to continue the Recursion with no further checks.

* Removed colChildNodes from cNode.cls because it was not being used. It can be reimplemented in the future if needed.

* Added a Recordset Property to cNode.cls to eliminate the need to pass the Recordset between Procedures.

* Updated several other Procedures to Pass and Receive fewer Variables.

* Added an Expected Value Window that displays the Expected Value of Points added, Subtracted (and Attribute Multipliers) to or from an Attribute. The Window Updates when a New Tree is Generated or a Node is Edited and Saved.

* Various Procedures were sub-divided to make their tasks more specific.

* Fixed a Bug that prevented Trees from being as Random as intended. Branch numbers from Roots were being Randomly Generated outside the Loop which made every Branch under a Root identical. Branches from different Roots could be different but the Branches under a Root were all the same.

* Fixed a Bug in the Tree Editor that updated the Associated Attribute and Points from the wrong Combobox.

* Fixed a Bug in cNumericTextbox.cls that would not allow the user to input anything into a Textbox that contained a Minus Sign when a Minus Sign is included in the Seltext. (Notes about cNumericTextbox.cls are at the end).

* Updated cNumericTextbox.cls to allow a Comma or Decimal point (if the NumberType set allows non-whole numbers). Then fixed a Bug that would allow one Comma and one Decimal in the same Texbox.

* Removed various Dead Code.

* Fixed a Variable that was being Set and then Changed without the Intermediate Value being used.

===========================================================

Application Notes:

I adjusted my attitude about this application. At first I wanted something quick and dirty so I could get on to developing the Game Engine. I think I said 'It doesn't have to be perfect. It just needs to work.'

But I realized quickly that this application will be foundational to the Game so I began taking it a lot more seriously.

The Node System is simple to read and easy to figure out how it works. If you need a Deeper Branch at some point you can manually add to a Branch in the Database. You will have to calculate the Probability yourself.

If you type in Large Numbers of Roots and Target Depth it can take hours. I tried 999 for Roots and 99 for Target Depth (Max Numbers allowed). Hours later it was nowhere close to being finished AND it overflowed the database (over 2 gb).

So don't do things like that. If you want 999 Roots then do something like 4 Target Depth.

Or find a super-computer and a storage solution that can handle data that large. Maybe go on a cruise while you wait for it to finish.

My approach is to decide the Number of Nodes I want in advance and then play with the numbers to get approximately that number while striking a good balance between number of Roots (more Variety for Players) and Target Depth (more Choices for Players).

===========================================================

Game Notes:

The Database is not intended to be a part of the real final product (this application and any Games that utilized it). Instead a Binary Access file containing game data will be created. This is very low priority because it will also require building an engine to handle the data.

I'm not sure that I'm doing the Math properly when calculating Expected Values.

The intent of Expected Values is to ensure the game is balanced properly.

Values closer to zero will skew the game less. Values less than zero skew the game against the player. Positive values skew the game for the player.

===========================================================

cNumericTextbox.cls is intended to be much simpler than Controls like the MaskedEditBox which is a pain to use in practice.

It has many fewer features that aren't normally needed. If you need more then this class isn't for you.

It specifies three Numeric types: Integer (which means 'Whole Numbers' in this case, not Integer data type. It's actually a Long), Decimal and Currency (internally saved as Doubles).

Other than standard Textbox properties, the Class has these:

---------

*NumberType (one of the three types mentioned above).

*Min Value ' By default this precludes needing to have an Allow Negative Property).

*Max Value

*Format

*Decimal Places ' By default this precludes needing to have an Allow Decimal Property).

---------

And that's about it. It's super-easy to use. See the cmdCreateTree_Click Event in frmTree to see how to use it.

There is nothing more you need to do with cNumericTextbox.cls after it is Initialized. You always reference the Class Object you created and never directly reference the actual textbox.

All other properties (Font, Height, Width, etc.) are set via the Class. If a Property you want to use is missing from the Class it's simple to add as you're just Passing the Value to the Internal Reference to the Textbox.
Attached Files

Viewing all articles
Browse latest Browse all 1448

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>