36

Someone asked a question about self-avoiding random walks, and it made me think of the following:

Consider a piece that starts at a corner of an ordinary $8 \times 8$ chessboard. At each turn, it moves one step, either up, down, left, or right, with equal probability, except that it must stay on the board, of course, and it must not return to a square previously visited.

Clarification. On any given step, if the piece has $n$ available moves (excluding those that would put the piece on a previously visited square), it chooses randomly and uniformly from those $n$ moves. Example: Starting from a corner, at first move, $n = 2$, and either move is chosen with probability $1/2$. Next move, $n = 2$ also, because it cannot return to the corner, and so either of the two other moves are chosen with probability $1/2$. On the third move, if it is on the edge, $n = 2$, while if it is off the edge, $n = 3$. And so on.

It is possible for the piece to be deadlocked at some point prior to completing a tour of the chessboard. For instance, if it starts at lower left, and moves up, right, right, down, left, it is now stuck.

What is the probability that it completes the tour? Is there a method that answers this question besides exhaustive enumeration? What about $n \times n$ chessboards for $n \geq 3$? (The problem is trivial for $n = 1$ or $2$.)


Analysis for $n = 3$, as another clarification:

Let the chessboard be labelled $(1, 1)$ through $(3, 3)$, and the piece starts at $(1, 1)$. Without loss of generality, the piece moves to $(2, 1)$. Then:

  • With probability $1/2$, the piece moves to the center square $(2, 2)$ on its second move. From there, only one move permits completion of the tour—the move to $(1, 2)$—and in that case, the tour is guaranteed to complete. This move is chosen with probability $1/3$.

  • With probability $1/2$, the piece moves to $(3, 1)$ on its second move. It is then forced to move to $(3, 2)$.

    • With probability $1/2$, it then moves to $(3, 3)$ on its fourth move and is guaranteed to complete the tour.

    • Otherwise, also with probability $1/2$, it moves to the center square $(2, 2)$ on its fourth move. From there, it moves to $(1, 2)$ with probability $1/2$ (and is then guaranteed to complete the tour), or to $(2, 3)$ also with probability $1/2$ (and is then unable to complete the tour).

Thus, the probability of completing the tour on a $3 \times 3$ board is

$$ p_3 = \frac{1}{2} \times \frac{1}{3} + \frac{1}{2} \times \left( \frac{1}{2} + \frac{1}{2} \times \frac{1}{2} \right) = \frac{1}{6} + \frac{3}{8} = \frac{13}{24} $$


Update. An exhaustive enumeration in floating point yielded the following:

For $n = 8, p_n = 0.000006751027716$

Chain Markov
  • 16,012
Brian Tung
  • 35,584
  • @Nikunj The question isn't whether the tour is possible (it obviously is), it's about the probability that a series of random movements completes the tour. – DylanSp Mar 03 '16 at 20:54
  • @DylanSp and that is why I deleted my comment right after posting, but somehow it is magically still there :P – Nikunj Mar 03 '16 at 20:55
  • 1
    You could rephrase the problem as "the probability that a self-avoiding random walk on a grid is an hamiltonian path". – Graffitics Mar 03 '16 at 21:57
  • Is this sequence equivalent to your problem, and if so how do you want it to be translated into a probability figure? Which probability distribution did you have in mind? The probability of an unrestricted random walk of length $n\times n$ steps to conform to the requirements of staying within the board and not be self-intersecting? Or some other distribution based on the board? – String Mar 03 '16 at 22:53
  • @String: That is the right sequence, but I don't see a straightforward way to convert that into a probability. It's possible that whatever analysis gave rise to that sequence could be jiggered to produce the desired probability, but I don't see a good way of doing that from just the numbers themselves. (That doesn't mean it can't be done, though.) The probability I want is essentially that specified by Graffitics. – Brian Tung Mar 03 '16 at 23:08
  • If I understand correctly, we then have the numerators of probabilities (given by that OEIS sequence) and we need to find the denominators, that is the total number of maximal (?) self-avoiding walks on a $n\times n$ chessboard. By brute force I've found: $p(3)=8/20$, $p(4)=52/548$, $p(5)=824/40440$, $p(6)=22144/8442742$, but the sequence of the denominators cannot be found in the OEIS. – Intelligenti pauca Mar 04 '16 at 09:45
  • @Aretino: But do those denominators make sense in terms of the probability distribution. It must be much more likely to stumble upon a shorter maximal self-avoiding walk on a chessboard than a longer one if what you do is essentially moving step-by-step and choosing next direction to go in uniformly at random from all available directions. Then the probability of a particular path diminishes with each step you take. – String Mar 04 '16 at 12:37
  • @BrianTung: Does it make sense to choose uniformly among all maximal self-avoiding walks on a chessboard? These will be very different in length and nature and thus not equally likely to come up with by randomly trying out different paths. See my previous comment too making the same point. Don't you think that this choice of probability distribution is debatable? – String Mar 04 '16 at 12:41
  • @String: Good point. Indeed I've run a simulation (1000000 trials) and have found higher probabilities than expected: $p(3)\approx 0.541$ instead of $8/20=0.4$ and $p(4)\approx 0.140$ instead of $52/548=0.0948905$. – Intelligenti pauca Mar 04 '16 at 13:33
  • @Aretino: Your simulations conform to the figures I found writing another program exhausting all possible paths recursively and reporting back probabilities, namely $p(3)=2/12+6/16=0.541\overline 6$ and $p(4)=20/512 + 12/288 + 4/216 + 16/384=0.1409143\overline{518}$. I too ran a simulation with a similar result. – String Mar 04 '16 at 13:51
  • 2
    @String: You are right: computing the probabilities is as easy as counting the number of paths. I can confirm your results: $p(3)=13/24$, $p(4)=487/3456$, $p(5)= 621,799/23,887,872$ and $p(6)= 3,764,115,767/1,486,016,741,376$. – Intelligenti pauca Mar 04 '16 at 14:34
  • @String: That is not what I meant to specify. I meant to specify that at each turn, the choice of direction is chosen uniformly. Each path does not have equal probability. ¶ I will review comments and edit the question accordingly. – Brian Tung Mar 04 '16 at 17:01
  • @BrianTung: OK, good! That is what I thought. It was clear from other comments, so that is why I asked about it in the first place. – String Mar 04 '16 at 17:36
  • @Aretino: I have clarified the move process. From the size of the numbers you're getting, would it be correct to assume that $8 \times 8$ might be too large to brute force it in this way in a reasonable period of time? – Brian Tung Mar 04 '16 at 18:26
  • @String: Your intuition is vindicated. :-) See above for further clarification. – Brian Tung Mar 04 '16 at 18:28
  • @BrianTung: for the $n=6$ case I had to wait about 15 minutes to get a result, and my estimate for $n=8$ is around $10^5$ hours, so this is not feasible, unless one can find a radically improved algorithm. – Intelligenti pauca Mar 04 '16 at 19:45
  • @Aretino: Doing floating-point for the enumeration allowed me to get the $n = 6$ case in about a tenth of a second (on an iMac) and the $n = 7$ case in about half a minute. But the $n = 8$ case would probably still take a while. Might give it a shot, though. ¶ If I had a list of the 180 million or so different complete tours for $n = 8$, this would be straightforward. But I'm not sure how simple it is to obtain that. – Brian Tung Mar 04 '16 at 19:51
  • @Aretino: Update added in edit for $n = 8$. I'll probably try moving from floating point to rationals next week. – Brian Tung Mar 05 '16 at 19:54
  • This probability will go to $0$ very fast, maybe it could be more interesting to consider the probability of reaching the border starting from the center. – Marco Disce Mar 05 '16 at 19:59
  • @MarcoDisce: That's a question for another post. :-) For this one, it might be illuminating to uncover the asymptotic behavior as $n \to \infty$. It certainly seems as though exact answers yield only to exhaustive enumeration. – Brian Tung Mar 05 '16 at 20:00
  • 1
    This might be remotely relevant? https://arxiv.org/pdf/1607.02433 . See the self-avoiding edge-covering sections. One would need to transform their "edge" into vertices which in turn shall be transformed into your `chess board position'. – Lee David Chung Lin Sep 30 '16 at 09:50
  • @Graffitics You are right. But, I think the OP requires the piece to end up at the starting square, in which case, it is rather a Hamiltonian cycle (i.e., Hamiltonian tour). – Cyriac Antony Nov 19 '22 at 05:26

1 Answers1

2

Let’s solve a more general version of your problem:

Suppose a piece stands in the vertice $v$ of a graph $G = (V, E)$. At each turn, it moves along any edge starting from the vertex it is in currently, with equal probability, except that it must not return to a vertex previously visited.

Let’s denote such probability as $P(G, v)$, then the problem is solved by the recurrent formula:

$$P(G, v) = \begin{cases} 1 & \quad |V| = 1 \\ \frac{\Sigma_{(v, w) \in E} P(G\setminus v, w)}{deg(v)} & \quad |V| > 1 \end{cases}$$

Here $G\setminus v$ stands for a graph that is constructed by removing $v$ and all adjacent edges.

Using that formula the exact probability can always be calculated.

And the probability for $n \times n$ chessboard from your initial question is calculated by this wee piece of code in Python (which is the direct implementation of the aforementioned formula):

import numpy
from fractions import Fraction

def rec(A, n):
    if (A.size == 1):
        return Fraction(1, 1)
    else:
        k = numpy.sum(A[n][:])
        if (k == 0):
            return Fraction(0, 1)
        else:
            res = Fraction(0, 1)
            for i in range(A.shape[0]):
                if A[n][i] == 1:
                    if i < n:
                        res += rec(numpy.delete(numpy.delete(A, (n), axis = 0), (n), axis = 1), i)
                    else:
                        res += rec(numpy.delete(numpy.delete(A, (n), axis = 0), (n), axis = 1), i - 1)
            res = res*Fraction(1, int(k))
            return res


n = int(input())
A = numpy.zeros((n*n, n*n))
for i in range(n):
    for j in range(n):
        for k in range(n):
            for l in range(n):
                if (i - j == 1 and k == l) or (j - i == 1 and k == l) or (k - l == 1 and i == j) or (l - k == 1 and i == j):
                    A[n*i + k][n*j + l] = 1
print(rec(A, 0))

I should also mention, that the function "rec" is designed here to solve the generalised problem, with its arguments being exactly the adjacency matrix of $G$ and the number of its column corresponding to $v$

Chain Markov
  • 16,012