In my programming class, we've been practicing trying to calculate the worst-case scenario. Recently, I was assigned a problem as homework that was interesting, but I wasn't able to find a solution to it. The problem goes a little like this:
Suppose your robot is playing a game on a 3×3 board of unit squares. The robot starts at the center square, and has four options. It can either move to the square above, to the left, to the right, or below. Because your robot has not been optimized yet, it will move randomly to either of the 4 options. The robot will have the option to move up to 4 times, but will stop if it ever reaches a corner square. what is the probability that the robot will end up at a corner square after the end of the 4 moves? Additionally, if a robot ever moves off the edge of the board, it will be warped to the opposite square. For example, if it were at the leftmost square that was in the middle row and chose to move to the left for the next move, it would be warped to the rightmost square in the middle row.
I'm still pretty new to probability and all of this, but I'm guessing the first step is to find the total amount of sequences, and then finding the sequences that end up on a corner square. I was able to calculate the first 3 scenarios fine. The minimum moves needed to reach a corner square is at least 3 moves. I've found $4^4$ possibilities for the 4 moves. For the 2 moves and 3 moves, I've figured out there's 8 possibilities of getting to the corner for each. Is this correct? After this, I've got pretty stumped, as I'm not sure how to calculate the number of times it can get to the corner squares with $4$ moves.
EDIT: Ok so I've done a bit more work. For doing 2 moves, there are only 8 possibilities. The robot has to move out of the center, and then to one of the corner squares around it. For doing 3 moves, there were also 8 possibilities. The robot has to move out of the center, then moves the same direction again to warp to the opposite side, and then can go to one of the 2 corners. And for 4 moves, it turns out there's no way to utilize the warp to go to a corner. So the only way is either going to a side square, back to center, and then repeating the scenario with 2 squares. There's 4 ways to do the first part and 8 for the second part, so another 32. This adds up to 48 ways. However, I'm still having difficulty calculating the entire total. Does anyone have any ideas on how to get the amount of any possible moves?
Best Answer
A direct count of possibilities isn’t too hard if you organize it properly. There are $4^4=256$ possible four-move sequences. I’ll use $L,R,U$, and $D$ to denote moves to the left, right, up, and down, respectively.
The first and third categories above cover all sequences that change direction on the second move, and the second and fourth categories account for all sequences that first change direction on the third move. If the first three moves are the same, i.e., $RRR,LLL,UUU$, or $DDD$, the robot is back at the centre and cannot reach a corner. From that point $4$ moves are possible, so this final category covers $4\cdot4=16$ four-move sequences, none of which reaches a corner.
We’ve now accounted for
$$128+32+32+32+8+8+16=256$$
four-move sequences, which is all of them, and found that $200$ of them reach a corner. The probability that the robot reaches a corner within four moves is therefore
$$\frac{200}{256}=\frac{25}{32}\,.$$
And we have the information to say more: the first category above shows that the probability that the robot reaches a corner in two moves, for instance, is
$$\frac{128}{256}=\frac12\,.$$
Similarly, the second category shows that the probability that the robot reaches a corner in three moves is
$$\frac{32}{256}=\frac18\,.$$
And of course this means that the probability that it takes the robot all four moves to reach a corner is
$$\frac{25}{32}-\frac12-\frac18=\frac5{32}\,.$$