#include #include "lib_type.h" #define GRIDWIDTH 120 #define GRIDHEIGHT 80 struct open_list_node{ u32 x; u32 y; u32 fvalue; struct open_list_node *parent; struct open_list_node *next; }; typedef struct open_list_node olnode; olnode* head; void init_open_list(u32 x, u32 y, u32 f){ head = calloc(1,sizeof(head) * GRIDWIDTH * GRIDHEIGHT); head->x = x/8; head->y = y/8; // Map_rep = Map_rep + (y/8 * GRIDWIDTH) + x/8; head->fvalue = f; head->parent = NULL; head->next = NULL; } void insert(u32 x, u32 y, u32 f){ if (in_list(x,y,f) == 1){ return; } else{ olnode* newnode = calloc(1,sizeof(newnode)); newnode->x = x/8; newnode->y = y/8; newnode->fvalue = f; olnode* temp = head; while(temp != NULL){ printf("%d\n",temp->fvalue); if(is_smaller(newnode,temp) == 1){ if(temp->parent == NULL){ printf("NOOOOOOOOOOOOOOO\n"); newnode->next = temp; newnode->parent = NULL; temp->parent = newnode; head = newnode; return; } else{ printf("HELLO\n"); newnode->parent = temp->parent; newnode->parent->next = newnode; temp->parent = newnode; newnode->next = temp; return; } } else if(temp->next == NULL){ // end of list temp->next = newnode; newnode->parent = temp; newnode->next = NULL; printf("%d\n",temp->fvalue); printf("HELLO\n"); return; } temp = temp->next; } } } int in_list(u32 x, u32 y, u32 f){ // olnode* temp = head; // while (temp != NULL){ // if ((temp->x == x/8) && (temp->y == y/8)){ // is_better(temp,f); // return 1; // } // temp = temp->next; // } // return 0; } void is_better(olnode* node,u32 f){ // if (f < node->fvalue){ // node->parent->next = node->next; // node->next->parent = node->parent; // free(node); // olnode* betternode = calloc(1,sizeof(betternode)); // // // } } int is_smaller(olnode* n1, olnode* n2){ if (n1->fvalue <= n2->fvalue){ return 1; } else { return 0; } } olnode* extract_min(){ olnode* min= head; if (head->next != NULL){ head = head->next; head->parent = NULL; } else { head = NULL; } return min; } int main(void){ init_open_list(50,25,2); insert(70,85,7); insert(35,49,5); olnode* temp = extract_min(); u32 x = temp->x; u32 y = temp->y; u32 f = temp->fvalue; printf("x: %d y: %d f: %d\n",x,y,f); temp = extract_min(); x = temp->x; y = temp->y; f = temp->fvalue; printf("x: %d y: %d f: %d\n",x,y,f); temp = extract_min(); x = temp->x; y = temp->y; f = temp->fvalue; printf("x: %d y: %d f: %d\n",x,y,f); }