18
A* Pathfinding

A* Pathfinding. Basis A* Algorithmus add the starting node to the open list while the open list is not empty { current node=node from open list with the

Embed Size (px)

Citation preview

Page 1: A* Pathfinding. Basis A* Algorithmus add the starting node to the open list while the open list is not empty { current node=node from open list with the

A* Pathfinding

Page 2: A* Pathfinding. Basis A* Algorithmus add the starting node to the open list while the open list is not empty { current node=node from open list with the

Basis A* Algorithmusadd the starting node to the open listwhile the open list is not empty{

current node=node from open list with the lowest costif current node = goal node then

path completeelse

move current node to the closed listexamine each node adjacent to the current nodefor each adjacent nodeif it isn‘t on the open list and isn‘t on the closed list and isn‘t an obstacle then move it to open list and calculate cost

}

Page 3: A* Pathfinding. Basis A* Algorithmus add the starting node to the open list while the open list is not empty { current node=node from open list with the

• Open List: valide Nodes, die noch geprüft werden müssen

(Invalide Nodes sind Nodes, die Hindernisse beinhalten)

• Closed List: Nodes, die schon geprüft worden sind

• Parent Node: Jedes Node hat ein Parent-Node, und zwar dasjenige von dem der Spielcharakter kommt. Pointer zeigt immer zum Parent Node

Page 4: A* Pathfinding. Basis A* Algorithmus add the starting node to the open list while the open list is not empty { current node=node from open list with the

Spiel

E

A

Open List

Closed List

Hindernis

Offenes Terrain

Sumpfgelände

Graslandschaft

Page 5: A* Pathfinding. Basis A* Algorithmus add the starting node to the open list while the open list is not empty { current node=node from open list with the

Basis A* Algorithmusadd the starting node to the open listwhile the open list is not empty{

current node=node from open list with the lowest costif current node = goal node then

path completeelse

move current node to the closed listexamine each node adjacent to the current nodefor each adjacent nodeif it isn‘t on the open list and isn‘t on the closed list and isn‘t an obstacle then move it to open list and calculate cost

}

Page 6: A* Pathfinding. Basis A* Algorithmus add the starting node to the open list while the open list is not empty { current node=node from open list with the

add the starting node to the open list

E

A

Open List

Closed List

Hindernis

Offenes Terrain

Sumpfgelände

Graslandschaft

Page 7: A* Pathfinding. Basis A* Algorithmus add the starting node to the open list while the open list is not empty { current node=node from open list with the

Basis A* Algorithmusadd the starting node to the open listwhile the open list is not empty{

current node=node from open list with the lowest costif current node = goal node then

path completeelse

move current node to the closed listexamine each node adjacent to the current nodefor each adjacent nodeif it isn‘t on the open list and isn‘t on the closed list and isn‘t an obstacle then move it to open list and calculate cost

}

Page 8: A* Pathfinding. Basis A* Algorithmus add the starting node to the open list while the open list is not empty { current node=node from open list with the

CostCost = (Cost from Start + Terrain Cost) + Heuristic

Cost from Start: Kosten von Startpunkt zum aktuellen Node (über wie viele Pointer kommt man vom aktuellen Node zum Startnode)

Terrain Cost: Kosten des Terrains (zum Beispiel, wie viele Sekunden braucht Spielcharakter um Terrain zu durchqueren)

Unser Beispiel: Offenes Terrain: 1

Graslandschaft: 3

Sumpfgelände: 5

Heuristic: Kosten vom Endpunkt zum aktuellen Node

Schätzungswert, da der Weg noch nicht determiniert ist.

Man nimmt die Anzahl der Schritte, die zum Endpunkt führen, jedoch ohne Berücksichtung von Terrain oder Hindernis.

Page 9: A* Pathfinding. Basis A* Algorithmus add the starting node to the open list while the open list is not empty { current node=node from open list with the

current node=node from open list with the lowest cost

E

T:3,S:1,

H:3,C:7

T:1,S:1,

H:3,C:5

T:3,S:1

H:3,C:7

T:1,S:1

H:4,C:6 A

T:1,S:1

H:4,C:6

T:1,S:1

H:5,

T:1,S:1,

H:5,C:7

T:1,S:1,H:5,C:7

Open ListT=Terraincost

S=Cost from Start

H=Heuristic

C=Cost

Closed List

Hindernis (wird ignoriert)

Offenes Terrain (1)

Sumpfgelände (5)

Graslandschaft (3)

Page 10: A* Pathfinding. Basis A* Algorithmus add the starting node to the open list while the open list is not empty { current node=node from open list with the

Basis A* Algorithmusadd the starting node to the open listwhile the open list is not empty{

current node=node from open list with the lowest costif current node = goal node then

path completeelse

move current node to the closed listexamine each node adjacent to the current nodefor each adjacent nodeif it isn‘t on the open list and isn‘t on the closed list and isn‘t an obstacle then move it to open list and calculate cost

}

Page 11: A* Pathfinding. Basis A* Algorithmus add the starting node to the open list while the open list is not empty { current node=node from open list with the

current node=node from open list with the lowest cost

E

T:3,S:1,

H:3,C:7

T:1,S:1,

H:3,C:5

T:3,S:1

H:3,C:7

T:1,S:1

H:4,C:6 A

T:1,S:1

H:4,C:6

T:1,S:1

H:5,C:7

T:1,S:1,

H:5,C:7

T:1,S:1,H:5,C:7

Open ListT=Terraincost

S=Cost from Start

H=Heuristic

C=Cost

Closed List

Hindernis (wird ignoriert)

Offenes Terrain (1)

Sumpfgelände (5)

Graslandschaft (3)

Page 12: A* Pathfinding. Basis A* Algorithmus add the starting node to the open list while the open list is not empty { current node=node from open list with the

current node=node from open list with the lowest cost

E

T:3,S:2

H:4,C:9

T:3,S:1,

H:3,C:7

T:1,S:1,

H:3,C:5

T:3,S:1

H:3,C:7

T:1,S:2,

H:3;C:6

T:1,S:2

H:4,C:7

T:1,S:1

H:4,C:6 A

T:1,S:1

H:4,C:6

T:1,S:2,

H:4,C:7

T:1,S:2

H:5;C:8 T:1,S:1

H:5,C:7

T:1,S:1,

H:5,C:7

T:1,S:1,H:5,C:7

T:1,S:2

H:5,C:8

Open ListT=Terraincost

S=Cost from Start

H=Heuristic

C=Cost

Closed List

Hindernis (wird ignoriert)

Offenes Terrain (1)

Sumpfgelände (5)

Graslandschaft (3)

Page 13: A* Pathfinding. Basis A* Algorithmus add the starting node to the open list while the open list is not empty { current node=node from open list with the

current node=node from open list with the lowest cost(worst case, alle 7 Nodes werden überprüft)

E

T:3,S:2

H:4,C:9

T:3,S:1,

H:3,C:7

T:1,S:1,

H:3,C:5

T:3,S:1

H:3,C:7

T:1,S:2,

H:3;C:6

T:1,S:2

H:4,C:7

T:1,S:1

H:4,C:6 A

T:1,S:1

H:4,C:6

T:1,S:2,

H:4,C:7

T:1,S:2

H:5;C:8 T:1,S:1

H:5,C:7

T:1,S:1,

H:5,C:7

T:1,S:1,H:5,C:7

T:1,S:2

H:5,C:8

Open ListT=Terraincost

S=Cost from Start

H=Heuristic

C=Cost

Closed List

Hindernis (wird ignoriert)

Offenes Terrain (1)

Sumpfgelände (5)

Graslandschaft (3)

Page 14: A* Pathfinding. Basis A* Algorithmus add the starting node to the open list while the open list is not empty { current node=node from open list with the

current node=node from open list with the lowest cost(worst case, alle Nodes mit lowest cost werden überprüft)

E

T:5,S:3

H:4,

C:12

T:1,S:3

H:5,C:9

T:3,S:2

H:4,C:9

T:3,S:1,

H:3,C:7

T:1,S:1,

H:3,C:5

T:3,S:1

H:3,C:7

T:1,S:2,

H:3;C:6

T:5,S:3

H:5,

C:13

T:1,S:2

H:4,C:7

T:1,S:1

H:4,C:6 A

T:1,S:1

H:4,C:6

T:1,S:2,

H:4,C:7

T:3,S3

H:5,

C:11

T:1,S:2

H:5;C:8

T:1,S:1

H:5,C:7

T:1,S:1,

H:5,C:7

T:1,S:1,H:5,C:7

T:1,S:2

H:5,C:8

T:3,S:2

H:6,

C:6

T:3,S:2

H:6,

C:11

T:3,S:2

H:6,

C:11

T:5,S:2

H:6;

C:13

Open ListT=Terraincost

S=Cost from Start

H=Heuristic

C=Cost

Closed List

Hindernis (wird ignoriert)

Offenes Terrain (1)

Sumpfgelände (5)

Graslandschaft (3)

Page 15: A* Pathfinding. Basis A* Algorithmus add the starting node to the open list while the open list is not empty { current node=node from open list with the

current node=node from open list with the lowest cost(hier kommt nur 1 Node auf Open List,2 auf Closed list)

E

T:5,S:3

H:4,

C:12

T:1,S:3

H:5,C:9

T:3,S:2

H:4,C:9

T:3,S:1,

H:3,C:7

T:1,S:1,

H:3,C:5

T:3,S:1

H:3,C:7

T:1,S:2,

H:3;C:6

T:5,S:3

H:5,

C:13

T:1,S:2

H:4,C:7

T:1,S:1

H:4,C:6 A

T:1,S:1

H:4,C:6

T:1,S:2,

H:4,C:7

T:3,S3

H:5,

C:11

T:1,S:2

H:5;C:8

T:1,S:1

H:5,C:7

T:1,S:1,

H:5,C:7

T:1,S:1,H:5,C:7

T:1,S:2

H:5,C:8

T:3,S:2

H:6,

C:6

T:3,S:2

H:6,

C:11

T:3,S:2

H:6,

C:11

T:5,S:2

H:6;

C:13

T:3,S:3

H:6

C:12

Open ListT=Terraincost

S=Cost from Start

H=Heuristic

C=Cost

Closed List

Hindernis (wird ignoriert)

Offenes Terrain (1)

Sumpfgelände (5)

Graslandschaft (3)

Page 16: A* Pathfinding. Basis A* Algorithmus add the starting node to the open list while the open list is not empty { current node=node from open list with the

current node=node from open list with the lowest cost(worst case: alle Nodes mit lowest cost werden überprüft)

E

T:1,S:4

H:6,

C:11

T:1,S:3,

H:5,C:9

T:5,S:3

H:4,

C:12

T:5,S:4

H:6

C:15

T:1,S:3

H:5,C:9

T:3,S:2

H:4,C:9

T:3,S:1,

H:3,C:7

T:1,S:1,

H:3,C:5

T:3,S:1

H:3,C:7

T:1,S:2,

H:3;C:6

T:1,S:4

H:6

C:11

T:5,S:3

H:5,

C:13

T:1,S:2

H:4,C:7

T:1,S:1

H:4,C:6 A

T:1,S:1

H:4,C:6

T:1,S:2,

H:4,C:7

T:3,S3

H:5,

C:11

T:1,S:2

H:5;C:8

T:1,S:1

H:5,C:7

T:1,S:1,

H:5,C:7

T:1,S:1,H:5,C:7

T:1,S:2

H:5,C:8

T:3,S:2

H:6,

C:6

T:3,S:2

H:6,

C:11

T:3,S:2

H:6,

C:11

T:5,S:2

H:6;

C:13

T:3,S:3

H:6

C:12

Open ListT=Terraincost

S=Cost from Start

H=Heuristic

C=Cost

Closed List

Hindernis (wird ignoriert)

Offenes Terrain (1)

Sumpfgelände (5)

Graslandschaft (3)

Page 17: A* Pathfinding. Basis A* Algorithmus add the starting node to the open list while the open list is not empty { current node=node from open list with the

if current node= goal node then path complete

T:3,S:6

H:4

C:13

T:1,S:6,

H:3,

C:10

T:3,S:7

H:2,

C:12

T:1,S:8

H:1

C:10

T:1,S:9

H:1

C:11

T:1,S:5

H:5

C:11

T:1,S:5

H:4

C:10

T:5,S:5

H:3

C:13

T:1,S:7

H:2

C:10

T:1,S:8

H:1

C:10E C:10

T:1,S:4

H:6

C:11

T:1,S:4

H:5

C:10

T:1,S:4

H:4

C:9

T:3,S:5

H:3

C:11

T:1,S:8

H:2,

C:11

T:1,S:8

H1

C:10

T:1,S:9

H:1

C:11

T:1,S:4

H:6

C:11

T:1,S:3

H:5

C:9

T:5,S:2

H:4,

C:11

T:5,S:4

H:6

C:15

T:1,S:3

H:5,C:9

T:3,S:2

H:4,C:9

T:3,S:1,

H:3,C:7

T:1,S:1,

H:3,C:5

T:3,S:1

H:3,C:7

T:1,S:2,

H:3;C:6

T:1,S:4

H:6

C:11

T:5,S:3

H:5,

C:13

T:1,S:2

H:4,C:7

T:1,S:1

H:4,C:6 A

T:1,S:1

H:4,C:6

T:1,S:2,

H:4,C:7

T:3,S3

H:5,

C:11

T:1,S:2

H:5;C:8

T:1,S:1

H:5,C:7

T:1,S:1,

H:5,C:7

T:1,S:1,H:5,C:7

T:1,S:2

H:5,C:8

T:3,S:2

H:6,

C:11

T:3,S:2

H:6,

C:11

T:3,S:2

H:6,

C:11

T:5,S:2

H:6;

C:13

T:3,S:3

H:6,

C:12

Open ListT=Terraincost

S=Cost from Start

H=Heuristic

C=Cost

Closed List

Hindernis (wird ignoriert)

Offenes Terrain (1)

Sumpfgelände (5)

Graslandschaft (3)

Page 18: A* Pathfinding. Basis A* Algorithmus add the starting node to the open list while the open list is not empty { current node=node from open list with the

Schnellster Pfad

E

A

Open List

Closed List

Hindernis

Offenes Terrain

Sumpfgelände

Graslandschaft