Decision trees in delphi ???

Posted on 2001-06-03
Last Modified: 2010-08-05

i've been working on some program and i have to check a lot of things in it so it will result in a huge , really huge list of nested if's.
Now i have read things about decision trees and i think this is a solution for me BUT i have no idea how to implement int in delphi ! i know it is a linked list and i also now you have to use recursion to do it so if someone could point me to a site where they explain it using examples and code for delphi or can explain it to me with some code i will be really happy !
Question by:joyrider
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 13

Expert Comment

ID: 6150930
I've never heard of a decision tree in Delphi. Only decisioncubes, -grids and -graphs, but that is something completely different.

Author Comment

ID: 6151038
here is a small explaination of it but it couldn't help me any further :(

i need a concreet example in delphi so i can use it, cause i'm not going to nest 20 or more if's

Expert Comment

ID: 6151078
I think he may be refering to case statements which are usually faster anyway.

This is directly from the Delphi5 online help documentation.

The case statement provides a readable alternative to complex nested if conditionals. A case statement has the form

case selectorExpression of

  caseList1: statement1;
  caseListn: statementn;

where selectorExpression is any expression of an ordinal type (string types are invalid) and each caseList is one of the following:

A numeral, declared constant, or other expression that the compiler can evaluate without executing your program. It must be of an ordinal type compatible with selectorExpression. Thus 7, True, 4 + 5 * 3, 'A', and Integer('A') can all be used as caseLists, but variables and most function calls cannot. (A few built-in functions like Hi and Lo can occur in a caseList. See Constant expressions.)
     A subrange having the form First..Last, where First and Last both satisfy the criterion above and First is less than or equal to Last.

A list having the form item1, ..., itemn, where each item satisfies one of the criteria above.

Each value represented by a caseList must be unique in the case statement; subranges and lists cannot overlap. A case statement can have a final else clause:

case selectorExpression of

  caseList1: statement1;
  caseListn: statementn;

When a case statement is executed, at most one of its constituent statements is executed. Whichever caseList has a value equal to that of selectorExpression determines the statement to be used. If none of the caseLists has the same value as selectorExpression, then the statement in the else clause (if there is one) is executed.
The case statement

case I of

  1..5: Caption := 'Low';
  6..9: Caption := 'High';
  0, 10..99: Caption := 'Out of range';
  Caption := '';

is equivalent to the nested conditional

if I in [1..5] then

  Caption := 'Low'
  else if I in [6..10] then
    Caption := 'High'
    else if (I = 0) or (I in [10..99]) then
      Caption := 'Out of range'
        Caption := '';

Other examples of case statements:

case MyColor of

  Red: X := 1;
  Green: X := 2;
  Blue: X := 3;
  Yellow, Orange, Black: X := 0;

case Selection of

  Done: Form1.Close;
  Compute: CalculateTotal(UnitCost, Quantity);

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

LVL 13

Expert Comment

ID: 6151116
Now I understand what you mean. The problem is that the implementation highly depends on what you want to do. You even may not have to use recursion.

Sorry, I can't give an example without more information...

Author Comment

ID: 6151140
RickHalle, tnx for the big info about cases but i knew what it was :)
but they actually do use trees.

Epsylon, i was trying to implement it to a simple game i was making to learn how these trees worked and should be implemented so i could use it in later projects.

i want to make a tree for the pc player mainly where he had to put his piece on the board.

i was thinking on something like this (i don't know if it is a good way cause i never tested it):
1) check if other play can do a 4 on a row if so put piece there
2) check if computer can make 4 on row if so put piece there
3) check if computer can make 3 on row if so put piece there
4) check if computer can make 2 on row if so put piece there
choose random place where to put piece

i know this is prefectly possible just using if's but i wanted to give these "decision trees" as shot
LVL 22

Accepted Solution

Mohammed Nasman earned 200 total points
ID: 6151522

  This page contain some programs to Solve Decision Trees
but the code in pascal and c

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month8 days, 22 hours left to enroll

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question