-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBot.py
63 lines (55 loc) · 1.81 KB
/
Bot.py
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
'''
Created on 04/09/2012
@author: rafa
'''
import copy
from multiprocessing import Process
class Bot(Process):
'''
classdocs
'''
def __init__(self, nombre, diccL, intento, master):
Process.__init__(self)
self.nombre = nombre
self.diccL = diccL
self.intento = intento
self.master = master
self.lockM = self.master.lockM
def buscarAlt(self):
first = True
i = 0
try:
while (True):
i += 1
inten = self.intento.__next__()
if first:
#print('{}: Nuevo slice desde {}'.format(self.name, ''.join(inten)))
first = False
if ''.join(inten) == "luciernaga":
print(''.join(inten).strip())
intent = ''.join(inten)
#for palabra in self.diccL:
if intent in self.diccL:
self.master.lockM.acquire()
print("Anagrama-> " + self.nombre + ":" + intent + ' en el intento {}'.format(i))
self.master.lockM.release()
del inten
except StopIteration:
pass
self.master.lockM.acquire()
print(self.nombre + ":Finalize")
self.master.lockM.release()
self.master.botsS.release()
def buscar(self):
consiguio = False
intento = self.intento.__str__().replace('\'', '').replace(
',', '').replace(' ', '').strip('()').strip()
for palabra in self.diccL:
if palabra == intento:
print("Anagrama-> " + self.nombre + ":" + palabra)
consiguio = True
return consiguio
def pedirIntento(self):
self.intento = self.master.genIntento()
def run(self):
self.buscarAlt()