1 import utils
.file, random
, grammar
6 def __init__(self
,file,grammar
=grammar
):
10 file = utils
.file.read(self
.file)
11 d
= file.split(self
.grammar
.line
)
12 d
.append(gramar
.time
.join(self
.history
) + self
.grammar
.att
+ data
)
13 utils
.file.write(self
.file, self
.grammar
.line
.join(d
))
14 def output(self
, options
):
15 data
= utils
.file.read(self
.file)
18 for option
in options
:
19 n
= self
.find(data
, option
)
26 ret
= opts
[random
.randint(0, len(opts
)-1)]
27 self
.history
.append(ret
)
29 def find(self
,data
,att
):
31 for line
in data
.split(self
.grammar
.line
):
32 if line
.split(self
.grammar
.att
)[0] == att
:
33 if line
.split(self
.grammar
.att
)[1] == self
.grammar
.good
:
35 elif line
.split(self
.grammar
.att
)[1] == self
.grammar
.bad
:
38 score
+= self
.find(data
, line
.split(self
.grammar
.att
)[1])