Look at the attached diagram. In each square I have marked the number of ways of arriving at that square, given the rules you describe.
How did I get these numbers? Well, for each the squares that are not on the perimeter, you find the total number of routes to that square by adding together the numbers in any adjacent squares (including adjacent diagonally) if they are nearer to the starting point. For example, you'll see the square I've shaded yellow containing the number 13. This is the sum of the three green squares: 5 + 5 + 3.
The rule for the squares on the perimeter is different, because you can't include into the total the number in an adjacent square if it's also on the perimeter, because by then, Sam would already be on the perimeter.
So, if you total these up, you'll find that the answer for each side counting one of the corners, but not the other one is: 63 + 88 + 32 + 8 + 1 + 8 + 32 + 88 = 320. There are four of these totals on the perimeter, so I reckon the answer is 4 x 320 = 1280.