<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>    def setRandomState(self):
>       # container for the elements to pick from
>       container = [1,2,3,4,5,6,7,8,-1]
>
>       # create elements of puzzle randomly
>       i = 0
>       j = 0
>       while i <= self.dim-1:
>           while j <= self.dim-1:
>               if len(container) > 0:
>                   randomindex = random.randint(0,len(container)-1)
>                   self.elements[j][i] = container[randomindex]
>                   del container[randomindex]
>                   j=j+1
>               else:
>                   break
>           j=0
>           i=i+1

Without reading closely, I believe that the above can generate any possible 
position.  Are you aware that half are unsolvable?  If that matters, you 
need to either find a book or site that explains the parity test for 
solvability or generate the start position from the goal position by a 
series of random moves.

Terry J. Reedy




-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to