In a pathfinding routine i am working on i would like to chart the estimated distance(in movement cost) from each square on my search area to the given target node. I am doing this before doing the actual search to initialise the search area ahead of time.
* horizontal and vertical steps only
* Each step costs 10movement points.
* all squares are valid steps
The target can be anywhere but for now i will say its in the centre of a 20 x 20 square area.
My current solution to this problem uses four (while) loops
each loop works outwards from the target node to a corner of the search area incrementing the cost by 10 on each move and storing in Hscore[Down][Across]
1st loop > back and up to top left
2nd > forward and up to top right
3rd > forward and down to bottom right
4th > back and down to bottom left
I am sure that i can just use one loop to achieve this! using a little calculation in the loop i would like to just sweep the search area from top left to bottom right adding the value as i go using a sum of some kind,
Ihad a quick go at a couple of versions but think i was getting my precedence in wrong order becasue it was producing all kinds of minus numbers.