-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
188 lines (169 loc) · 5.68 KB
/
Copy pathmain.cpp
File metadata and controls
188 lines (169 loc) · 5.68 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include <iostream>
#include <fstream>
#include <ncurses.h>
#include <unistd.h>
#include <stdio.h>
#include <chrono>
#include "table.hpp"
using namespace std;
//int dim=100;
/*
char vacio[]=" ";
char obstaculo[]="O";
char persona[]="P";
char coch[]="C";
char meta[]="M";
int tabla_actual,tabla_prox;
int estado_actual,estado_sig;
int x_act,y_act,x_sig,y_sig;
int filas=0;
int columnas=0;
char button='a';
int delay_10th=3;
bool color;
void init_game(){
while (button!=' ') {
clear();
getmaxyx(stdscr,filas,columnas);
if (color) {
attron(COLOR_PAIR(1));
}
mvprintw(filas/2, columnas/2-11, "Space para comenzar");
mvprintw(filas/2+1, columnas/2-12, "Otro space para acabar");
if (color) {
attroff(COLOR_PAIR(1));
}
refresh();
button=getch();
}
clear();
tabla_actual=-1;
estado_actual=2;
y_act=filas/2;
x_act=columnas/2;
for (int i=0; i<filas; i++) {
for (int j=0; j<columnas; j++) {
if (color) {
attron(COLOR_PAIR(3));
mvprintw(i, j, vacio);
attroff(COLOR_PAIR(3));
}else{
mvprintw(i, j, vacio);
}
}
}
if (color) {
attron(COLOR_PAIR(5));
mvprintw(y_act,x_act,coche[estado_actual-1]);
attroff(COLOR_PAIR(5));
}else{
mvprintw(y_act,x_act,coche[estado_actual-1]);
}
refresh();
}
*/
int main()
{
int inputx, inputy, inputz;
string opc;
// initscr();
// curs_set(0);
// noecho();
// cbreak();
// halfdelay(delay);
// color=has_colors();
// if(color){
// start_color();
// init_pair(COLOR_BLACK,COLOR_RED);//‘int init_pair(short int, short int, short int)’
// init_pair(COLOR_BLACK,COLOR_BLUE);
// init_pair(COLOR_BLACK,COLOR_MAGENTA);
// while(1){
// int new_row = 1;
// int new_col = 1;
// getmaxyx(stdscr,new_row,new_col);
// if(new_row!=row || new_col!= col){
// inicializar();
// }
// button = getch();
// if(button == ' ')
// break;
// current_x+=next_x*(current_state%2)*(current_state-2);
// current_y+=nex
// }
// }
// //wborder(win, 0, 0, 0, 0, 0, 0, 0, 0);
table* mapa;
car* coche= new car(1, 1);
//IA::
cout << "\033[32m"<< "Escoja una opción:\nfile->abrir fichero\nnormal->tablero por defecto\nrand->generar valor" <<"\033[0m"<< endl;
cin >> opc;
if (opc == "file"){
ifstream ifs;
ifs.open("map2.txt");
mapa = new table(ifs,coche);
}else if (opc == "normal"){
cout << "\033[32m"<< "Introduzca el tamaño del tablero:\nx->";
cin >> inputx;
cout << "y->";
cin >> inputy;
cout << "\033[0m";
mapa = new table(inputx,inputy,coche,false);//tamaño mapa;
}else if (opc == "rand"){
cout << "\033[32m"<<"Introduzca el tamaño del tablero:\nx->";
cin >> inputx;
cout << "y->";
cin >> inputy;
cout << "\033[0m";
mapa = new table(inputx,inputy,coche,true);
}else cout <<"\033[31m" << "error" << "\033[0m";
bool stay = true;
cout << mapa->final.first << "," <<mapa->final.second << endl;
cout << "\033[32m" <<"Escoja una opción:\nchange->cambia el valor de una casilla\nbool->crea o destruye un obstaculo\niter->mostrar mapa\n>rectilinear\n>euclid\n>level\nquit->Terminar" << "\033[0m"<< endl;
while(stay){
cin >> opc;
if (opc == "change"){
cin >> inputx >> inputy >> inputz;
mapa->set_final(inputx, inputy, inputz);
}
else if (opc == "move"){
cin >> inputx >> inputy;
mapa->set_car(inputx, inputy);
}
else if (opc == "bool"){
cin >> inputx >> inputy >> stay;
mapa->set_obstacle(inputx, inputy, (bool)stay/2);
stay = true;
}
else if (opc == "iter"){
mapa->write(std::cout);
}
else if (opc == "rectilinear"){
cout << "-----------------------" << endl;
auto start = std::chrono::high_resolution_clock::now();
coche->move_rect();
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
cout << "\033[32m"<<"Elapsed time: " << duration.count() << " microseconds(10^-9)" << "\033[0m"<< endl;
}
else if (opc == "level"){
cout << "-----------------------" << endl;
auto start = std::chrono::high_resolution_clock::now();
coche->move_lvlalg();
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
cout << "\033[32m"<<"Elapsed time: " << duration.count() << " microseconds(10^-9)" << "\033[0m"<< endl;
}
else if (opc == "euclid"){
cout << "-----------------------" << endl;
auto start = std::chrono::high_resolution_clock::now();
coche->move_euc();
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
cout << "\033[32m"<<"Elapsed time: " << duration.count() << " microseconds(10^-9)" << "\033[0m"<< endl;
}
else if (opc == "quit"){
stay = false;
}
}
return 0;
}