Pathfinding
Door Pim -, 18 jaar geleden, 7.507x bekeken
Hiermee kan je de kortste route tussen punten vinden.
Voorbeeld:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
ini_set('display_errors', 'on');
error_reporting(E_ALL | E_STRICT);
require_once 'Pathfinding.php';
require_once 'Pathfinding_Point.php';
// Create the points
$a = new Pathfinding_Point('A');
$b = new Pathfinding_Point('B');
$c = new Pathfinding_Point('C');
$d = new Pathfinding_Point('D');
$e = new Pathfinding_Point('E');
$f = new Pathfinding_Point('F');
$g = new Pathfinding_Point('G');
$h = new Pathfinding_Point('H');
$i = new Pathfinding_Point('I');
$j = new Pathfinding_Point('J', true);
$k = new Pathfinding_Point('K');
$l = new Pathfinding_Point('L');
// Create the links
$a->addLink($b)->addLink($g);
$b->addLink($e, 2)->addLink($d);
$c->addLink($g, 2)->addLink($d);
$d->addLink($f)->addLink($h);
$e->addLink($f)->addLink($i, 3);
$f->addLink($i, 3)->addLink($k);
$h->addLink($k)->addLink($l);
$i->addLink($j);
$l->addLink($j, 3);
// Create the object and adds the points
$pathFinding = new Pathfinding(array($a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k, $l));
// Calculate the route
$route = $pathFinding->find($a);
// Formats the route
echo Pathfinding::formatRoute($route);
echo '<br /> in '.$pathFinding->time().' seconds';
?>
ini_set('display_errors', 'on');
error_reporting(E_ALL | E_STRICT);
require_once 'Pathfinding.php';
require_once 'Pathfinding_Point.php';
// Create the points
$a = new Pathfinding_Point('A');
$b = new Pathfinding_Point('B');
$c = new Pathfinding_Point('C');
$d = new Pathfinding_Point('D');
$e = new Pathfinding_Point('E');
$f = new Pathfinding_Point('F');
$g = new Pathfinding_Point('G');
$h = new Pathfinding_Point('H');
$i = new Pathfinding_Point('I');
$j = new Pathfinding_Point('J', true);
$k = new Pathfinding_Point('K');
$l = new Pathfinding_Point('L');
// Create the links
$a->addLink($b)->addLink($g);
$b->addLink($e, 2)->addLink($d);
$c->addLink($g, 2)->addLink($d);
$d->addLink($f)->addLink($h);
$e->addLink($f)->addLink($i, 3);
$f->addLink($i, 3)->addLink($k);
$h->addLink($k)->addLink($l);
$i->addLink($j);
$l->addLink($j, 3);
// Create the object and adds the points
$pathFinding = new Pathfinding(array($a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k, $l));
// Calculate the route
$route = $pathFinding->find($a);
// Formats the route
echo Pathfinding::formatRoute($route);
echo '<br /> in '.$pathFinding->time().' seconds';
?>
Voorbeeld: http://pimwebdesign.nl/phphulp/pathfinding
Gesponsorde koppelingen
PHP script bestanden
Er zijn 15 reacties op 'Pathfinding'
Om te reageren heb je een account nodig en je moet ingelogd zijn.
PHP hulp
0 seconden vanaf nu