-
Notifications
You must be signed in to change notification settings - Fork 0
/
agente inteligente robô aspirador de pó.cpp
131 lines (97 loc) · 2.43 KB
/
agente inteligente robô aspirador de pó.cpp
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void printMatriz(int * * matriz, int valorI, int valorJ) {
for(int i = 0; i < valorI; i++) {
for (int j = 0; j < valorJ; j++) {
printf("%d ", matriz[i][j]);
}
printf("\n");
}
printf("\n");
}
int main(int argc, char** argv)
{
int valorI = 0;
int valorJ = 0;
int casasuja = 0;
int cont = 0;
int x = 0;
int y = 0;
int l =1;
do{
printf("informe o valor de I: ");
scanf("%d",&valorI);
printf("informe o valor de J: ");
scanf("%d",&valorJ);
do{
printf("informe o valor de casa suja: ");
scanf("%d",&casasuja);
}while(casasuja >((valorI*valorJ)-1));
int * * r = (int * * ) malloc(sizeof (int * ) * valorI);
for (int i = 0; i < valorI; i++) {
r[i] = (int * ) malloc(sizeof (int) * valorJ);
}
srand(time(NULL));
x = rand() % valorI;
y = rand() % valorJ;
r[x][y] = 0;
do{
cont = 0;
for(int i = 0; i < valorI; i++) {
for (int j = 0; j < valorJ; j++) {
if((x==i)&& (y==j)){
continue;
}
if(cont<=casasuja){
r[i][j] = rand() % 2;
if(r[i][j]== 1){
cont++;
}
}else
{
r[i][j] = 0;
}
}
}
}while(cont!=casasuja);
printf("Matriz inicial:\n");
printf("O comeca robo na posicao: (%d)(%d)\n", x, y);
printMatriz(r, valorI, valorJ);
do {
if((((y + 1) < valorJ) && ((y + 1) >= 0)) && (r[x][y + 1] > 0)) {
y += 1;
printf("O robo esta na posicao: (%d)(%d)\n", x, y);
r[x][y] = 0;
printMatriz(r, valorI, valorJ);
continue;
}
if((((x + 1) < valorI) && ((x + 1) >= 0)) && (r[x + 1][y] > 0)) {
x += 1;
printf("O robo esta na posicao: (%d)(%d)\n", x, y);
r[x][y] = 0;
printMatriz(r, valorI, valorJ);
continue;
}
if((((y - 1) < valorJ) && ((y - 1) >= 0)) && (r[x][y - 1] > 0)) {
y -= 1;
printf("O robo esta na posicao: (%d)(%d)\n", x, y);
r[x][y] = 0;
printMatriz(r, valorI,valorJ);
continue;
}
if((((x - 1) < valorI) && ((x - 1) >= 0)) && (r[x - 1][y] > 0)) {
x -= 1;
printf("O robo esta na posicao: (%d)(%d)\n", x, y);
r[x][y] = 0;
printMatriz(r, valorI,valorJ);
continue;
}
break;
} while(true);
printf("\nAperte a tecla 0 zero para sair: ");
scanf("%d", &l);
system("cls");
}while(l!=0);
return 0;
}