春秋里的自动寻路实在是太让人头疼了,闲来无事,研究了一下传说已久的A*寻路。挺有趣的算法,以下是我用PHP实现的A*寻路代码。
<?php
set_time_limit(5);
// A*寻路
$map_width = 9; $map_height = 9;
// 是否允许障碍物边界斜向通过 $is_agree = 0;
// 消耗 $cost_1 = 10; $cost_2 = 14;
// 设置起始和结束坐标 $begin_x = 4; $begin_y = 2; $end_x = 0; $end_y = 0;
// 设置障碍物坐标 $hindrance = array(); $hindrance[] = array(1,2); |