HAZıRLAYAN: YRD.DOÇ.DR.EMIN BORANDAĞ Oyun Programlama (Yol Bulma)
Yol Bulma Problem Oyuncu verilen yollar içerisinden en kıza olan yolu bulması gerekmektedir. Yol Bulma Algoritması En etkin şekilde en az maliyetle en güzel yolu bulma Etkinlik Yolun Durumuna Bak Çevrenin Durumuna Bak Noktaları Kullan.
Pseudocode Add starting node to open_list while (not_empty(open_list)) { current_node := node from open_list with lowest cost if (current_node==goal_node) { path complete } else { move current_node to closed_list for each node adjacent to current_node { if ((node is not in open_list) && (node is not in closed_list)) { move node to open_list assign cost to node }
Yolu Nasıl Kat Edeceğiz Add starting node to open_list while (not_empty(open_list)) { current_node := node from open_list with lowest cost if (current_node==goal_node) { path complete } else { move current_node to closed_list for each node adjacent to current_node { if ((node is not in open_list) && (node is not in closed_list)) { move node to open_list assign cost to node } Yolun Tamamlanması yada yolda bir yer katedildiğinde hangi kodların çalışacağı liste içerisinde nasıl kullanılacağı verilmiştir. B A
Maliyeti Nasıl Belirleyeceğiz? Maliiyet = Başlangıç Maliyeti + Sezgisel Başlangıç Maliyeti= Başlangıç Noktasında olan maliyet Sezgisel = Hedef Düz bir çizgi gibi ulaşılabiliyormu?
Örnek Start End Adım 1: Open List: Closed List: Empty Node: (2,2) Cost: 5 Distance from start: 0
Örnek Devam 7 5 Start 7 5 End Adım 2: Open List: Closed List: Node: (1,2) Cost: 7 Distance from start: 1 Node: (2,1) Cost: 7 Distance from start: 1 Node: (3,2) Cost: 5 Distance from start: 1 Node: (2,3) Cost: 5 Distance from start: 1 Node: (2,2)
Örnek Devam 7 5 Start 7 End Adım 3: Open List: Closed List: Node: (1,2) Cost: 7 Distance from start: 1 Node: (2,1) Cost: 7 Distance from start: 1 Node: (2,3) Cost: 5 Distance from start: 1 Node: (3,3) Cost: 5 Distance from start: 2 Node: (2,2) Node: (4,2) Cost: 5 Distance from start: 2 Node: (3,1) Cost: 7 Distance from start: 2 Node: (3,2)
Graph Yol Bulma Maze tarzı Bir oyunda Yolbulma.
Graph Yol Bulma Bir Graf oluştur. Düyümler Sistem İçerisinde Tanımanmış Olmalı
Graph Path-Finding Her Birinin Belli Bir Maliyet Hesabı Olmalı
Graph Path-Finding destination start
Graph En Kısa Yol En Kısa Yolu Bulma Algoritması Dijkstra’s Algorithm { Add starting node to open_list while (not_empty(open_list)) { current_node := node from open_list with lowest cost if (current_node==goal_node) { path complete } else { move current_node to closed_list for each node adjacent to current_node { if (node is not in closed_list) { if (node not in open_list) move node to open_list AssignCost(node) } How to AssignCost(node)? In the beginning, each node has infinite cost. When AssignCost(node), calculate the new cost of the node. New cost = Cost current_node + Distance current_node,node If (new_cost < original_cost) cost := new_cost