Here's a recursive process to find the number of moves from point $X$ to point $Y$ in a grid $G$ with obstacles $O$.
Search algorithms work by generation the set of squares that can be reached in $n$ moves.
Let $B_0 = \{X\}$ - the border of expansion, $I_0 = \emptyset$ - interior, $E_0 = (G / O) / B_0$ -exterior.
Let $f$ - a function such that for any $g \in G$, $f(g)$ is the set of squares that can be reached from $g$ in one move. This function is the definition of the chess piece you use.
Now, iterate:
$B_n = \bigcup \limits_{x \in B_{n-1}} f(x) \cap E_{n-1}$
$I_n = I_{n-1} \cup B_{n-1}$
$E_n = E_{n-1} / B_n$
Continue until $Y \in B_n$ or $B_n = \emptyset$. In the first case $\text{distance}(X, Y) = n$, in the second, there is no path from $X$ to $Y$.
I hope that explains the general idea. There is plenty of code examples for pathfinding problems. Note that instead of sets of squares, lists of Nodes are used, where a Node is an object containing the position of a square, a reference to the Node that generated it, for the purposes of backtracking and also a priority number if heuristics are used. Heuristic is the simple idea that if $Y$ lies to the left from $X$, the path from $X$ to $Y$ most likely goes to the left (which is not true in case of obstacles). There isn't much point to use heuristics here since $f$ is usually not trivial and the grid is small.
After some thinking, I figured out how to prove it.
To avoid confusion, let $x_v$ be weight of shortest path $s$ to $v$, and $d(v)$ be actual distance, $d(v)=d(s,v)$.
First condition and $x_s=0$ implies
$\displaystyle d(t)=\sum_{(u,v) \in p}w(u,v)\geq \sum_{(u,v) \in p}(x_v-x_u)=x_t-x_s=x_t$.
So, $x_t\leq d(t)$ for all vertices.
Second condition gives actual instance of such path, and it is guaranteed that it's actual shortest path by above. Note that no nonnegativity condition is used, so it also works for such as Bellman-Ford algorithm.
Best Answer
Also we can assume that graph $G$ is connected. Let $s$ be the starting vertex, $n$ be the number of vertices and $m$ be the number of edges. At first it should be verified that function $\pi\colon V\setminus \{\,s\,\} \to V$ of parents in the tree really produces a tree, i. e. there is no sequence $v_1, \ldots, v_k$ of vertices that $v_1 = \pi(v_2)$, $\ldots$, $v_{k-1} \pi(v_k)$ and $v_k = \pi(v_1)$. It is tree if and only if each vertex can be attained from $s$ passing from parent $\pi(v)$ to vertex $v$ only. Use one DFS from $s$ to check attainability of all vertices, requires $\mathrm O(m)$ time.
Then you should check for each vertex $v$ that the for all neighour vertices $u$ inequality $d(s, u) \ge d(s, v) + w_{uv}$ holds ($d(a, b)$ is the distance between vertices $a$ and $b$ and $w_{ab}$ is the weight of edge $\{\,a, b\,\}$), i. e. for all vertices distance can not be reduced. It should be checked for each egde once, so requires $\mathrm O(m)$ time again.
There are two more conditions: distance from vertex $s$ to itself should be zero and distance to any other vertex $v$ should be equal to distance to it's parent $\pi(v)$ plus weight of edge, connecting them. Checking the first of these conditions requires $\mathrm O(1)$ time and checking the second one requires $\mathrm O(n)$ time. All condition together: $$\begin{cases} \pi(\pi(\ldots\pi(v)\ldots)) = s & \forall v \in V(G) \,\\ d(s, u) \ge d(s, v) + w_{uv} & \forall u \in N_G(v),\\ d(s, s) = 0,\\ d(s, v) = d(s, \pi(v)) + w_{v\pi(v)} & \forall v \in V(G) \setminus \{\,s\,\}. \end{cases}$$ Totally we need $\mathrm O(m)$ time for connected graph $G$. If need of any condition or sufficiency of their aggregate are not obvious, ask in comments.