Is the problem this?
1) Find the tree that is closest to the character
2) Move to that tree
If trees are rare, and cells are plentiful, then it's probably easier to keep a separate list of each tree, together with which cell it is in. Then run through all the trees, calculating the distance between the player and the trees, and remembering which tree is closest. At the end, you know which tree you want to move towards, which should give you the direction to move.
You do not need Dijkstra or A*, because the cost of examining a square is very small, and you don't know which square is actually the goal -- A* works great when you know the goal, but your problem is finding the goal.
If you can't keep a list of trees, then examine each of the grid cells, and if the cell has a tree, calculate distance from cell to player, and if closer than the previously closest cell, then remember that cell. When done, you will be remembering the closest tree cell, which is the cell you want to walk towards. Examining 1200 cells (40x30) really doesn't take any noticeable time on a modern CPU; at least as long as you only do it once in a while.
--
Jon Watte, Direct3D MVP
kW X-port 3ds Max .X exporter
14 days after getting my RROD box back, it's going back for service again. Grr.