e.g.) Course advisor DT:
Computer
asks you questions in order to
advise you on what courses to take:
e.g.) suppose choice between
CSE 101, 111, 113, 115
Your question to computer:
"Should I take 101, 111, 113, or 115?"
Computer's questions to you,
and your
answers, and computer's
further questions,
and your further answers,
etc., make up
the DT.
-- Click
here for image of tree in "postscript".
-- Click
here for image of tree in "PDF".
* DTs are called "trees", since they sort of look
like trees if you look at them upside down.
-- The
first box (at the top) is called the "root".
-- Each
"yes/no" line is called a "branch".
-- And
the suggestion boxes ("Take 115") are
called "leaves"
-- instead of questions/answers,
there are moves/countermoves
i.e.) DT is also an algorithm for playing a
game
i.e.)
for solving the problem: what move
should I make next?
e.g.) 5-NIM:
Playing board: row
of 5 boxes
(you can also play 1-NIM,
2-NIM, ..., 1000-NIM)
___ ___ ___ ___ ___ | | | | | | |___|___|___|___|___|
e.g.)
___ ___ ___ ___ ___ | | | | | | | X | X | O | O | X | |___|___|___|___|___|
Possible DT for 5-NIM:
computer says: -------------- | Your move. | -------------- /\ human's move: X/ \XX / \ / \ / \ / \ / \ ----------- ----------- |I play O;| |I play O;| |your move| |your move| ----------- ----------- /\ /\ / \ / \ X/ \XX X/ \XX / \ / \ / \ / \ ------------ ------------ ----------- ---------- |I play OO;| |I play 00;| |I play O;| |You win!| | I win! | | I win! | | I win! | ---------- ------------ ------------ -----------Issues:
*
one way to handle this:
figure out computer's best strategy;
then put that in the DT
2- How to get computer to actually play Nim:
*
in general, how to get computer to
run a DT program
* DT program
has to be able to print
questions
b) Sample Pascal program:
* same program, with comments:
{Name: Bill Rapaport
}
{Date: 2 Oct 00
}
{Anything within braces is a comment}
begin {a reserved word indicating start}
{of a sequence of instructions;
}
{here, it's like Karel's
}
{"beginning-of-execution"
}
writeln('This is a');
{semicolons separate instructions}
writeln('test program')
{"This is a" & "test program" are data}
end.
{"end" is a reserved word indicating}
{the end of a sequence; here, it's like}
{Karel's "end-of-execution"}
{The period ends the program;}
{it's like Karel's "end-of-program"}
You can type either of these into a Unix file,
compile them, and execute them.
The method I showed in lecture was this
(you'll get more detail in HW #5,
including a fix you'll have to make to your
".cshrc" file before you can access the Pascal
compiler)
1) Use pico to create a file containing
your
program
2) Save the program & exit
pico
3) Use the "pc" command to compile
the
program
4) Execute the "a.out" file that
the compiler
creates.