-
Notifications
You must be signed in to change notification settings - Fork 1
/
ANIMAL.ACH
107 lines (90 loc) · 2.46 KB
/
ANIMAL.ACH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# The ANIMAL game in Archetype. A neat demo! The ability to save total
# object state in Archetype is used to painlessly and transparently save
# the question/answer database. Because of this, the initial database is
# stored directly within the code! Showcases some unusual features
# of Archetype.
#
# Author: DTJ 11/26/94
null main
branch : UNDEFINED
alternative : UNDEFINED
key_pressed : UNDEFINED
response : UNDEFINED
methods
'AFFIRM' : {
response := ( ((key_pressed := key) leftfrom 1) within "yY" )
write key_pressed
response
}
'START' : {
writes "Load old game? "
if 'AFFIRM' -> main then {
writes "Name of file? "
'LOAD STATE' -> system
read -> system
}
while TRUE do {
'PLAY'
writes "Another game [y/n] ? "
if not 'AFFIRM' -> main then {
writes "Save this game? "
if 'AFFIRM' -> main then {
writes "Save to file: "
'SAVE STATE' -> system
read -> system
}
stop "Thanks for playing."
}
}
}
'PLAY' : {
write "Think of an animal; hit any key when ready."; key
branch := beginning
while alternative := 'QUESTION' -> branch do
branch := alternative
write "You were thinking of... ", 'ANSWER' -> branch, "!"
writes "Am I right? "
if 'AFFIRM' -> main then
write "I knew it!"
else
'EXTEND' -> branch
}
end
class question based on null
IfYes : UNDEFINED
IfNo : UNDEFINED
Q : UNDEFINED
A : UNDEFINED
methods
'QUESTION' :
if Q then {
writes Q & " "
if 'AFFIRM' -> main then IfYes else IfNo
}
'ANSWER' : A
'EXTEND' : {
create question named IfYes
writes "What were you thinking of? "
IfYes.A := read
write "What question could I ask to distinguish \"", A, "\" from \"",
IfYes.A, "\" ? "
Q := read
create question named IfNo
IfNo.A := A
writes "So if I ask \"", Q, "\", the right answer is \"", IfYes.A, "\" ? "
if not 'AFFIRM' -> main then {
A := IfNo.A
IfNo.A := IfYes.A
IfYes.A := A
}
A := UNDEFINED
}
end
# To get things started: one question with a yes and no answer
question beginning
IfYes : whale
IfNo : dog
Q : "Does it live in the water?"
end
question whale A : "a whale" end
question dog A : "a dog" end