Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct uzol{
- int value;
- int x, y;
- char type;
- int f_value;
- int cena_cesty;
- struct uzol *parent;
- }UZOL;
- void graph_search(GRAF* graf, int x, int y, int konc_x, int konc_y){
- FRONT* open_list = NULL;
- UZOL *akt, *ls = NULL, *ps = NULL, *hs = NULL, *ds = NULL, *pom = NULL;
- int i = 0;
- akt = graf->uzol[x][y];
- akt->f_value = 0;
- akt->cena_cesty = 0;
- akt->parent = NULL;
- open_list = front_insert(open_list, akt);
- while (open_list != NULL){
- akt = front_return (open_list);
- front_remove_min (open_list);
- if (akt->x == konc_x && akt->y == konc_y)
- break;
- int cena;
- if (akt->x - 1 >= 0){ //lavy sused
- ls = graf->uzol[akt->y][akt->x - 1];
- if (ls->type == 'h')
- cena = akt->cena_cesty + 2;
- else
- cena = akt->cena_cesty + 1;
- ls->cena_cesty = cena;
- ls->parent = akt;
- ls->f_value = cena + abs(ls->x - konc_x) + abs(ls->y - konc_y);
- open_list = front_insert(open_list, ls);
- }
- if (akt->x + 1 <= graf->sirka){ //pravy sused
- ps = graf->uzol[akt->y][akt->x + 1];
- if (ps->type == 'h')
- cena = akt->cena_cesty + 2;
- else
- cena = akt->cena_cesty + 1;
- ps->cena_cesty = cena;
- ps->parent = akt;
- ps->f_value = cena + abs(ps->x - konc_x) + abs(ps->y - konc_y);
- open_list = front_insert(open_list, ps);
- }
- if (akt->y- 1 >= 0){ //horny sused
- hs = graf->uzol[akt->y - 1][akt->x];
- if (hs->type == 'h')
- cena = akt->cena_cesty + 2;
- else
- cena = akt->cena_cesty + 1;
- hs->cena_cesty = cena;
- hs->parent = akt;
- hs->f_value = cena + abs(hs->x - konc_x) + abs(hs->y - konc_y);
- open_list = front_insert(open_list, hs);
- }
- if (akt->y + 1 >= 0){ //dolny sused
- ds = graf->uzol[akt->y + 1][akt->x];
- if (ds->type == 'h')
- cena = akt->cena_cesty + 2;
- else
- cena = akt->cena_cesty + 1;
- ds->cena_cesty = cena;
- ds->parent = akt;
- ds->f_value = cena + abs(ds->x - konc_x) + abs(ds->y - konc_y);
- open_list = front_insert(open_list, ds);
- }
- akt = graf->uzol[x][y];
- while (akt != NULL) {
- printf("x: %d y: %d\n", akt->x, akt->y);
- akt = akt->parent;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement