This repository has been archived by the owner on Feb 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
project_oops.oz~
89 lines (89 loc) · 2.98 KB
/
project_oops.oz~
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
declare ProjectLib in
[ProjectLib] = {Link ['Documents/Etudes/Q3/Info2/projet/ProjectLib.ozf']}
local
ListOfPersons = {ProjectLib.loadDatabase file "Documents/Etudes/Q3/Info2/projet/database.txt"}
fun {BuildDecisionTree DB}
ListOfQuestions = ['A-t-il des cheveux longs ?'
'A-t-il des cheveux noirs ?'
'A-t-il une barbe ?'
'A-t-il une moustache ?'
'Voit-on ses dents ?'
'Est-il blanc de peau ?']
fun {BuildDecisionTreeAcc DB Question}
case Question of nil then
local Name={NewCell nil} in
for Person in DB do
Name:=Person.1|@Name
end
leaf(@Name)
end
[] H|T then
local ListTrue={NewCell nil} ListFalse={NewCell nil} ListUnknown={NewCell nil} ActualQuestion=H in
for Person in DB do
local Reponse=Person.ActualQuestion in
if Reponse==true then
ListTrue:=Person|@ListTrue
elseif Reponse==false then
ListFalse:=Person|@ListFalse
else
ListUnknown:=Person|@ListUnknown
end
end
end
question(H true:{BuildDecisionTreeAcc {Append @ListTrue @ListUnknown} T} false:{BuildDecisionTreeAcc {Append @ListFalse @ListUnknown} T})
end
end
end
in
{BuildDecisionTreeAcc DB ListOfQuestions}
end
fun {GameDriver Tree}
Result
fun {GameDriverAcc Tree OldTree ListOfQuestions OldListOfQuestions}
case Tree of leaf(ListOfNames) then
{ProjectLib.found ListOfNames}
[] question(H true:T false:F) then
local Reponse={ProjectLib.askQuestion ListOfQuestions.1} in
if Reponse==unknown then {GameDriverAcc {AttaTree T F} Tree ListOfQuestions.2 ListOfQuestions} % UNKNOWN
elseif Reponse==true then {GameDriverAcc T Tree ListOfQuestions.2 ListOfQuestions} % VRAI
elseif Reponse==false then {GameDriverAcc F Tree ListOfQuestions.2 ListOfQuestions} % FAUX
else {GameDriverAcc OldTree Tree OldListOfQuestions ListOfQuestions} % OOPS
end
end
end
end
fun {AttaTree Tree1 Tree2}
case Tree1 of leaf(ListOfNames1) then
case Tree2 of leaf(ListOfNames2) then
leaf({Append ListOfNames1 ListOfNames2})
[] question(H3 true:T3 false:T4) then
{Browse 'il y a une putain d''erreur'}
end
[] question(H1 true:T1 false:F1) then
case Tree2 of leaf(ListOfNames) then
{Browse 'il y a aussi une erreur bordel de merde'}
[] question(H2 true:T2 false:F2) then
if H1==H2 then question(H1 true:{AttaTree T1 T2} false:{AttaTree F1 F2})
else
{Browse 'il y a une erreur, les questions ne sont pas les mêmes'}
end
end
end
end
ListOfQuestions = ['A-t-il des cheveux longs ?'
'A-t-il des cheveux noirs ?'
'A-t-il une barbe ?'
'A-t-il une moustache ?'
'Voit-on ses dents ?'
'Est-il blanc de peau ?']
in
Result = {GameDriverAcc Tree Tree ListOfQuestions ListOfQuestions}
unit
end
in
{ProjectLib.play opts(builder:BuildDecisionTree
persons:ListOfPersons
driver:GameDriver
allowUnknown:true
oopsButton:true)}
end