A * algorithm restriction algorithm (shortest path ???) code file 3

zhaozj2021-02-16  77

// myfindgo.cpp: defines the entry point for the console application.//

#include "stdafx.h" #include

#include "find_path.h"

#include "windows.h" #include "mmsystem.h" #pragma comment (lib, "winmm.lib")

Class test_map {#define map_w_max 1000 # define map_h_max 1000public: Test_map () {MEMSET (Map, 0, Sizeof (Map));}

Static Bool Go_Test (INT X, INT Y) {IF (x <0 || y <0 || x> = map_w_max || y> = map_h_max) Return False;

IF (0! = MAP [x] [Y]) Return False;

Return True;

Static Bool Map [MAP_W_MAX] [MAP_H_MAX];}; BOOL TEST_MAP:: MAP [MAP_W_MAX] [MAP_H_MAX]; INT X0 = 2; int y0 = 2; int x1 = 1; int y1 = 1;

Void readMap () {file * f; f = fopen ("c: //tmp/map.txt", "r"); if (null == f) return;

INT x = 0; int y = 0; fscanf (f, "% D,% D / N", & x, & y); for (int J = 0; j

For (INT i = 0; i

IF ('s' == line [i]) {x0 = i; y0 = j; test_map :: map [i] [j] = 0;}

IF ('e' == line [i]) {x1 = i; y1 = j; test_map :: map [i] [j] = 0;}}}}}}} fclose (f);}

INT Main (int Argc, char * argv []) {test_map map; // - Initialization map // - Non-reachable point //map.map[0][0] = 1; map.map [2] [1] = 1; Map.map [3] [1] = 1; map.map [1] [2] = 1; map.map [3] [2] = 1; map.map [0] [2 ] = 1; readmap ();

Find_pathab fp; fp.init (100, 25, test_map :: go_test);

Int z;

DWORD T1 = TimegetTime (); // - Troubleshoot {for (int i = 0; i <1000; i ) z = fp.go (x0, y0, x1, y1);} DWORD T2 = TimegetTime (); DWORD T = T2 - T1; // - Print path for (int i = 0; i <= fp.path_t; i ) {printf ("x =% DY =% D / R / N", fp.path_p [ I] .x, fp.path_p [i] .y);} printf ("Path_t =% D Time_T =% D (MS) / R / N", fp.path_t, t);

Getch (); return 0;}

Use the file C:

//tmp//map.txt content is as follows 80,

24oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo oo oo s oooooooooooooo oo o oooooooooooo o oo o ooooooo oooooooooooooo oooooooo oo oooooo o oooo o o oo o o ooo ooo oo oooo oooo oo ooooooooooooooooooooooooooooooooooooooooooooooo oo oo ooooooooooooooooooooooooooooooooooooooooooooo oo o oooooooooooo o ooooooo oooooooo oo o o o o oo ooooooooooo oooooooooo o o oo oe ooo o o oo ooooo o o o oo o o oo

转载请注明原文地址:https://www.9cbs.com/read-14435.html

New Post(0)