in Education by
I have a map stored as a multidimensional array ($map[row][col]) and I'd wish to create a path from point A to point B. Since I can have some obstacles with turns, corners, etc, etc, I'd wish to use the A* search to calculate the fastest path. So the general function is f(x) = g(x) + h(x) and I have all of these values. g(x) is the cost of the move (and it's saved on the map); h(x) is the linear distance between A and B. so I have everything I need, but I have a question: how can I organize everything? I have no need to test for alternative paths since a square on the map can be passable or not, so when I reach the target it should be the shortest one. how can I organize everything? I tried with the multidimensional array, but I get lost.. :( EDIT I worked out some code, it's pretty a wall of text :) //$start = array(28, 19), $end = array(14, 19) //$this->map->map is a multidimensional array, everything has a cost of 1, except for //blocking squares that cost 99 //$this->map->map == $this->radar //blocking square at 23-17, 22-18, 22-19, 22-20, 23-21, 19-17, 20-18,20-19,20-20,19-21 //they are like 2 specular mustache :P function createPath($start, $end) { $found = false; $temp = $this->cost($start, $end); foreach($temp as $t){ if($t['cost'] == $this->map->map[$end[0]][$end[1]]) $found = true; $this->costStack[$t['cost']][] = array('grid' => $t['grid'], 'dir' => $t['dir']); } ksort($this->costStack); if(!$found) { foreach($this->costStack as $k => $stack){ foreach($stack as $kn => $node){ $curNode = $node['grid']; unset($this->costStack[$k][$kn]); break; } if(!count($this->costStack[$k])) unset($this->costStack[$k]); break; } $this->createPath($curNode, $end); } } function cost($current, $target) { $return = array(); //$AIM = array('n' => array(-1, 0),'e' => array( 0, 1),'s' => array( 1, 0),'w' => array( 0, -1)); foreach($this->AIM as $direction => $offset){ $position[0] = $current[0] + $offset[0]; $position[1] = $current[1] + $offset[1]; //radar is a copy of the map if ( $this->radar[$position[0]][$position[1]] == 'V') continue; else $this->radar[$position[0]][$position[1]] = 'V'; $h = (int) $this->distance($position, $target); $g = $this->map->map[$position[0]][$position[1]]; $return[] = array('grid' => $position, 'dir' => $direction, 'cost' => $h + $g); } return $return; } I hope you can understand everything, I tried to be clear as much as possible. Finally, I can get to my destination, expanding only cheaper nodes, but now I have a problem. How can I turn it into directions? I have to store a stack of orders (ie n, n, e, etc), how can I identify a path inside these values? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
There are sites which can guide you for solving your query: Here are some helpful sites you can refer to: https://www.thoughtco.com/simple-site-search-2694116 Simple-search-using-PHP-MySQL PHP-MySQL-search-algorithm If you wish to know more about PHP MYSQL then visit this PHP and MySQL Training by Intellipaat.

Related questions

0 votes
    A friend of mine told me that it is possible to even create games with PHP. Is that really possible? Can we ... Looking for your ideas. Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    I quote from Artificial Intelligence: A Modern Approach: The properties of the depth-first search depend strongly on ... 3rd edition). Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I have an assignment to make an AI Agent that will learn play a video game using ML. I want to create a new ... the help of OpenAI Gym? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I write programs to play a board game variants sometimes. The basic strategy is standard alpha-beta pruning or ... human players. Select the correct answer from above options...
asked Jan 29, 2022 in Education by JackTerrance
0 votes
    I know the basics of feedforward neural networks, and how to train them using the backpropagation algorithm, but I'm ... , even better. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I'm looking for some examples of robot/AI programming using Lisp. Are there any good online examples available ... in nature)? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I'm teaching a kid programming, and am introducing some basic artificial intelligence concepts at the moment. To begin ... and boxes)? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    Nominally a good problem to have, but I'm pretty sure it is because something funny is going on... As ... labeled data vectors/instances (transformed video frames of individuals--...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I am learning programming (Python and algorithms) and was trying to work on a project that I find interesting. ... is impossible). Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    I'm trying to recover from a PCA done with scikit-learn, which features are selected as relevant. A classic example ... for your help. Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    I use a linear SVM to predict the sentiment of tweets. The LSVM classifies the tweets as neutral or positive ... predict('textoftweet') Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I have learned a Machine Learning course using Matlab as a prototyping tool. Since I got addicted to F#, I ... of resources? Thanks. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I have trouble understanding the difference (if there is one) between roc_auc_score() and auc() in scikit-learn. I ... out why. Thanks! Select the correct answer from above options...
asked Jan 29, 2022 in Education by JackTerrance
0 votes
    I'm creating a very basic AI with Tensorflow, and am using the code from the official docs/tutorial. Here's my ... Tensorflow 1.13.1. Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    I am currently working on an AI Agent that will be able to identify both the start state and the goal ... be greatly appreciated. Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
...