Solved

Decision trees in delphi ???

Posted on 2001-06-03
6
357 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

806 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