liblashgame

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

manhattan.c (911B)


      1 // manhattanmagnitude
      2 
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 #include <time.h>
      6 #include "../lash_game_standard.h"
      7 
      8 int main(int argc, char *argv[]) {
      9 	
     10 	clock_t test_clock_total = 0.f;
     11 	
     12 	if (argc<5) {
     13 		printf("Usage: %s targetx targety sourcex sourcey\n", argv[0]);
     14 		return 1;
     15 	}
     16 	
     17 	lash_game_coords_t targetcoords, sourcecoords;
     18 	targetcoords.x = atoi(argv[1]);
     19 	targetcoords.y = atoi(argv[2]);
     20 	sourcecoords.x = atoi(argv[3]);
     21 	sourcecoords.y = atoi(argv[4]);
     22 	
     23 	clock_t begin = clock();
     24 	int distance = lash_getManhattanMagnitudeFromCartesian(targetcoords, sourcecoords);
     25 	test_clock_total += clock() - begin;
     26 	
     27 	printf("Distance from x%d,y%d to x%d,%d: %d\n", sourcecoords.x, sourcecoords.y, targetcoords.x, targetcoords.y, distance);
     28 	printf("Total insert time: %lu ticks @ %li pr sec = %.7f secs\n\n", (long)test_clock_total, CLOCKS_PER_SEC, ((double)test_clock_total / CLOCKS_PER_SEC));
     29 	return 0;
     30 }