liblashgame

Pathfinder and path decision making library for 2D tile game
git clone git://holbrook.no/liblashgame.git
Log | Files | Refs

pathsimple.c (1099B)


      1 #include <stdlib.h>
      2 #include <stdio.h>
      3 
      4 #include "../lash_game_path_simple.h"
      5 #include "../../liblash/lash_tree3_dump.h"
      6 #include "../../liblash/lash_tree3.h"
      7 #include "../lash_game_map.h"
      8 
      9 int main() {
     10 	
     11 	lash_path_simple_t path;
     12 	lash_map_simple_t map;
     13 	lash_path_simple_space_t *space;
     14 	unsigned int w = 20;
     15 	unsigned int h = 10;
     16 	lash_game_map_index_t startindex = 50;
     17 	lash_game_map_index_t nextindex = 60;
     18 	lash_game_map_index_t endindex = 150;
     19 	lash_path_simple_space_t *resultspace;
     20 	
     21 	if (lash_mapSimpleInit(&map, &w, &h) == NULL)
     22 		return 1;
     23 	
     24 	lash_pathSimpleInit();
     25 	
     26 	if (lash_pathSimpleNew(&path, &map, startindex, endindex) == NULL)
     27 		return 1;
     28 	
     29 	lash_pathSimpleNext(&path, &space);
     30 	_lash_pathSimpleClose(&path, *(path.opentree)->item);
     31 	resultspace = _lash_pathSimpleFindIndexInTree(path.closedtree, startindex);
     32 	
     33 	space = _lash_pathSimpleAddSpace(&path);
     34 	_lash_pathSimpleUpdateSpace(&path, space, resultspace, nextindex, resultspace->g + 14);
     35 	lash_treePush(path.opentree, space, NULL);
     36 	
     37 	resultspace = _lash_pathSimpleFindIndexInTree(path.opentree, nextindex);
     38 	
     39 	return 0;
     40 }