Solved

Decision trees in delphi ???

Posted on 2001-06-03
6
387 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
[X]
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
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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:
Mohammed Nasman 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

751 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