#define ROBOTOOLS_INCLUDED 1
#include "robotools.c"
#include "graph.c"
struct pont curr_poz;
struct csucs *curr_csucs, *start_csucs;
int curr_dir;
struct csucslista* csfej;
char csucs_dump_pointer[250];
int csucs_festes=1;
int first_junction=0;
void unknown_csucs(char* what) {
if (what[3]== '2' && first_junction++) {
curr_poz=pont_move(curr_poz, curr_dir);
curr_csucs=csucs_move(curr_csucs, curr_dir);
known_csucs(curr_csucs, "010", curr_dir, curr_poz, csfej, 0);
elfest(curr_csucs, curr_dir);
curr_poz=pont_move(curr_poz, curr_dir);
curr_csucs=csucs_move(curr_csucs, curr_dir);
known_csucs(curr_csucs, what, curr_dir, curr_poz, csfej, 1);
} else {
curr_poz=pont_move(curr_poz, curr_dir);
curr_csucs=csucs_move(curr_csucs, curr_dir);
known_csucs(curr_csucs, what, curr_dir, curr_poz, csfej, 1);
}
}
int main(int argc, char **argv) {
init();
curr_poz.x=0;
curr_poz.y=0;
curr_csucs=start_csucs=new_csucs();
csfej=cslist_add(NULL, curr_poz, curr_csucs);
curr_dir=0;
known_csucs(curr_csucs, "010\01", curr_dir, curr_poz, csfej, 0);
while (1) {
elfest(curr_csucs, curr_dir);
if (csucs_move(curr_csucs, curr_dir)->state==0) {
unknown_csucs(junction_search(1));
if (curr_csucs->siblings[(curr_dir+3)%4]!=NULL && curr_csucs->elfestes[(curr_dir+3)%4]==0) {
curr_dir=(curr_dir+3)%4;
left_turn();
} else if (curr_csucs->siblings[curr_dir]!=NULL && curr_csucs->elfestes[curr_dir]==0) {
no_turn();
} else if (curr_csucs->siblings[(curr_dir+1)%4]!=NULL && curr_csucs->elfestes[(curr_dir+1)%4]==0) {
curr_dir=(curr_dir+1)%4;
right_turn();
} else {
curr_dir=(curr_dir+2)%4;
around_turn();
}
} else {
if (curr_csucs->elfestes[curr_dir]==1) {
cputs("WTF1");
csucs_dump(start_csucs, csucs_dump_pointer, 0, csucs_festes++);
while(!shutdown_requested()) {
lnp_integrity_write(csucs_dump_pointer,strlen(csucs_dump_pointer));
delay(1000);
dsound_system(0);
}
deinit();
} else if (curr_csucs->elfestes[curr_dir]==2) {
junction_search(0);
curr_poz=pont_move(curr_poz, curr_dir);
curr_csucs=csucs_move(curr_csucs, curr_dir);
if (curr_csucs->siblings[curr_dir]!=NULL && curr_csucs->siblings[(curr_dir+3)%4]==NULL && curr_csucs->siblings[(curr_dir+1)%4]==NULL) {
elfest(curr_csucs, curr_dir);
curr_poz=pont_move(curr_poz, curr_dir);
curr_csucs=csucs_move(curr_csucs, curr_dir);
}
if (curr_csucs->siblings[(curr_dir+3)%4]!=NULL && curr_csucs->elfestes[(curr_dir+3)%4]==0) {
curr_dir=(curr_dir+3)%4;
left_turn();
} else if (curr_csucs->siblings[curr_dir]!=NULL && curr_csucs->elfestes[curr_dir]==0) {
no_turn();
} else if (curr_csucs->siblings[(curr_dir+1)%4]!=NULL && curr_csucs->elfestes[(curr_dir+1)%4]==0) {
curr_dir=(curr_dir+1)%4;
right_turn();
}
else if (curr_csucs->siblings[(curr_dir+3)%4]!=NULL && curr_csucs->elfestes[(curr_dir+3)%4]==1) {
curr_dir=(curr_dir+3)%4;
left_turn();
} else if (curr_csucs->siblings[curr_dir]!=NULL && curr_csucs->elfestes[curr_dir]==1) {
no_turn();
} else if (curr_csucs->siblings[(curr_dir+1)%4]!=NULL && curr_csucs->elfestes[(curr_dir+1)%4]==1) {
curr_dir=(curr_dir+1)%4;
right_turn();
} else {
break;
}
}
}
}
csucs_dump(start_csucs, csucs_dump_pointer, 0, csucs_festes++);
while(!shutdown_requested()) {
lnp_integrity_write(csucs_dump_pointer,strlen(csucs_dump_pointer));
delay(1000);
dsound_system(0);
}
deinit();
return 0;
}