커뮤니티로 돌아가기

대화

ThatGuyWithAS3님의 글에서 이어진 답글 0개

T
ThatGuyWithAS3@parkjimin

길찾기 알고리즘 ㅇㅇ 내가 저작권자이므로 다른 데 올린거 퍼온것도 내맘(퍽) * 수정 : 아래 만든이 이름, 격자 갯수 - 여긴 주닷이니까 주닷 닉넴으로(퍽) 아 그런데 swf 파일은 아래 파일을 쓰지 않은거 그냥 최단 거리 길찾기 알고리즘의 예시(?) 사용법: 이걸 따로 액션스크립트 파일(*.as)로 저장하기를 바랍니다. function Astar(arr:Array, sx:Number, sy:Number, ex:Number, ey:Number):Array arr: 2차원 행렬, 통과할 수 있는 지점의 값은 0, 통과할 수 없는 지점의 값은 0이 아닌 값으로 나타냅니다. arr[가로][세로] 꼴로 나타내집니다. (sx,sy)는 시작점, (ex,ey)는 끝점입니다., 리턴값은 Point 클래스들로 이루어진 행렬로, 시작점부터 끝점까지의 경로를 표시합니다. 그러므로 이것을 사용할 때에는 import flash.geom.Point; 를 꼭 넣으세요. 저작권은 바로 아래 파일 주석에 있습니다. 예제는 없습니다. /** MADE BY 123jimin@naver.com CCL by-sa 2.0 ( http://creativecommons.org/licenses/by-sa/2.0/deed.ko ) 을 따릅니다. 이용자는 아래의 조건을 따르는 경우에 한하여 자유롭게 이 저작물을 복제, 배포, 전송, 전시, 공연 및 방송할 수 있습니다. 리믹스 &#8212; 저작물의 개작 다음과 같은 조건을 따라야 합니다: 저작자표시 &#8212; 저작자나 이용허락자가 정한 방법으로 저작물의 원저작자를 표시하여야 합니다(그러나 귀하나 귀하의 저작물을 추천하는 의미로 표시되어서는 안됩니다). 동일조건변경허락 &#8212; 이 저작물의 개작, 변형물이나 가공물은 이 라이선스와 같거나 유사한 라이선스 하에서만 배포할 수 있습니다. */ //Point 클래스 import flash.geom.Point; //인덱스 찾기 function indOf(arr:Array, num:Number) { for (i=arr.length-1; i>=0; i--) { if (arr[i] == num) { break; } } return i; } //제거하기 function remove(arr:Array, num:Number):Array { var remove_ind:Number = indOf(arr, num); if (remove_ind>=0) { if (remove_ind == arr.length-1) { arr.pop(); } else { arr[remove_ind] = arr[arr.length-1]; arr.pop(); } } return arr; } //점 좌표로부터 숫자 리턴 function makeNum(x:Number, y:Number, wid:Number):Number { return x+y*wid; } //근처 점을 리턴하는 행렬 function nearPoint(num:Number, wid:Number, hei:Number):Array { var cap:Number = wid*hei-1; var ind:Number = num%wid; var num1:Number = num-wid; var num2:Number = num+wid; var ret:Array = new Array(); if (num1>=0) { ret.push(num1); } if (num2 =0; i--) { return_path.push(new Point(temp_path[i]%map_width,int(temp_path[i]/map_width))); } return return_path; } remove(open_set, k); closed_set.push(k); near_arr = new Array(); near_arr = nearPoint(k, map_width, map_height); for (i_near=0; i_near =0) { continue; } if (map[nr] != 0) { continue; } tentative_is_better = false; //이것도 수정 가능 tentative_g_score = g_score[k]+hEstimate(k, nr, map_width); if (indOf(open_set, nr)<0) { open_set.push(nr); tentative_is_better = true; } else if (tentative_g_score<g_score[nr]) { tentative_is_better = true; } if (tentative_is_better) { path[nr] = k; g_score[nr] = tentative_g_score; h_score[nr] = hEstimate(nr, endNum, map_width); } } } //실패 return return_path; } /* pseudocode function A*(start,goal) closedset := the empty set % The set of nodes already evaluated. openset := set containing the initial node % The set of tentative nodes to be evaluated. g_score[start] := 0 % Distance from start along optimal path. h_score[start] := heuristic_estimate_of_distance(start, goal) f_score[start] := h_score[start] % Estimated total distance from start to goal through y. while openset is not empty x := the node in openset having the lowest f_score[] value if x = goal return reconstruct_path(came_from,goal) remove x from openset add x to closedset foreach y in neighbor_nodes(x) if y in closedset continue tentative_g_score := g_score[x] + dist_between(x,y) if y not in openset add y to openset tentative_is_better := true elseif tentative_g_score < g_score[y] tentative_is_better := true else tentative_is_better := false if tentative_is_better = true came_from[y] := x g_score[y] := tentative_g_score h_score[y] := heuristic_estimate_of_distance(y, goal) f_score[y] := g_score[y] + h_score[y] return failure */