-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.cpp
More file actions
112 lines (88 loc) · 2.57 KB
/
bot.cpp
File metadata and controls
112 lines (88 loc) · 2.57 KB
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
108
109
110
111
/*
* bot.cpp
*
* Created on: 06/09/2012
* Author: rafa
*/
#include <sstream>
bot::bot(){
}
void bot::inicializar(string n, vector<string> *dicc, vector<string> *inten, pthread_mutex_t* c,pthread_mutex_t* di){
this->Nombre=n;
this->dicc=dicc;
this->intentos=inten;
this->consola=c;
this->consola=di;
}
void bot::inicializar(string n, vector<string> *dicc, vec_iter inicio, vec_iter fin, pthread_mutex_t* c,pthread_mutex_t* di){
this->Nombre=n;
this->dicc=dicc;
this->inicio=inicio;
this->fin=fin;
this->consola=c;
this->consola=di;
}
bot::bot(string n, vector<string> *dicc, vector<string> *inten, pthread_mutex_t* c,pthread_mutex_t* di) {
this->inicializar(n,dicc,inten,c,di);
}
bot::bot(string n, vector<string> *dicc, vec_iter inicio, vec_iter fin, pthread_mutex_t* c,pthread_mutex_t* di) {
this->inicializar(n,dicc,inicio,fin,c,di);
}
void bot::buscarAlt(){
std::stringstream sstm;
for(std::vector<string>::iterator intento = this->intentos->begin(); intento != this->intentos->end(); ++intento){
for(std::vector<string>::iterator palabra = this->dicc->begin(); palabra != this->dicc->end(); ++palabra){
//this->enviarMsj(*intento+":"+*palabra);
if(*intento == *palabra)
{
//std::cout<<this->Nombre<<":Anagrama: "<<this->intentos->at(k)<<std::endl;
sstm <<this->Nombre<<": Anagrama-> "<<*intento<<"\n";
this->enviarMsj(sstm.str());
//this->enviarMsj("consiguio");
sstm.str("");
}
}
}
//this->enviarMsj(this->Nombre + ": Finalize");
}
void bot::buscar(){
std::stringstream sstm;
//this->enviarMsj(*this->inicio+":");
for (vec_iter intento = this->inicio; intento != (this->fin - 1); ++intento){
for(std::vector<string>::iterator palabra = this->dicc->begin(); palabra != this->dicc->end(); ++palabra){
//this->enviarMsj(*intento+":"+*palabra);
if(*intento == *palabra)
{
//std::cout<<this->Nombre<<":Anagrama: "<<this->intentos->at(k)<<std::endl;
sstm <<this->Nombre<<": Anagrama-> "<<*intento<<"\n";
this->enviarMsj(sstm.str());
//this->enviarMsj("consiguio");
sstm.str("");
}
}
}
this->enviarMsj(this->Nombre + ": Finalize");
}
bool bot::comparar(int k)
{
bool r;
pthread_mutex_lock(this->diccIntentos);
if(this->intentos->at(k)==this->dicc->at(k)){
r=true;
pthread_mutex_unlock(this->diccIntentos);
return r;
}
else{
r= false;
pthread_mutex_unlock(this->diccIntentos);
return r;
}
}
void bot::enviarMsj(string msj){
pthread_mutex_lock(this->consola);
std::cout<<msj<<std::endl;
pthread_mutex_unlock(this->consola);
}
bot::~bot() {
// TODO Auto-generated destructor stub
}