Solved

Decision trees in delphi ???

Posted on 2001-06-03
6
329 Views
Last Modified: 2010-08-05
Hi

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 !
0
Comment
Question by:joyrider
6 Comments
 
LVL 13

Expert Comment

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

Author Comment

by:joyrider
ID: 6151038
here is a small explaination of it but it couldn't help me any further :(
http://www.gamedev.net/reference/programming/features/trees1

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

Expert Comment

by:RickHalle
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;
end

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;
else
  statement;
end

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';
else
  Caption := '';
end;

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'
      else
        Caption := '';

Other examples of case statements:

case MyColor of

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

case Selection of

  Done: Form1.Close;
  Compute: CalculateTotal(UnitCost, Quantity);
else
  Beep;
end;
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 13

Expert Comment

by:Epsylon
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...
0
 

Author Comment

by:joyrider
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
else
2) check if computer can make 4 on row if so put piece there
else
3) check if computer can make 3 on row if so put piece there
else
4) check if computer can make 2 on row if so put piece there
else
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
0
 
LVL 22

Accepted Solution

by:
mnasman earned 200 total points
ID: 6151522
Hello

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

 http://www.public.asu.edu/~kirkwood/DAStuff/code/scode.htm
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now